[llvm] [LLVM][TableGen] Speed up sorting of intrinsics (PR #109230)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 05:26:57 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/109230
>From fb3928dee7887fb01bb3d4c412da04dc9a125609 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 18 Sep 2024 21:34:00 -0700
Subject: [PATCH] [LLVM][TableGen] Speed up sorting of intrinsics
Speed up sorting of intrinsics by using the TargetPrefix to only
discriminate beteween target dependent vs target independent intrinsics
where target independent ones need to be sorted before target dependent
ones. When comaring two target dependent intrinsics, the Name already
includes llvm.<TargetPrefix> as a suffix, so no need to needlessly
compare it separately.
---
llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
index e566b7ceedf38e..a30dc72a83154a 100644
--- a/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
+++ b/llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
@@ -49,14 +49,21 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
for (const Record *Def : Defs)
Intrinsics.emplace_back(CodeGenIntrinsic(Def, Ctx));
- // To ensure deterministic sorted order when duplicates are present, use
- // record ID as a tie-breaker similar to sortAndReportDuplicates in Utils.cpp.
llvm::sort(Intrinsics,
[](const CodeGenIntrinsic &LHS, const CodeGenIntrinsic &RHS) {
+ // Order target independent intrinsics before target dependent
+ // ones.
+ bool LHSHasTarget = !LHS.TargetPrefix.empty();
+ bool RHSHasTarget = !RHS.TargetPrefix.empty();
+
+ // To ensure deterministic sorted order when duplicates are
+ // present, use record ID as a tie-breaker similar to
+ // sortAndReportDuplicates in Utils.cpp.
unsigned LhsID = LHS.TheDef->getID();
unsigned RhsID = RHS.TheDef->getID();
- return std::tie(LHS.TargetPrefix, LHS.Name, LhsID) <
- std::tie(RHS.TargetPrefix, RHS.Name, RhsID);
+
+ return std::tie(LHSHasTarget, LHS.Name, LhsID) <
+ std::tie(RHSHasTarget, RHS.Name, RhsID);
});
Targets.push_back({"", 0, 0});
More information about the llvm-commits
mailing list