Skip to content

Commit b3b390b

Browse files
[SandboxIR][NFC] Fixes for LoadInst::create functions (llvm#100955)
This patch updates `LoadInst::create()` functions. The end result is four `LoadInst::create()` functions in total, two of which with an `IsVolatile` argument and two without.
1 parent fb70282 commit b3b390b

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,17 @@ class LoadInst final : public Instruction {
772772
unsigned getNumOfIRInstrs() const final { return 1u; }
773773
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
774774
Instruction *InsertBefore, Context &Ctx,
775-
bool IsVolatile = false, const Twine &Name = "");
775+
const Twine &Name = "");
776+
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
777+
Instruction *InsertBefore, bool IsVolatile,
778+
Context &Ctx, const Twine &Name = "");
776779
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
777780
BasicBlock *InsertAtEnd, Context &Ctx,
778-
bool IsVolatile = false, const Twine &Name = "");
781+
const Twine &Name = "");
782+
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
783+
BasicBlock *InsertAtEnd, bool IsVolatile,
784+
Context &Ctx, const Twine &Name = "");
785+
779786
/// For isa/dyn_cast.
780787
static bool classof(const Value *From);
781788
Value *getPointerOperand() const;

llvm/lib/SandboxIR/SandboxIR.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,13 @@ void BranchInst::dump() const {
612612

613613
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
614614
Instruction *InsertBefore, Context &Ctx,
615-
bool IsVolatile, const Twine &Name) {
615+
const Twine &Name) {
616+
return create(Ty, Ptr, Align, InsertBefore, /*IsVolatile=*/false, Ctx, Name);
617+
}
618+
619+
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
620+
Instruction *InsertBefore, bool IsVolatile,
621+
Context &Ctx, const Twine &Name) {
616622
llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
617623
auto &Builder = Ctx.getLLVMIRBuilder();
618624
Builder.SetInsertPoint(BeforeIR);
@@ -624,7 +630,13 @@ LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
624630

625631
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
626632
BasicBlock *InsertAtEnd, Context &Ctx,
627-
bool IsVolatile, const Twine &Name) {
633+
const Twine &Name) {
634+
return create(Ty, Ptr, Align, InsertAtEnd, /*IsVolatile=*/false, Ctx, Name);
635+
}
636+
637+
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
638+
BasicBlock *InsertAtEnd, bool IsVolatile,
639+
Context &Ctx, const Twine &Name) {
628640
auto &Builder = Ctx.getLLVMIRBuilder();
629641
Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
630642
auto *NewLI =

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -750,37 +750,59 @@ define void @foo(ptr %arg0, ptr %arg1) {
750750
auto *BB = &*F->begin();
751751
auto It = BB->begin();
752752
auto *Ld = cast<sandboxir::LoadInst>(&*It++);
753-
auto *Vld = cast<sandboxir::LoadInst>(&*It++);
753+
auto *VLd = cast<sandboxir::LoadInst>(&*It++);
754754
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
755755

756756
// Check isVolatile()
757757
EXPECT_FALSE(Ld->isVolatile());
758758
// Check isVolatile()
759-
EXPECT_TRUE(Vld->isVolatile());
759+
EXPECT_TRUE(VLd->isVolatile());
760760
// Check getPointerOperand()
761761
EXPECT_EQ(Ld->getPointerOperand(), Arg0);
762762
// Check getAlign()
763763
EXPECT_EQ(Ld->getAlign(), 64);
764764
// Check create(InsertBefore)
765765
sandboxir::LoadInst *NewLd =
766766
sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
767-
/*InsertBefore=*/Ret, Ctx,
768-
/*IsVolatile=*/false, "NewLd");
767+
/*InsertBefore=*/Ret, Ctx, "NewLd");
769768
// Checking if create() was volatile
770769
EXPECT_FALSE(NewLd->isVolatile());
771770
EXPECT_EQ(NewLd->getType(), Ld->getType());
772771
EXPECT_EQ(NewLd->getPointerOperand(), Arg1);
773772
EXPECT_EQ(NewLd->getAlign(), 8);
774773
EXPECT_EQ(NewLd->getName(), "NewLd");
775-
774+
// Check create(InsertBefore, IsVolatile=true)
776775
sandboxir::LoadInst *NewVLd =
777-
sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
778-
/*InsertBefore=*/Ret, Ctx,
779-
/*IsVolatile=*/true, "NewVLd");
776+
sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8),
777+
/*InsertBefore=*/Ret,
778+
/*IsVolatile=*/true, Ctx, "NewVLd");
780779

781780
// Checking if create() was volatile
782781
EXPECT_TRUE(NewVLd->isVolatile());
783782
EXPECT_EQ(NewVLd->getName(), "NewVLd");
783+
// Check create(InsertAtEnd)
784+
sandboxir::LoadInst *NewLdEnd =
785+
sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
786+
/*InsertAtEnd=*/BB, Ctx, "NewLdEnd");
787+
EXPECT_FALSE(NewLdEnd->isVolatile());
788+
EXPECT_EQ(NewLdEnd->getName(), "NewLdEnd");
789+
EXPECT_EQ(NewLdEnd->getType(), Ld->getType());
790+
EXPECT_EQ(NewLdEnd->getPointerOperand(), Arg1);
791+
EXPECT_EQ(NewLdEnd->getAlign(), 8);
792+
EXPECT_EQ(NewLdEnd->getParent(), BB);
793+
EXPECT_EQ(NewLdEnd->getNextNode(), nullptr);
794+
// Check create(InsertAtEnd, IsVolatile=true)
795+
sandboxir::LoadInst *NewVLdEnd =
796+
sandboxir::LoadInst::create(VLd->getType(), Arg1, Align(8),
797+
/*InsertAtEnd=*/BB,
798+
/*IsVolatile=*/true, Ctx, "NewVLdEnd");
799+
EXPECT_TRUE(NewVLdEnd->isVolatile());
800+
EXPECT_EQ(NewVLdEnd->getName(), "NewVLdEnd");
801+
EXPECT_EQ(NewVLdEnd->getType(), VLd->getType());
802+
EXPECT_EQ(NewVLdEnd->getPointerOperand(), Arg1);
803+
EXPECT_EQ(NewVLdEnd->getAlign(), 8);
804+
EXPECT_EQ(NewVLdEnd->getParent(), BB);
805+
EXPECT_EQ(NewVLdEnd->getNextNode(), nullptr);
784806
}
785807

786808
TEST_F(SandboxIRTest, StoreInst) {

0 commit comments

Comments
 (0)