[llvm] [SandboxIR] Added isVolatile args to existing LoadInst::create function (PR #100850)

Julius Alexandre via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 18:58:03 PDT 2024


https://github.com/medievalghoul created https://github.com/llvm/llvm-project/pull/100850

Added isVolatile args along with the tests 

Previous PR: https://github.com/llvm/llvm-project/pull/100781

>From f66ee5e7c901bda1a2cb78a8554f7621dc96020b Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Fri, 26 Jul 2024 21:48:23 -0400
Subject: [PATCH] Added isVolatile args in LoadInst::create function

---
 llvm/include/llvm/SandboxIR/SandboxIR.h    |  4 ++--
 llvm/lib/SandboxIR/SandboxIR.cpp           |  8 ++++----
 llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 ++++++++++++-
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 5c89f165c9647..d13e547bc97cc 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -769,10 +769,10 @@ class LoadInst final : public Instruction {
   unsigned getNumOfIRInstrs() const final { return 1u; }
   static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
                           Instruction *InsertBefore, Context &Ctx,
-                          const Twine &Name = "");
+                          bool isVolatile = false, const Twine &Name = "");
   static LoadInst *create(Type *Ty, Value *Ptr, MaybeAlign Align,
                           BasicBlock *InsertAtEnd, Context &Ctx,
-                          const Twine &Name = "");
+                          bool isVolatile = false, 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 da482765c7d11..9e41bacf1a8dd 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -612,23 +612,23 @@ void BranchInst::dump() const {
 
 LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
                            Instruction *InsertBefore, Context &Ctx,
-                           const Twine &Name) {
+                           bool isVolatile, 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);
+                                          isVolatile, Name);
   auto *NewSBI = Ctx.createLoadInst(NewLI);
   return NewSBI;
 }
 
 LoadInst *LoadInst::create(Type *Ty, Value *Ptr, MaybeAlign Align,
                            BasicBlock *InsertAtEnd, Context &Ctx,
-                           const Twine &Name) {
+                           bool isVolatile, const Twine &Name) {
   auto &Builder = Ctx.getLLVMIRBuilder();
   Builder.SetInsertPoint(cast<llvm::BasicBlock>(InsertAtEnd->Val));
   auto *NewLI = Builder.CreateAlignedLoad(Ty, Ptr->Val, Align,
-                                          /*isVolatile=*/false, Name);
+                                          isVolatile, Name);
   auto *NewSBI = Ctx.createLoadInst(NewLI);
   return NewSBI;
 }
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 0565e87ce9517..d1d326dab9cbb 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -764,11 +764,22 @@ define void @foo(ptr %arg0, ptr %arg1) {
   // Check create(InsertBefore)
   sandboxir::LoadInst *NewLd =
       sandboxir::LoadInst::create(Ld->getType(), Arg1, Align(8),
-                                  /*InsertBefore=*/Ret, Ctx, "NewLd");
+                                  /*InsertBefore=*/Ret, Ctx, 
+                                  Ld->isVolatile(), "NewLd");
   EXPECT_EQ(NewLd->getType(), Ld->getType());
   EXPECT_EQ(NewLd->getPointerOperand(), Arg1);
   EXPECT_EQ(NewLd->getAlign(), 8);
   EXPECT_EQ(NewLd->getName(), "NewLd");
+  
+  sandboxir::LoadInst *NewVld =
+      sandboxir::LoadInst::create(Vld->getType(), Arg1, Align(8),
+                                  /*InsertBefore=*/Ret, Ctx, 
+                                  Vld->isVolatile(), "NewVld");
+  EXPECT_EQ(NewVld->getType(), Vld->getType());
+  EXPECT_EQ(NewVld->getPointerOperand(), Arg1);
+  EXPECT_EQ(NewVld->isVolatile(), Vld->isVolatile());
+  EXPECT_EQ(NewVld->getAlign(), 8);
+  EXPECT_EQ(NewVld->getName(), "NewVld");
 }
 
 TEST_F(SandboxIRTest, StoreInst) {



More information about the llvm-commits mailing list