Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Jan 30, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Jan 30, 2025

@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-tablegen

Author: Matt Arsenault (arsenm)

Changes

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 --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)

@arsenm arsenm marked this pull request as ready for review January 30, 2025 02:56
@github-actions
Copy link

github-actions bot commented Jan 30, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/add-intr-will-return-sendmsg branch from 804a16d to f37429b Compare January 30, 2025 03:01
@arsenm arsenm force-pushed the users/arsenm/tablegen/add-intrinsic-property-norecurse branch from 020be08 to 0f11011 Compare January 30, 2025 03:01
@jayfoad
Copy link
Contributor

jayfoad commented Jan 30, 2025

This needs motivation. What does norecurse mean for an intrinsic and how does it differ from nocallback? What sort of intrinsic would be norecurse but not nocallback?

Base automatically changed from users/arsenm/amdgpu/add-intr-will-return-sendmsg to main January 31, 2025 16:40
@arsenm
Copy link
Contributor Author

arsenm commented Feb 11, 2025

Replaced by #126782

@arsenm arsenm closed this Feb 11, 2025
@arsenm arsenm deleted the users/arsenm/tablegen/add-intrinsic-property-norecurse branch February 11, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants