From 7d3a9347530ea506cc9638536212ffdb4dd01e95 Mon Sep 17 00:00:00 2001 From: medievalghoul <61852278+medievalghoul@users.noreply.github.com> Date: Sun, 28 Jul 2024 20:42:04 -0400 Subject: [PATCH 1/6] [SandboxIR][NFC] Fixes for functions --- llvm/include/llvm/SandboxIR/SandboxIR.h | 11 +++++++-- llvm/lib/SandboxIR/SandboxIR.cpp | 27 ++++++++++++++++++++-- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 +++++------ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h index 667aeba1bda1f..3b5a17ccc9522 100644 --- a/llvm/include/llvm/SandboxIR/SandboxIR.h +++ b/llvm/include/llvm/SandboxIR/SandboxIR.h @@ -772,10 +772,17 @@ class LoadInst final : public Instruction { unsigned getNumOfIRInstrs() const final { return 1u; } static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align, Instruction *InsertBefore, Context &Ctx, - bool IsVolatile = false, const Twine &Name = ""); + const Twine &Name = ""); + static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align, + Instruction *InsertBefore, bool IsVolatile, + Context &Ctx, const Twine &Name = ""); static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align, BasicBlock *InsertAtEnd, Context &Ctx, - bool IsVolatile = false, const Twine &Name = ""); + const Twine &Name = ""); + static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align, + BasicBlock *InsertAtEnd, bool IsVolatile, + Context &Ctx, const Twine &Name = ""); + /// For isa/dyn_cast. static bool classof(const Value *From); Value *getPointerOperand() const; diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp index d2b4fb207ba3a..cf926de8a75bd 100644 --- a/llvm/lib/SandboxIR/SandboxIR.cpp +++ b/llvm/lib/SandboxIR/SandboxIR.cpp @@ -612,7 +612,19 @@ void BranchInst::dump() const { LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, Instruction *InsertBefore, Context &Ctx, - bool IsVolatile, const Twine &Name) { + const Twine &Name) { + llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction(); + auto &Builder = Ctx.getLLVMIRBuilder(); + Builder.SetInsertPoint(BeforeIR); + auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, + /*IsVolatile=*/false, Name); + auto *NewSBI = Ctx.createLoadInst(NewLI); + return NewSBI; +} + +LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, + Instruction *InsertBefore, bool IsVolatile, + Context &Ctx, const Twine &Name) { llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction(); auto &Builder = Ctx.getLLVMIRBuilder(); Builder.SetInsertPoint(BeforeIR); @@ -624,7 +636,18 @@ LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, BasicBlock *InsertAtEnd, Context &Ctx, - bool IsVolatile, const Twine &Name) { + const Twine &Name) { + auto &Builder = Ctx.getLLVMIRBuilder(); + Builder.SetInsertPoint(cast(InsertAtEnd->Val)); + auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, + /*IsVolatile=*/false, Name); + auto *NewSBI = Ctx.createLoadInst(NewLI); + return NewSBI; +} + +LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, + BasicBlock *InsertAtEnd, bool IsVolatile, + Context &Ctx, const Twine &Name) { auto &Builder = Ctx.getLLVMIRBuilder(); Builder.SetInsertPoint(cast(InsertAtEnd->Val)); auto *NewLI = diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 122508d15194f..4ef867c2af418 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -750,13 +750,13 @@ define void @foo(ptr %arg0, ptr %arg1) { auto *BB = &*F->begin(); auto It = BB->begin(); auto *Ld = cast(&*It++); - auto *Vld = cast(&*It++); + auto *VLd = cast(&*It++); auto *Ret = cast(&*It++); // Check isVolatile() EXPECT_FALSE(Ld->isVolatile()); // Check isVolatile() - EXPECT_TRUE(Vld->isVolatile()); + EXPECT_TRUE(VLd->isVolatile()); // Check getPointerOperand() EXPECT_EQ(Ld->getPointerOperand(), Arg0); // Check getAlign() @@ -764,8 +764,7 @@ define void @foo(ptr %arg0, ptr %arg1) { // Check create(InsertBefore) sandboxir::LoadInst *NewLd = sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), - /*InsertBefore=*/Ret, Ctx, - /*IsVolatile=*/false, "NewLd"); + /*InsertBefore=*/Ret, Ctx, "NewLd"); // Checking if create() was volatile EXPECT_FALSE(NewLd->isVolatile()); EXPECT_EQ(NewLd->getType(), Ld->getType()); @@ -774,9 +773,9 @@ define void @foo(ptr %arg0, ptr %arg1) { EXPECT_EQ(NewLd->getName(), "NewLd"); sandboxir::LoadInst *NewVLd = - sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8), - /*InsertBefore=*/Ret, Ctx, - /*IsVolatile=*/true, "NewVLd"); + sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8), + /*InsertBefore=*/Ret, + /*IsVolatile=*/true, Ctx, "NewVLd"); // Checking if create() was volatile EXPECT_TRUE(NewVLd->isVolatile()); From 8ebf05a60d5da200a28efd61b481978e2bacbf5b Mon Sep 17 00:00:00 2001 From: medievalghoul <61852278+medievalghoul@users.noreply.github.com> Date: Mon, 29 Jul 2024 02:54:06 -0400 Subject: [PATCH 2/6] minor changes along with InsertAtEnd test --- llvm/lib/SandboxIR/SandboxIR.cpp | 15 ++------------- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp index cf926de8a75bd..9c52927c16735 100644 --- a/llvm/lib/SandboxIR/SandboxIR.cpp +++ b/llvm/lib/SandboxIR/SandboxIR.cpp @@ -613,13 +613,7 @@ void BranchInst::dump() const { LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, Instruction *InsertBefore, Context &Ctx, const Twine &Name) { - llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction(); - auto &Builder = Ctx.getLLVMIRBuilder(); - Builder.SetInsertPoint(BeforeIR); - auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, - /*IsVolatile=*/false, Name); - auto *NewSBI = Ctx.createLoadInst(NewLI); - return NewSBI; + return create(Ty, Ptr, Align, InsertBefore, /*IsVolatile=*/false, Ctx, Name); } LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, @@ -637,12 +631,7 @@ LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, BasicBlock *InsertAtEnd, Context &Ctx, const Twine &Name) { - auto &Builder = Ctx.getLLVMIRBuilder(); - Builder.SetInsertPoint(cast(InsertAtEnd->Val)); - auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, - /*IsVolatile=*/false, Name); - auto *NewSBI = Ctx.createLoadInst(NewLI); - return NewSBI; + return create(Ty, Ptr, Align, InsertAtEnd, /*IsVolatile=*/false, Ctx, Name); } LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align, diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 4ef867c2af418..4393fb7fdfde1 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -780,6 +780,19 @@ define void @foo(ptr %arg0, ptr %arg1) { // Checking if create() was volatile EXPECT_TRUE(NewVLd->isVolatile()); EXPECT_EQ(NewVLd->getName(), "NewVLd"); + + // Check create(InsertAtEnd) + sandboxir::LoadInst *NewLdEnd = + sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), + /*InsertAtEnd=*/BB, Ctx, "NewLdEnd"); + EXPECT_FALSE(NewLdEnd->isVolatile()); + EXPECT_EQ(NewLdEnd->getName(), "NewLdEnd"); + // Check create(InsertAtEnd) + sandboxir::LoadInst *NewVLdEnd = + sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8), + /*InsertAtEnd=*/BB, Ctx, "NewVLdEnd"); + EXPECT_FALSE(NewVLdEnd->isVolatile()); + EXPECT_EQ(NewVLdEnd->getName(), "NewVLdEnd"); } TEST_F(SandboxIRTest, StoreInst) { From eb55a5239907e3638b8492b4d5459324ac57ef79 Mon Sep 17 00:00:00 2001 From: medievalghoul <61852278+medievalghoul@users.noreply.github.com> Date: Mon, 29 Jul 2024 02:58:13 -0400 Subject: [PATCH 3/6] added a isVolatile value --- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 4393fb7fdfde1..51aa41ecad613 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -790,8 +790,9 @@ define void @foo(ptr %arg0, ptr %arg1) { // Check create(InsertAtEnd) sandboxir::LoadInst *NewVLdEnd = sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8), - /*InsertAtEnd=*/BB, Ctx, "NewVLdEnd"); - EXPECT_FALSE(NewVLdEnd->isVolatile()); + /*InsertAtEnd=*/BB, + /*IsVolatile=*/true, Ctx, "NewVLdEnd"); + EXPECT_TRUE(NewVLdEnd->isVolatile()); EXPECT_EQ(NewVLdEnd->getName(), "NewVLdEnd"); } From 22f8c4b220b146fa94fc1f9203fd9cca242937ed Mon Sep 17 00:00:00 2001 From: medievalghoul <61852278+medievalghoul@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:06:45 -0400 Subject: [PATCH 4/6] Added more tests for SandboxIRTest --- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 51aa41ecad613..33287c22c90a9 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -780,13 +780,17 @@ define void @foo(ptr %arg0, ptr %arg1) { // Checking if create() was volatile EXPECT_TRUE(NewVLd->isVolatile()); EXPECT_EQ(NewVLd->getName(), "NewVLd"); - // Check create(InsertAtEnd) sandboxir::LoadInst *NewLdEnd = sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), /*InsertAtEnd=*/BB, Ctx, "NewLdEnd"); EXPECT_FALSE(NewLdEnd->isVolatile()); EXPECT_EQ(NewLdEnd->getName(), "NewLdEnd"); + EXPECT_EQ(NewLdEnd->getType(), Ld->getType()); + EXPECT_EQ(NewLdEnd->getPointerOperand(), Arg1); + EXPECT_EQ(NewLdEnd->getAlign(), 8); + EXPECT_EQ(NewLdEnd->getParent(), BB); + EXPECT_EQ(NewLdEnd->getNextNode(), nullptr); // Check create(InsertAtEnd) sandboxir::LoadInst *NewVLdEnd = sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8), @@ -794,6 +798,11 @@ define void @foo(ptr %arg0, ptr %arg1) { /*IsVolatile=*/true, Ctx, "NewVLdEnd"); EXPECT_TRUE(NewVLdEnd->isVolatile()); EXPECT_EQ(NewVLdEnd->getName(), "NewVLdEnd"); + EXPECT_EQ(NewVLdEnd->getType(), VLd->getType()); + EXPECT_EQ(NewVLdEnd->getPointerOperand(), Arg1); + EXPECT_EQ(NewVLdEnd->getAlign(), 8); + EXPECT_EQ(NewVLdEnd->getParent(), BB); + EXPECT_EQ(NewVLdEnd->getNextNode(), nullptr); } TEST_F(SandboxIRTest, StoreInst) { From 38379aebf491485eeb7304e499b025c94f7c0f26 Mon Sep 17 00:00:00 2001 From: medievalghoul <61852278+medievalghoul@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:17:19 -0400 Subject: [PATCH 5/6] minor change: added some comments --- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 33287c22c90a9..0601756ed523e 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -761,7 +761,7 @@ define void @foo(ptr %arg0, ptr %arg1) { EXPECT_EQ(Ld->getPointerOperand(), Arg0); // Check getAlign() EXPECT_EQ(Ld->getAlign(), 64); - // Check create(InsertBefore) + // Check create(InsertBefore, IsVolatile=false) sandboxir::LoadInst *NewLd = sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), /*InsertBefore=*/Ret, Ctx, "NewLd"); @@ -771,7 +771,7 @@ define void @foo(ptr %arg0, ptr %arg1) { EXPECT_EQ(NewLd->getPointerOperand(), Arg1); EXPECT_EQ(NewLd->getAlign(), 8); EXPECT_EQ(NewLd->getName(), "NewLd"); - + // Check create(InsertBefore, IsVolatile=true) sandboxir::LoadInst *NewVLd = sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8), /*InsertBefore=*/Ret, @@ -780,7 +780,7 @@ define void @foo(ptr %arg0, ptr %arg1) { // Checking if create() was volatile EXPECT_TRUE(NewVLd->isVolatile()); EXPECT_EQ(NewVLd->getName(), "NewVLd"); - // Check create(InsertAtEnd) + // Check create(InsertAtEnd, IsVolatile=false) sandboxir::LoadInst *NewLdEnd = sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), /*InsertAtEnd=*/BB, Ctx, "NewLdEnd"); @@ -791,7 +791,7 @@ define void @foo(ptr %arg0, ptr %arg1) { EXPECT_EQ(NewLdEnd->getAlign(), 8); EXPECT_EQ(NewLdEnd->getParent(), BB); EXPECT_EQ(NewLdEnd->getNextNode(), nullptr); - // Check create(InsertAtEnd) + // Check create(InsertAtEnd, IsVolatile=true) sandboxir::LoadInst *NewVLdEnd = sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8), /*InsertAtEnd=*/BB, From 05879447c04c57afa75fb1f56b7dff2dc91fa7bb Mon Sep 17 00:00:00 2001 From: medievalghoul <61852278+medievalghoul@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:31:49 -0400 Subject: [PATCH 6/6] minor change: added fixed comments --- llvm/unittests/SandboxIR/SandboxIRTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp index 0601756ed523e..b32715340e4f8 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -761,7 +761,7 @@ define void @foo(ptr %arg0, ptr %arg1) { EXPECT_EQ(Ld->getPointerOperand(), Arg0); // Check getAlign() EXPECT_EQ(Ld->getAlign(), 64); - // Check create(InsertBefore, IsVolatile=false) + // Check create(InsertBefore) sandboxir::LoadInst *NewLd = sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), /*InsertBefore=*/Ret, Ctx, "NewLd"); @@ -780,7 +780,7 @@ define void @foo(ptr %arg0, ptr %arg1) { // Checking if create() was volatile EXPECT_TRUE(NewVLd->isVolatile()); EXPECT_EQ(NewVLd->getName(), "NewVLd"); - // Check create(InsertAtEnd, IsVolatile=false) + // Check create(InsertAtEnd) sandboxir::LoadInst *NewLdEnd = sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8), /*InsertAtEnd=*/BB, Ctx, "NewLdEnd");