[llvm] [TableGen][GlobalISel] Use `GIM_SwitchOpcode` in Combiners (PR #66864)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 00:06:47 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/66864.diff


1 Files Affected:

- (modified) llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp (+13) 


``````````diff
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");

``````````

</details>


https://github.com/llvm/llvm-project/pull/66864


More information about the llvm-commits mailing list