From e05fdab1250c0956ef9fc87fe764c9f0c144304d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 27 Apr 2021 09:21:28 -0700 Subject: [PATCH] [TableGen] Add predicate checks to isel patterns for default HwMode. As discussed in D100691 and based on 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. Reviewed By: kparzysz Differential Revision: https://reviews.llvm.org/D101240 --- llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 23 +++++++--------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index aee232e559ed..95d75815466d 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -4306,11 +4306,11 @@ static void collectModes(std::set &Modes, const TreePatternNode *N) { void CodeGenDAGPatterns::ExpandHwModeBasedTypes() { const CodeGenHwModes &CGH = getTargetInfo().getHwModes(); - std::map> ModeChecks; std::vector Copy; PatternsToMatch.swap(Copy); - auto AppendPattern = [this, &ModeChecks](PatternToMatch &P, unsigned Mode) { + auto AppendPattern = [this](PatternToMatch &P, unsigned Mode, + ArrayRef Check) { TreePatternNodePtr NewSrc = P.getSrcPattern()->clone(); TreePatternNodePtr NewDst = P.getDstPattern()->clone(); if (!NewSrc->setDefaultMode(Mode) || !NewDst->setDefaultMode(Mode)) { @@ -4318,8 +4318,7 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() { } std::vector Preds = P.getPredicates(); - const std::vector &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 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() { // 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 DefaultPred; + SmallVector 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); } }