Skip to content

Commit 4121191

Browse files
[SandboxIR] Added isVolatile args to existing LoadInst::create function (#100850)
Added isVolatile args along with the tests.
1 parent a17f8fe commit 4121191

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
#define LLVM_SANDBOXIR_SANDBOXIR_H
6666

6767
#include "llvm/IR/Function.h"
68-
#include "llvm/IR/Instruction.h"
6968
#include "llvm/IR/IRBuilder.h"
69+
#include "llvm/IR/Instruction.h"
7070
#include "llvm/IR/User.h"
7171
#include "llvm/IR/Value.h"
7272
#include "llvm/SandboxIR/Tracker.h"
@@ -772,10 +772,10 @@ 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-
const Twine &Name = "");
775+
bool IsVolatile = false, const Twine &Name = "");
776776
static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
777777
BasicBlock *InsertAtEnd, Context &Ctx,
778-
const Twine &Name = "");
778+
bool IsVolatile = false, const Twine &Name = "");
779779
/// For isa/dyn_cast.
780780
static bool classof(const Value *From);
781781
Value *getPointerOperand() const;

llvm/lib/SandboxIR/SandboxIR.cpp

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

613613
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
614614
Instruction *InsertBefore, Context &Ctx,
615-
const Twine &Name) {
615+
bool IsVolatile, const Twine &Name) {
616616
llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
617617
auto &Builder = Ctx.getLLVMIRBuilder();
618618
Builder.SetInsertPoint(BeforeIR);
619-
auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
620-
/*isVolatile=*/false, Name);
619+
auto *NewLI =
620+
Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, IsVolatile, Name);
621621
auto *NewSBI = Ctx.createLoadInst(NewLI);
622622
return NewSBI;
623623
}
624624

625625
LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
626626
BasicBlock *InsertAtEnd, Context &Ctx,
627-
const Twine &Name) {
627+
bool IsVolatile, const Twine &Name) {
628628
auto &Builder = Ctx.getLLVMIRBuilder();
629629
Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
630-
auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
631-
/*isVolatile=*/false, Name);
630+
auto *NewLI =
631+
Builder.CreateAlignedLoad(Ty, Ptr->Val, Align, IsVolatile, Name);
632632
auto *NewSBI = Ctx.createLoadInst(NewLI);
633633
return NewSBI;
634634
}

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,23 @@ define void @foo(ptr %arg0, ptr %arg1) {
764764
// Check create(InsertBefore)
765765
sandboxir::LoadInst *NewLd =
766766
sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
767-
/*InsertBefore=*/Ret, Ctx, "NewLd");
767+
/*InsertBefore=*/Ret, Ctx,
768+
/*IsVolatile=*/false, "NewLd");
769+
// Checking if create() was volatile
770+
EXPECT_FALSE(NewLd->isVolatile());
768771
EXPECT_EQ(NewLd->getType(), Ld->getType());
769772
EXPECT_EQ(NewLd->getPointerOperand(), Arg1);
770773
EXPECT_EQ(NewLd->getAlign(), 8);
771774
EXPECT_EQ(NewLd->getName(), "NewLd");
775+
776+
sandboxir::LoadInst *NewVLd =
777+
sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
778+
/*InsertBefore=*/Ret, Ctx,
779+
/*IsVolatile=*/true, "NewVLd");
780+
781+
// Checking if create() was volatile
782+
EXPECT_TRUE(NewVLd->isVolatile());
783+
EXPECT_EQ(NewVLd->getName(), "NewVLd");
772784
}
773785

774786
TEST_F(SandboxIRTest, StoreInst) {

0 commit comments

Comments
 (0)