Skip to content

Commit 745aa48

Browse files
[SandboxIR] Implement isVolatile() for LoadInst (#100717)
1 parent 53283dc commit 745aa48

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define LLVM_SANDBOXIR_SANDBOXIR_H
6666

6767
#include "llvm/IR/Function.h"
68+
#include "llvm/IR/Instruction.h"
6869
#include "llvm/IR/IRBuilder.h"
6970
#include "llvm/IR/User.h"
7071
#include "llvm/IR/Value.h"
@@ -758,6 +759,9 @@ class LoadInst final : public Instruction {
758759
}
759760

760761
public:
762+
/// Return true if this is a load from a volatile memory location.
763+
bool isVolatile() const { return cast<llvm::LoadInst>(Val)->isVolatile(); }
764+
761765
unsigned getUseOperandNo(const Use &Use) const final {
762766
return getUseOperandNoDefault(Use);
763767
}

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ TEST_F(SandboxIRTest, LoadInst) {
738738
parseIR(C, R"IR(
739739
define void @foo(ptr %arg0, ptr %arg1) {
740740
%ld = load i8, ptr %arg0, align 64
741+
%vld = load volatile i8, ptr %arg0, align 64
741742
ret void
742743
}
743744
)IR");
@@ -749,8 +750,13 @@ define void @foo(ptr %arg0, ptr %arg1) {
749750
auto *BB = &*F->begin();
750751
auto It = BB->begin();
751752
auto *Ld = cast<sandboxir::LoadInst>(&*It++);
753+
auto *Vld = cast<sandboxir::LoadInst>(&*It++);
752754
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
753755

756+
// Check isVolatile()
757+
EXPECT_FALSE(Ld->isVolatile());
758+
// Check isVolatile()
759+
EXPECT_TRUE(Vld->isVolatile());
754760
// Check getPointerOperand()
755761
EXPECT_EQ(Ld->getPointerOperand(), Arg0);
756762
// Check getAlign()

0 commit comments

Comments
 (0)