[llvm] 2f43e65 - [LLVM][TableGen] Check name conflicts between target dep and independent intrinsics (#109826)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 12:01:22 PDT 2024
Author: Rahul Joshi
Date: 2024-09-25T12:01:17-07:00
New Revision: 2f43e65955565f92d3103b4bd57f17d02385d0e3
URL: https://github.com/llvm/llvm-project/commit/2f43e65955565f92d3103b4bd57f17d02385d0e3
DIFF: https://github.com/llvm/llvm-project/commit/2f43e65955565f92d3103b4bd57f17d02385d0e3.diff
LOG: [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.
Added:
llvm/test/TableGen/intrinsic-target-prefix-for-target-independent.td
Modified:
llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
Removed:
################################################################################
diff --git a/llvm/test/TableGen/intrinsic-target-prefix-for-target-independent.td b/llvm/test/TableGen/intrinsic-target-prefix-for-target-independent.td
new file mode 100644
index 00000000000000..84e365f02d968c
--- /dev/null
+++ b/llvm/test/TableGen/intrinsic-target-prefix-for-target-independent.td
@@ -0,0 +1,9 @@
+// RUN: not llvm-tblgen -gen-intrinsic-enums -I %p/../../include %s 2>&1 | FileCheck %s -DFILE=%s
+
+include "llvm/IR/Intrinsics.td"
+
+// Check that target independent intrinsics with a prefix that matches a target
+// name are flagged.
+// CHECK: [[FILE]]:[[@LINE+1]]:5: error: target independent intrinsic `llvm.aarch64.foo' has prefix `llvm.aarch64` that conflicts with intrinsics for target `aarch64`
+def int_aarch64_foo : Intrinsic<[],[]>;
+
diff --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
index a30dc72a83154a..c3bd7efd8387a8 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
@@ -75,6 +75,7 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
Targets.back().Count = Intrinsics.size() - Targets.back().Offset;
CheckDuplicateIntrinsics();
+ CheckTargetIndependentIntrinsics();
}
// Check for duplicate intrinsic names.
@@ -101,6 +102,28 @@ void CodeGenIntrinsicTable::CheckDuplicateIntrinsics() const {
PrintFatalNote(First.TheDef, "Previous definition here");
}
+// For target independent intrinsics, check that their second dotted component
+// does not match any target name.
+void CodeGenIntrinsicTable::CheckTargetIndependentIntrinsics() const {
+ SmallDenseSet<StringRef> TargetNames;
+ for (const auto &Target : ArrayRef(Targets).drop_front())
+ TargetNames.insert(Target.Name);
+
+ // Set of target independent intrinsics.
+ const auto &Set = Targets[0];
+ for (const auto &Int : ArrayRef(&Intrinsics[Set.Offset], Set.Count)) {
+ StringRef Name = Int.Name;
+ StringRef Prefix = Name.drop_front(5).split('.').first;
+ if (!TargetNames.contains(Prefix))
+ continue;
+ PrintFatalError(Int.TheDef,
+ "target independent intrinsic `" + Name +
+ "' has prefix `llvm." + Prefix +
+ "` that conflicts with intrinsics for target `" +
+ Prefix + "`");
+ }
+}
+
CodeGenIntrinsic &CodeGenIntrinsicMap::operator[](const Record *Record) {
if (!Record->isSubClassOf("Intrinsic"))
PrintFatalError("Intrinsic defs should be subclass of 'Intrinsic' class");
diff --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
index 2df598da3f2507..1cdeaacd52dcdb 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
@@ -192,6 +192,7 @@ class CodeGenIntrinsicTable {
private:
void CheckDuplicateIntrinsics() const;
+ void CheckTargetIndependentIntrinsics() const;
};
// This class builds `CodeGenIntrinsic` on demand for a given Def.
More information about the llvm-commits
mailing list