[SandboxIR] Implement isVolatile() for LoadInst (#100717)

This commit is contained in:
Julius Alexandre
2024-07-26 16:06:28 -04:00
committed by GitHub
parent 53283dc464
commit 745aa48165
2 changed files with 10 additions and 0 deletions

View File

@@ -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<llvm::LoadInst>(Val)->isVolatile(); }
unsigned getUseOperandNo(const Use &Use) const final {
return getUseOperandNoDefault(Use);
}

View File

@@ -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<sandboxir::LoadInst>(&*It++);
auto *Vld = cast<sandboxir::LoadInst>(&*It++);
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
// Check isVolatile()
EXPECT_FALSE(Ld->isVolatile());
// Check isVolatile()
EXPECT_TRUE(Vld->isVolatile());
// Check getPointerOperand()
EXPECT_EQ(Ld->getPointerOperand(), Arg0);
// Check getAlign()