[llvm] [SandboxIR] Implement a few Instruction member functions (PR #109820)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 24 08:51:28 PDT 2024
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/109820
This patch implements a few sandboxir::Instruction predicate functions.
>From 556720d293fc2f9338aae3342d9a4662489114ba Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Tue, 24 Sep 2024 08:48:02 -0700
Subject: [PATCH] [SandboxIR] Implement a few Instruction member functions
This patch implements a few sandboxir::Instruction predicate functions.
---
llvm/include/llvm/SandboxIR/SandboxIR.h | 16 ++++++++++++++++
llvm/unittests/SandboxIR/SandboxIRTest.cpp | 13 +++++++++++++
2 files changed, 29 insertions(+)
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 84c32aeb0451f5..f81917bd50797b 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -1931,6 +1931,22 @@ class Instruction : public sandboxir::User {
/// \Returns this Instruction's opcode. Note that SandboxIR has its own opcode
/// state to allow for new SandboxIR-specific instructions.
Opcode getOpcode() const { return Opc; }
+
+ // TODO: Missing function getOpcodeName().
+
+ bool isTerminator() const {
+ return cast<llvm::Instruction>(Val)->isTerminator();
+ }
+ bool isUnaryOp() const { return cast<llvm::Instruction>(Val)->isUnaryOp(); }
+ bool isBinaryOp() const { return cast<llvm::Instruction>(Val)->isBinaryOp(); }
+ bool isIntDivRem() const {
+ return cast<llvm::Instruction>(Val)->isIntDivRem();
+ }
+ bool isShift() const { return cast<llvm::Instruction>(Val)->isShift(); }
+ bool isCast() const { return cast<llvm::Instruction>(Val)->isCast(); }
+
+ // TODO: More missing functions
+
/// Detach this from its parent BasicBlock without deleting it.
void removeFromParent();
/// Detach this Value from its parent and delete it.
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index 1fcc9cbea152cd..42df09609b675c 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -1769,6 +1769,7 @@ define void @foo(i8 %v1, ptr %ptr) {
store volatile i8 %ld0, 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
}
@@ -1861,6 +1862,18 @@ define void @foo(i8 %v1, ptr %ptr) {
for (auto &LLVMI : *LLVMBB1) {
auto &I = cast<sandboxir::Instruction>(*Ctx.getValue(&LLVMI));
+ // Check isTerminator().
+ EXPECT_EQ(LLVMI.isTerminator(), I.isTerminator());
+ // Check isUnaryOp().
+ EXPECT_EQ(LLVMI.isUnaryOp(), I.isUnaryOp());
+ // Check isBinaryOp().
+ EXPECT_EQ(LLVMI.isBinaryOp(), I.isBinaryOp());
+ // Check isIntDivRem().
+ EXPECT_EQ(LLVMI.isIntDivRem(), I.isIntDivRem());
+ // Check isShift().
+ EXPECT_EQ(LLVMI.isShift(), I.isShift());
+ // Check isCast().
+ EXPECT_EQ(LLVMI.isCast(), I.isCast());
// Check isAssociative().
EXPECT_EQ(LLVMI.isAssociative(), I.isAssociative());
// Check isCommutative().
More information about the llvm-commits
mailing list