[llvm] 5103910 - [SandboxIR] Add more functions to sandboxir:Instruction class. (#110050)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 16:09:18 PDT 2024
Author: Sriraman Tallam
Date: 2024-09-25T16:09:13-07:00
New Revision: 51039101cf32591782ef564a108db71150a3b7c3
URL: https://github.com/llvm/llvm-project/commit/51039101cf32591782ef564a108db71150a3b7c3
DIFF: https://github.com/llvm/llvm-project/commit/51039101cf32591782ef564a108db71150a3b7c3.diff
LOG: [SandboxIR] Add more functions to sandboxir:Instruction class. (#110050)
The getter functions simply turn around and call the LLVM
counterparts. This is fine until we don't add new sandbox IR
opcodes. At that point, we may have to explicitly check if
the behavior is different.
Added:
Modified:
llvm/include/llvm/SandboxIR/SandboxIR.h
llvm/unittests/SandboxIR/SandboxIRTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index ae54042c6df29a..c9dd7d09d04bc2 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -1942,7 +1942,13 @@ class Instruction : public sandboxir::User {
/// state to allow for new SandboxIR-specific instructions.
Opcode getOpcode() const { return Opc; }
- // TODO: Missing function getOpcodeName().
+ const char *getOpcodeName() const { return getOpcodeName(Opc); }
+
+ // Note that these functions below are calling into llvm::Instruction.
+ // A sandbox IR instruction could introduce a new opcode that could change the
+ // behavior of one of these functions. It is better that these functions are
+ // only added as needed and new sandbox IR instructions must explicitly check
+ // if any of these functions could have a
diff erent behavior.
bool isTerminator() const {
return cast<llvm::Instruction>(Val)->isTerminator();
@@ -1954,6 +1960,41 @@ class Instruction : public sandboxir::User {
}
bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
bool isCast() const { return cast<llvm::Instruction>(Val)->isCast(); }
+ bool isFuncletPad() const {
+ return cast<llvm::Instruction>(Val)->isFuncletPad();
+ }
+ bool isSpecialTerminator() const {
+ return cast<llvm::Instruction>(Val)->isSpecialTerminator();
+ }
+ bool isOnlyUserOfAnyOperand() const {
+ return cast<llvm::Instruction>(Val)->isOnlyUserOfAnyOperand();
+ }
+ bool isLogicalShift() const {
+ return cast<llvm::Instruction>(Val)->isLogicalShift();
+ }
+
+ //===--------------------------------------------------------------------===//
+ // Metadata manipulation.
+ //===--------------------------------------------------------------------===//
+
+ /// Return true if the instruction has any metadata attached to it.
+ bool hasMetadata() const {
+ return cast<llvm::Instruction>(Val)->hasMetadata();
+ }
+
+ /// Return true if this instruction has metadata attached to it other than a
+ /// debug location.
+ bool hasMetadataOtherThanDebugLoc() const {
+ return cast<llvm::Instruction>(Val)->hasMetadataOtherThanDebugLoc();
+ }
+
+ /// Return true if this instruction has the given type of metadata attached.
+ bool hasMetadata(unsigned KindID) const {
+ return cast<llvm::Instruction>(Val)->hasMetadata(KindID);
+ }
+
+ // TODO: Implement getMetadata and getAllMetadata after sandboxir::MDNode is
+ // available.
// TODO: More missing functions
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 941d874231d38a..aed91c88943811 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -1828,9 +1828,12 @@ define void @foo(i8 %v1, ptr %ptr) {
%atomicrmw = atomicrmw add ptr %ptr, i8 %v1 acquire
%udiv = udiv i8 %ld0, %v1
%urem = urem i8 %ld0, %v1
- call void @foo()
- ret void
+ call void @foo(), !dbg !1
+ ret void, !tbaa !2
}
+
+!1 = !{}
+!2 = !{}
)IR");
llvm::Function *LLVMF = &*M->getFunction("foo");
llvm::BasicBlock *LLVMBB1 = getBasicBlockByName(*LLVMF, "bb1");
@@ -1864,6 +1867,15 @@ define void @foo(i8 %v1, ptr %ptr) {
EXPECT_EQ(I1->getOpcode(), sandboxir::Instruction::Opcode::Sub);
EXPECT_EQ(Ret->getOpcode(), sandboxir::Instruction::Opcode::Ret);
+ // Check getOpcodeName().
+ EXPECT_EQ(I0->getOpcodeName(), "Add");
+ EXPECT_EQ(I1->getOpcodeName(), "Sub");
+ EXPECT_EQ(Ret->getOpcodeName(), "Ret");
+
+ EXPECT_EQ(sandboxir::Instruction::getOpcodeName(
+ sandboxir::Instruction::Opcode::Alloca),
+ "Alloca");
+
// Check moveBefore(I).
I1->moveBefore(I0);
EXPECT_EQ(I0->getPrevNode(), I1);
@@ -1932,6 +1944,19 @@ define void @foo(i8 %v1, ptr %ptr) {
EXPECT_EQ(LLVMI.isShift(), I.isShift());
// Check isCast().
EXPECT_EQ(LLVMI.isCast(), I.isCast());
+ // Check isFuncletPad().
+ EXPECT_EQ(LLVMI.isFuncletPad(), I.isFuncletPad());
+ // Check isSpecialTerminator().
+ EXPECT_EQ(LLVMI.isSpecialTerminator(), I.isSpecialTerminator());
+ // Check isOnlyUserOfAnyOperand().
+ EXPECT_EQ(LLVMI.isOnlyUserOfAnyOperand(), I.isOnlyUserOfAnyOperand());
+ // Check isLogicalShift().
+ EXPECT_EQ(LLVMI.isLogicalShift(), I.isLogicalShift());
+ // Check hasMetadata().
+ EXPECT_EQ(LLVMI.hasMetadata(), I.hasMetadata());
+ // Check hasMetadataOtherThanDebugLoc().
+ EXPECT_EQ(LLVMI.hasMetadataOtherThanDebugLoc(),
+ I.hasMetadataOtherThanDebugLoc());
// Check isAssociative().
EXPECT_EQ(LLVMI.isAssociative(), I.isAssociative());
// Check isCommutative().
More information about the llvm-commits
mailing list