[llvm] [TableGen][GlobalISel] Use `GIM_SwitchOpcode` in Combiners (PR #66864)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 20 00:05:44 PDT 2023
https://github.com/Pierre-vh created https://github.com/llvm/llvm-project/pull/66864
The call to `initOpcodeValuesMap` was missing, causing the MatchTable to (unintentionally) not emit a `SwitchMatcher`. Also adds other code imported from `GlobalISelEmitter.cpp` to ensure rules are sorted by precedence as well.
Overall this improves GlobalISel compile-time performance by a noticeable amount. See #66751
>From f2394dbed2eaf04471d8bd6dca1e23e7d1f7a4b4 Mon Sep 17 00:00:00 2001
From: pvanhout <pierre.vanhoutryve at amd.com>
Date: Wed, 20 Sep 2023 09:04:30 +0200
Subject: [PATCH] [TableGen][GlobalISel] Allow formating of `GIM_SwitchOpcode`
The call to `initOpcodeValuesMap` was missing, causing the MatchTable to never emit a `SwitchMatcher`.
Also adds other code imported frorm `GlobalISelEmitter.cpp` to ensure rules are sorted by precedence as welll.
Overall this improves GlobalISel performance by a noticeable amount.
See #66751
---
llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
index 08a4db2fb3dec91..b28915148ee5169 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
@@ -3652,6 +3652,9 @@ void GICombinerEmitter::gatherRules(
}
void GICombinerEmitter::run(raw_ostream &OS) {
+ InstructionOpcodeMatcher::initOpcodeValuesMap(Target);
+ LLTOperandMatcher::initTypeIDValuesMap();
+
Records.startTimer("Gather rules");
std::vector<RuleMatcher> Rules;
gatherRules(Rules, Combiner->getValueAsListOfDefs("Rules"));
@@ -3666,6 +3669,16 @@ void GICombinerEmitter::run(raw_ostream &OS) {
for (const auto &Rule : Rules)
MaxTemporaries = std::max(MaxTemporaries, Rule.countRendererFns());
+ llvm::stable_sort(Rules, [&](const RuleMatcher &A, const RuleMatcher &B) {
+ if (A.isHigherPriorityThan(B)) {
+ assert(!B.isHigherPriorityThan(A) && "Cannot be more important "
+ "and less important at "
+ "the same time");
+ return true;
+ }
+ return false;
+ });
+
const MatchTable Table = buildMatchTable(Rules);
Records.startTimer("Emit combiner");
More information about the llvm-commits
mailing list