[PATCH] D101240: [TableGen] Add predicate checks to isel patterns for default HwMode.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 24 14:05:58 PDT 2021


craig.topper created this revision.
craig.topper added a reviewer: kparzysz.
craig.topper requested review of this revision.
Herald added a project: LLVM.

As discussed in D100691 <https://reviews.llvm.org/D100691> and based on D100889 <https://reviews.llvm.org/D100889>.

I removed the ModeChecks cache which provides little value. Reduced
from three loops to two. Used ArrayRef to pass the Predicate to
AppendPattern to avoid needing to construct a vector for single
mode. Used SmallVector to avoid heap allocation constructing
DefaultCheck for the in tree targets the use it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101240

Files:
  llvm/utils/TableGen/CodeGenDAGPatterns.cpp


Index: llvm/utils/TableGen/CodeGenDAGPatterns.cpp
===================================================================
--- llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -4306,11 +4306,11 @@
 
 void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
   const CodeGenHwModes &CGH = getTargetInfo().getHwModes();
-  std::map<unsigned,std::vector<Predicate>> ModeChecks;
   std::vector<PatternToMatch> Copy;
   PatternsToMatch.swap(Copy);
 
-  auto AppendPattern = [this, &ModeChecks](PatternToMatch &P, unsigned Mode) {
+  auto AppendPattern = [this](PatternToMatch &P, unsigned Mode,
+                              ArrayRef<Predicate> Check) {
     TreePatternNodePtr NewSrc = P.getSrcPattern()->clone();
     TreePatternNodePtr NewDst = P.getDstPattern()->clone();
     if (!NewSrc->setDefaultMode(Mode) || !NewDst->setDefaultMode(Mode)) {
@@ -4318,8 +4318,7 @@
     }
 
     std::vector<Predicate> Preds = P.getPredicates();
-    const std::vector<Predicate> &MC = ModeChecks[Mode];
-    llvm::append_range(Preds, MC);
+    llvm::append_range(Preds, Check);
     PatternsToMatch.emplace_back(P.getSrcRecord(), std::move(Preds),
                                  std::move(NewSrc), std::move(NewDst),
                                  P.getDstRegs(),
@@ -4355,31 +4354,23 @@
     // duplicated patterns with different predicate checks, construct the
     // default check as a negation of all predicates that are actually present
     // in the source/destination patterns.
-    std::vector<Predicate> DefaultPred;
+    SmallVector<Predicate, 2> DefaultCheck;
 
     for (unsigned M : Modes) {
       if (M == DefaultMode)
         continue;
-      if (ModeChecks.find(M) != ModeChecks.end())
-        continue;
 
       // Fill the map entry for this mode.
       const HwMode &HM = CGH.getMode(M);
-      ModeChecks[M].emplace_back(Predicate(HM.Features, true));
+      AppendPattern(P, M, Predicate(HM.Features, true));
 
       // Add negations of the HM's predicates to the default predicate.
-      DefaultPred.emplace_back(Predicate(HM.Features, false));
-    }
-
-    for (unsigned M : Modes) {
-      if (M == DefaultMode)
-        continue;
-      AppendPattern(P, M);
+      DefaultCheck.push_back(Predicate(HM.Features, false));
     }
 
     bool HasDefault = Modes.count(DefaultMode);
     if (HasDefault)
-      AppendPattern(P, DefaultMode);
+      AppendPattern(P, DefaultMode, DefaultCheck);
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101240.340313.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210424/f5c06739/attachment.bin>


More information about the llvm-commits mailing list