Skip to content

[LLVM][TableGen] Check name conflicts between target dep and independent intrinsics #109826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<[],[]>;

23 changes: 23 additions & 0 deletions llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
Targets.back().Count = Intrinsics.size() - Targets.back().Offset;

CheckDuplicateIntrinsics();
CheckTargetIndependentIntrinsics();
}

// Check for duplicate intrinsic names.
Expand All @@ -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");
Expand Down
1 change: 1 addition & 0 deletions llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class CodeGenIntrinsicTable {

private:
void CheckDuplicateIntrinsics() const;
void CheckTargetIndependentIntrinsics() const;
};

// This class builds `CodeGenIntrinsic` on demand for a given Def.
Expand Down
Loading