[llvm-branch-commits] [llvm] TableGen: Add intrinsic property for norecurse (PR #125015)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 29 18:54:18 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/125015.diff
5 Files Affected:
- (modified) llvm/include/llvm/IR/Intrinsics.td (+2)
- (modified) llvm/test/TableGen/intrinsic-attrs.td (+9-1)
- (modified) llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp (+2)
- (modified) llvm/utils/TableGen/Basic/CodeGenIntrinsics.h (+3)
- (modified) llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp (+4-2)
``````````diff
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index ee877349a33149..3d3dc5572f053d 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -139,6 +139,8 @@ def IntrNoReturn : IntrinsicProperty;
// Applied by default.
def IntrNoCallback : IntrinsicProperty<1>;
+def IntrNoRecurse : IntrinsicProperty;
+
// IntrNoSync - Threads executing the intrinsic will not synchronize using
// memory or other means. Applied by default.
def IntrNoSync : IntrinsicProperty<1>;
diff --git a/llvm/test/TableGen/intrinsic-attrs.td b/llvm/test/TableGen/intrinsic-attrs.td
index 579b5e8a21b868..70056d77ff9db4 100644
--- a/llvm/test/TableGen/intrinsic-attrs.td
+++ b/llvm/test/TableGen/intrinsic-attrs.td
@@ -6,6 +6,8 @@ def int_random_gen : Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrHasSideEffec
def int_deref_ptr_ret : Intrinsic<[llvm_ptr_ty], [], [Dereferenceable<RetIndex, 16>]>;
+def int_no_recurse : Intrinsic<[llvm_i32_ty], [], [IntrNoRecurse]>;
+
// CHECK: static AttributeSet getIntrinsicArgAttributeSet(LLVMContext &C, unsigned ID) {
// CHECK-NEXT: switch (ID) {
// CHECK-NEXT: default: llvm_unreachable("Invalid attribute set number");
@@ -21,11 +23,17 @@ def int_deref_ptr_ret : Intrinsic<[llvm_ptr_ty], [], [Dereferenceable<RetIndex,
// CHECK-NEXT: return AttributeSet::get(C, {
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
// CHECK-NEXT: });
+// CHECK: case 1:
+// CHECK-NEXT: return AttributeSet::get(C, {
+// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
+// CHECK-NEXT: Attribute::get(C, Attribute::NoRecurse),
+// CHECK-NEXT: });
// CHECK: getAttributes(LLVMContext &C, ID id)
// CHECK: 0 << 8 | 0, // llvm.deref.ptr.ret
-// CHECK: 1 << 8 | 1, // llvm.random.gen
+// CHECK: 1 << 8 | 1, // llvm.no.recurse
+// CHECK: 2 << 8 | 1, // llvm.random.gen
// CHECK: case 1:
// CHECK-NEXT: return AttributeList::get(C, {
diff --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
index 0846f66ea64529..fca7038fa020f8 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
@@ -388,6 +388,8 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
isConvergent = true;
else if (R->getName() == "IntrNoReturn")
isNoReturn = true;
+ else if (R->getName() == "IntrNoRecurse")
+ isNoRecurse = true;
else if (R->getName() == "IntrNoCallback")
isNoCallback = true;
else if (R->getName() == "IntrNoSync")
diff --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
index 8428d09a94009e..90267cb1ed7da5 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
@@ -89,6 +89,9 @@ struct CodeGenIntrinsic {
/// True if the intrinsic is no-return.
bool isNoReturn = false;
+ /// True if the intrinsic is norecurse.
+ bool isNoRecurse = false;
+
/// True if the intrinsic is no-callback.
bool isNoCallback = false;
diff --git a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
index 6b36fddcb4bcec..aa49e400bebf24 100644
--- a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
@@ -415,7 +415,7 @@ static bool compareFnAttributes(const CodeGenIntrinsic *L,
const CodeGenIntrinsic *R) {
auto TieBoolAttributes = [](const CodeGenIntrinsic *I) -> auto {
// Sort throwing intrinsics after non-throwing intrinsics.
- return std::tie(I->canThrow, I->isNoDuplicate, I->isNoMerge, I->isNoReturn,
+ return std::tie(I->canThrow, I->isNoDuplicate, I->isNoMerge, I->isNoReturn, I->isNoRecurse,
I->isNoCallback, I->isNoSync, I->isNoFree, I->isWillReturn,
I->isCold, I->isConvergent, I->isSpeculatable,
I->hasSideEffects, I->isStrictFP);
@@ -440,7 +440,7 @@ static bool compareFnAttributes(const CodeGenIntrinsic *L,
/// NoUnwind = !canThrow, so we need to negate it's sense to test if the
// intrinsic has NoUnwind attribute.
static bool hasFnAttributes(const CodeGenIntrinsic &Int) {
- return !Int.canThrow || Int.isNoReturn || Int.isNoCallback || Int.isNoSync ||
+ return !Int.canThrow || Int.isNoReturn || Int.isNoRecurse || Int.isNoCallback || Int.isNoSync ||
Int.isNoFree || Int.isWillReturn || Int.isCold || Int.isNoDuplicate ||
Int.isNoMerge || Int.isConvergent || Int.isSpeculatable ||
Int.isStrictFP || getEffectiveME(Int) != MemoryEffects::unknown();
@@ -567,6 +567,8 @@ static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
addAttribute("NoUnwind");
if (Int.isNoReturn)
addAttribute("NoReturn");
+ if (Int.isNoRecurse)
+ addAttribute("NoRecurse");
if (Int.isNoCallback)
addAttribute("NoCallback");
if (Int.isNoSync)
``````````
</details>
https://github.com/llvm/llvm-project/pull/125015
More information about the llvm-branch-commits
mailing list