diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h index 2678ee0f4f90..1589369a6a4b 100644 --- a/llvm/include/llvm/SandboxIR/SandboxIR.h +++ b/llvm/include/llvm/SandboxIR/SandboxIR.h @@ -65,6 +65,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" @@ -758,6 +759,9 @@ class LoadInst final : public Instruction { } public: + /// Return true if this is a load from a volatile memory location. + bool isVolatile() const { return cast(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 05ec42c952eb..a9569d194cd8 100644 --- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp +++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp @@ -738,6 +738,7 @@ TEST_F(SandboxIRTest, LoadInst) { parseIR(C, R"IR( define void @foo(ptr %arg0, ptr %arg1) { %ld = load i8, ptr %arg0, align 64 + %vld = load volatile i8, ptr %arg0, align 64 ret void } )IR"); @@ -749,8 +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 *Ret = cast(&*It++); + // Check isVolatile() + EXPECT_FALSE(Ld->isVolatile()); + // Check isVolatile() + EXPECT_TRUE(Vld->isVolatile()); // Check getPointerOperand() EXPECT_EQ(Ld->getPointerOperand(), Arg0); // Check getAlign()