Skip to content

Commit 2f43e65

Browse files
authored
[LLVM][TableGen] Check name conflicts between target dep and independent intrinsics (#109826)
Validate that for target independent intrinsics the second dotted component of their name (after the `llvm.`) does not match any existing target names (for which atleast one intrinsic has been defined). Doing so is invalid as LLVM will search for that intrinsic in that target's intrinsic table and not find it, and conclude that its an unknown intrinsic.
1 parent c3334da commit 2f43e65

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not llvm-tblgen -gen-intrinsic-enums -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s
2+
3+
include "llvm/IR/Intrinsics.td"
4+
5+
// Check that target independent intrinsics with a prefix that matches a target
6+
// name are flagged.
7+
// CHECK: [[FILE]]:[[@LINE+1]]:5: error: target independent intrinsic `llvm.aarch64.foo' has prefix `llvm.aarch64` that conflicts with intrinsics for target `aarch64`
8+
def int_aarch64_foo : Intrinsic<[],[]>;
9+

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
7575
Targets.back().Count = Intrinsics.size() - Targets.back().Offset;
7676

7777
CheckDuplicateIntrinsics();
78+
CheckTargetIndependentIntrinsics();
7879
}
7980

8081
// Check for duplicate intrinsic names.
@@ -101,6 +102,28 @@ void CodeGenIntrinsicTable::CheckDuplicateIntrinsics() const {
101102
PrintFatalNote(First.TheDef, "Previous definition here");
102103
}
103104

105+
// For target independent intrinsics, check that their second dotted component
106+
// does not match any target name.
107+
void CodeGenIntrinsicTable::CheckTargetIndependentIntrinsics() const {
108+
SmallDenseSet<StringRef> TargetNames;
109+
for (const auto &Target : ArrayRef(Targets).drop_front())
110+
TargetNames.insert(Target.Name);
111+
112+
// Set of target independent intrinsics.
113+
const auto &Set = Targets[0];
114+
for (const auto &Int : ArrayRef(&Intrinsics[Set.Offset], Set.Count)) {
115+
StringRef Name = Int.Name;
116+
StringRef Prefix = Name.drop_front(5).split('.').first;
117+
if (!TargetNames.contains(Prefix))
118+
continue;
119+
PrintFatalError(Int.TheDef,
120+
"target independent intrinsic `" + Name +
121+
"' has prefix `llvm." + Prefix +
122+
"` that conflicts with intrinsics for target `" +
123+
Prefix + "`");
124+
}
125+
}
126+
104127
CodeGenIntrinsic &CodeGenIntrinsicMap::operator[](const Record *Record) {
105128
if (!Record->isSubClassOf("Intrinsic"))
106129
PrintFatalError("Intrinsic defs should be subclass of 'Intrinsic' class");

llvm/utils/TableGen/Basic/CodeGenIntrinsics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class CodeGenIntrinsicTable {
192192

193193
private:
194194
void CheckDuplicateIntrinsics() const;
195+
void CheckTargetIndependentIntrinsics() const;
195196
};
196197

197198
// This class builds `CodeGenIntrinsic` on demand for a given Def.

0 commit comments

Comments
 (0)