[llvm] [SandboxIR] Implemented isVolatile() for LoadInst (PR #100717)

Julius Alexandre via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 09:32:07 PDT 2024


https://github.com/medievalghoul updated https://github.com/llvm/llvm-project/pull/100717

>From 25f59f995a0da70d0a837daf38ccedf4fe35fbd5 Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Fri, 26 Jul 2024 04:12:02 -0400
Subject: [PATCH 1/2] Added isVolatile() to LoadInst

---
 llvm/include/llvm/SandboxIR/SandboxIR.h    | 4 ++++
 llvm/unittests/SandboxIR/SandboxIRTest.cpp | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 6c04c92e3e70e..21ff3cc23eb93 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -59,6 +59,7 @@
 #define LLVM_SANDBOXIR_SANDBOXIR_H
 
 #include "llvm/IR/Function.h"
+#include "llvm/IR/Instruction.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/User.h"
 #include "llvm/IR/Value.h"
@@ -735,6 +736,9 @@ class LoadInst final : public Instruction {
   }
 
 public:
+  /// Return true if this is a load from a volatile memory location.
+  bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }  
+
   unsigned getUseOperandNo(const Use &Use) const final {
     return getUseOperandNoDefault(Use);
   }
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index c600103fe10c6..c5850adeadcd5 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -737,7 +737,7 @@ define void @foo(i1 %cond0, i1 %cond2) {
 TEST_F(SandboxIRTest, LoadInst) {
   parseIR(C, R"IR(
 define void @foo(ptr %arg0, ptr %arg1) {
-  %ld = load i8, ptr %arg0, align 64
+  %ld = load volatile i8, ptr %arg0, align 64
   ret void
 }
 )IR");
@@ -751,6 +751,8 @@ define void @foo(ptr %arg0, ptr %arg1) {
   auto *Ld = cast<sandboxir::LoadInst>(&*It++);
   auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
 
+  // Check isVolatile()
+  EXPECT_TRUE(Ld->isVolatile());
   // Check getPointerOperand()
   EXPECT_EQ(Ld->getPointerOperand(), Arg0);
   // Check getAlign()

>From f0b40a235c018409496bad0d673b9f00b459c7cf Mon Sep 17 00:00:00 2001
From: medievalghoul <61852278+medievalghoul at users.noreply.github.com>
Date: Fri, 26 Jul 2024 12:31:54 -0400
Subject: [PATCH 2/2] Kept both volatile and non-volatile loads

---
 llvm/unittests/SandboxIR/SandboxIRTest.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index c5850adeadcd5..b771ec5d788e0 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -737,7 +737,8 @@ define void @foo(i1 %cond0, i1 %cond2) {
 TEST_F(SandboxIRTest, LoadInst) {
   parseIR(C, R"IR(
 define void @foo(ptr %arg0, ptr %arg1) {
-  %ld = load volatile i8, ptr %arg0, align 64
+  %ld = load i8, ptr %arg0, align 64
+  %vld = load volatile i8, ptr %arg0, align 64
   ret void
 }
 )IR");
@@ -749,10 +750,13 @@ define void @foo(ptr %arg0, ptr %arg1) {
   auto *BB = &*F->begin();
   auto It = BB->begin();
   auto *Ld = cast<sandboxir::LoadInst>(&*It++);
+  auto *Vld = cast<sandboxir::LoadInst>(&*It++);
   auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
 
   // Check isVolatile()
-  EXPECT_TRUE(Ld->isVolatile());
+  EXPECT_FALSE(Ld->isVolatile());
+  // Check isVolatile() 
+  EXPECT_TRUE(Vld->isVolatile());
   // Check getPointerOperand()
   EXPECT_EQ(Ld->getPointerOperand(), Arg0);
   // Check getAlign()



More information about the llvm-commits mailing list