[llvm] a1ff427 - [SandboxIR][NFC] Move intrinsic code to Utils::isMemIntrinsic() (#111019)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 10:40:36 PDT 2024
Author: vporpo
Date: 2024-10-03T10:40:33-07:00
New Revision: a1ff427558fc348d4ac9632e75872e7425a8df31
URL: https://github.com/llvm/llvm-project/commit/a1ff427558fc348d4ac9632e75872e7425a8df31
DIFF: https://github.com/llvm/llvm-project/commit/a1ff427558fc348d4ac9632e75872e7425a8df31.diff
LOG: [SandboxIR][NFC] Move intrinsic code to Utils::isMemIntrinsic() (#111019)
This patch moves the intrinsic specific code from
Utils::isMemDepCandidate() to a new function: Utils::isMemIntrinsic().
Added:
Modified:
llvm/include/llvm/SandboxIR/Utils.h
llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
llvm/unittests/SandboxIR/UtilsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/Utils.h b/llvm/include/llvm/SandboxIR/Utils.h
index 510ae8c10e62f3..781495d9498173 100644
--- a/llvm/include/llvm/SandboxIR/Utils.h
+++ b/llvm/include/llvm/SandboxIR/Utils.h
@@ -17,6 +17,7 @@
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/SandboxIR/Instruction.h"
+#include "llvm/SandboxIR/IntrinsicInst.h"
#include <optional>
namespace llvm::sandboxir {
@@ -101,24 +102,27 @@ class Utils {
}
static bool isStackSaveOrRestoreIntrinsic(Instruction *I) {
- auto *LLVMI = cast<llvm::Instruction>(I->Val);
- return match(LLVMI,
- PatternMatch::m_Intrinsic<llvm::Intrinsic::stackrestore>()) ||
- match(LLVMI,
- PatternMatch::m_Intrinsic<llvm::Intrinsic::stacksave>());
+ if (auto *II = dyn_cast<IntrinsicInst>(I)) {
+ auto IID = II->getIntrinsicID();
+ return IID == Intrinsic::stackrestore || IID == Intrinsic::stacksave;
+ }
+ return false;
+ }
+
+ /// \Returns true if intrinsic \p I touches memory. This is used by the
+ /// dependency graph.
+ static bool isMemIntrinsic(IntrinsicInst *II) {
+ auto IID = II->getIntrinsicID();
+ return IID != Intrinsic::sideeffect && IID != Intrinsic::pseudoprobe;
}
/// We consider \p I as a Memory Dependency Candidate instruction if it
/// reads/write memory or if it has side-effects. This is used by the
/// dependency graph.
static bool isMemDepCandidate(Instruction *I) {
- auto *LLVMI = cast<llvm::Instruction>(I->Val);
- return LLVMI->mayReadOrWriteMemory() &&
- (!isa<llvm::IntrinsicInst>(LLVMI) ||
- (cast<llvm::IntrinsicInst>(LLVMI)->getIntrinsicID() !=
- Intrinsic::sideeffect &&
- cast<llvm::IntrinsicInst>(LLVMI)->getIntrinsicID() !=
- Intrinsic::pseudoprobe));
+ IntrinsicInst *II;
+ return I->mayReadOrWriteMemory() &&
+ (!(II = dyn_cast<IntrinsicInst>(I)) || isMemIntrinsic(II));
}
};
} // namespace llvm::sandboxir
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
index 2a17e90d7dab84..e67051821e85ce 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
@@ -61,6 +61,7 @@ class DGNode {
virtual ~DGNode() = default;
/// \Returns true if this is before \p Other in program order.
bool comesBefore(const DGNode *Other) { return I->comesBefore(Other->I); }
+
/// \Returns true if \p I is a memory dependency candidate instruction.
static bool isMemDepNodeCandidate(Instruction *I) {
AllocaInst *Alloca;
diff --git a/llvm/unittests/SandboxIR/UtilsTest.cpp b/llvm/unittests/SandboxIR/UtilsTest.cpp
index 41317e4ab46684..fd7c423fef75a1 100644
--- a/llvm/unittests/SandboxIR/UtilsTest.cpp
+++ b/llvm/unittests/SandboxIR/UtilsTest.cpp
@@ -287,3 +287,31 @@ define void @foo(i8 %v1, ptr %ptr) {
EXPECT_TRUE(Utils::isMemDepCandidate(CallBar));
EXPECT_FALSE(Utils::isMemDepCandidate(Ret));
}
+
+TEST_F(UtilsTest, Instruction_isMemIntrinsic) {
+ parseIR(C, R"IR(
+declare void @llvm.sideeffect()
+declare void @llvm.pseudoprobe(i64)
+declare void @llvm.assume(i1)
+
+define void @foo(ptr %ptr, i1 %cond) {
+ call void @llvm.sideeffect()
+ call void @llvm.pseudoprobe(i64 42)
+ call void @llvm.assume(i1 %cond)
+ ret void
+}
+)IR");
+ llvm::Function *LLVMF = &*M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+ sandboxir::Function *F = Ctx.createFunction(LLVMF);
+ auto *BB = &*F->begin();
+ auto It = BB->begin();
+ auto *SideEffect = cast<sandboxir::IntrinsicInst>(&*It++);
+ auto *PseudoProbe = cast<sandboxir::IntrinsicInst>(&*It++);
+ auto *OtherIntrinsic = cast<sandboxir::IntrinsicInst>(&*It++);
+ using Utils = sandboxir::Utils;
+
+ EXPECT_FALSE(Utils::isMemIntrinsic(SideEffect));
+ EXPECT_FALSE(Utils::isMemIntrinsic(PseudoProbe));
+ EXPECT_TRUE(Utils::isMemIntrinsic(OtherIntrinsic));
+}
More information about the llvm-commits
mailing list