[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:06:28 PDT 2023


https://github.com/Pierre-vh updated https://github.com/llvm/llvm-project/pull/66864

>From 88bd8fc957721b840d929d69caf48a6f342d6640 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] Use GIM_SwitchOpcode in Combiners`

The call to `initOpcodeValuesMap` was missing, causing the MatchTable to never emit a `SwitchMatcher`.
Also adds other code imported from `GlobalISelEmitter.cpp` to ensure rules are sorted by precedence as well.

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