Skip to content

Commit 0f11011

Browse files
committed
TableGen: Add intrinsic property for norecurse
1 parent f37429b commit 0f11011

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def IntrNoReturn : IntrinsicProperty;
139139
// Applied by default.
140140
def IntrNoCallback : IntrinsicProperty<1>;
141141

142+
def IntrNoRecurse : IntrinsicProperty;
143+
142144
// IntrNoSync - Threads executing the intrinsic will not synchronize using
143145
// memory or other means. Applied by default.
144146
def IntrNoSync : IntrinsicProperty<1>;

llvm/test/TableGen/intrinsic-attrs.td

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ def int_random_gen : Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrHasSideEffec
66

77
def int_deref_ptr_ret : Intrinsic<[llvm_ptr_ty], [], [Dereferenceable<RetIndex, 16>]>;
88

9+
def int_no_recurse : Intrinsic<[llvm_i32_ty], [], [IntrNoRecurse]>;
10+
911
// CHECK: static AttributeSet getIntrinsicArgAttributeSet(LLVMContext &C, unsigned ID) {
1012
// CHECK-NEXT: switch (ID) {
1113
// CHECK-NEXT: default: llvm_unreachable("Invalid attribute set number");
@@ -21,11 +23,17 @@ def int_deref_ptr_ret : Intrinsic<[llvm_ptr_ty], [], [Dereferenceable<RetIndex,
2123
// CHECK-NEXT: return AttributeSet::get(C, {
2224
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
2325
// CHECK-NEXT: });
26+
// CHECK: case 1:
27+
// CHECK-NEXT: return AttributeSet::get(C, {
28+
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
29+
// CHECK-NEXT: Attribute::get(C, Attribute::NoRecurse),
30+
// CHECK-NEXT: });
2431

2532

2633
// CHECK: getAttributes(LLVMContext &C, ID id)
2734
// CHECK: 0 << 8 | 0, // llvm.deref.ptr.ret
28-
// CHECK: 1 << 8 | 1, // llvm.random.gen
35+
// CHECK: 1 << 8 | 1, // llvm.no.recurse
36+
// CHECK: 2 << 8 | 1, // llvm.random.gen
2937

3038
// CHECK: case 1:
3139
// CHECK-NEXT: return AttributeList::get(C, {

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ void CodeGenIntrinsic::setProperty(const Record *R) {
388388
isConvergent = true;
389389
else if (R->getName() == "IntrNoReturn")
390390
isNoReturn = true;
391+
else if (R->getName() == "IntrNoRecurse")
392+
isNoRecurse = true;
391393
else if (R->getName() == "IntrNoCallback")
392394
isNoCallback = true;
393395
else if (R->getName() == "IntrNoSync")

llvm/utils/TableGen/Basic/CodeGenIntrinsics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ struct CodeGenIntrinsic {
8989
/// True if the intrinsic is no-return.
9090
bool isNoReturn = false;
9191

92+
/// True if the intrinsic is norecurse.
93+
bool isNoRecurse = false;
94+
9295
/// True if the intrinsic is no-callback.
9396
bool isNoCallback = false;
9497

llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ static bool compareFnAttributes(const CodeGenIntrinsic *L,
416416
auto TieBoolAttributes = [](const CodeGenIntrinsic *I) -> auto {
417417
// Sort throwing intrinsics after non-throwing intrinsics.
418418
return std::tie(I->canThrow, I->isNoDuplicate, I->isNoMerge, I->isNoReturn,
419-
I->isNoCallback, I->isNoSync, I->isNoFree, I->isWillReturn,
420-
I->isCold, I->isConvergent, I->isSpeculatable,
421-
I->hasSideEffects, I->isStrictFP);
419+
I->isNoRecurse, I->isNoCallback, I->isNoSync, I->isNoFree,
420+
I->isWillReturn, I->isCold, I->isConvergent,
421+
I->isSpeculatable, I->hasSideEffects, I->isStrictFP);
422422
};
423423

424424
auto TieL = TieBoolAttributes(L);
@@ -440,10 +440,11 @@ static bool compareFnAttributes(const CodeGenIntrinsic *L,
440440
/// NoUnwind = !canThrow, so we need to negate it's sense to test if the
441441
// intrinsic has NoUnwind attribute.
442442
static bool hasFnAttributes(const CodeGenIntrinsic &Int) {
443-
return !Int.canThrow || Int.isNoReturn || Int.isNoCallback || Int.isNoSync ||
444-
Int.isNoFree || Int.isWillReturn || Int.isCold || Int.isNoDuplicate ||
445-
Int.isNoMerge || Int.isConvergent || Int.isSpeculatable ||
446-
Int.isStrictFP || getEffectiveME(Int) != MemoryEffects::unknown();
443+
return !Int.canThrow || Int.isNoReturn || Int.isNoRecurse ||
444+
Int.isNoCallback || Int.isNoSync || Int.isNoFree || Int.isWillReturn ||
445+
Int.isCold || Int.isNoDuplicate || Int.isNoMerge || Int.isConvergent ||
446+
Int.isSpeculatable || Int.isStrictFP ||
447+
getEffectiveME(Int) != MemoryEffects::unknown();
447448
}
448449

449450
namespace {
@@ -572,6 +573,8 @@ static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
572573
addAttribute("NoUnwind");
573574
if (Int.isNoReturn)
574575
addAttribute("NoReturn");
576+
if (Int.isNoRecurse)
577+
addAttribute("NoRecurse");
575578
if (Int.isNoCallback)
576579
addAttribute("NoCallback");
577580
if (Int.isNoSync)

0 commit comments

Comments
 (0)