From 9a9fa49cd27166009891a38d138b66f9b2583aed Mon Sep 17 00:00:00 2001 From: Roman Tereshin Date: Wed, 23 May 2018 21:30:16 +0000 Subject: [GlobalISel][InstructionSelect] Sorting MatchTable's 2nd level by root LLT, perf patch 7 This patch continues a series of patches started by r332907 (reapplied as r332917). In this commit we sort rules within their 2nd level by the type check on def operand of the root instruction, which allows for better nesting grouping on the level. This is expected to decrease time GlobalISel spends in its InstructionSelect pass by roughly 22% for an -O0 build as measured on sqlite3-amalgamation (http://sqlite.org/download.html) targeting AArch64 (cross-compile on x86). Reviewers: qcolombet, dsanders, bogner, aemerson, javed.absar Reviewed By: qcolombet Subscribers: rovka, llvm-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D44700 llvm-svn: 333131 --- llvm/utils/TableGen/GlobalISelEmitter.cpp | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'llvm/utils/TableGen/GlobalISelEmitter.cpp') diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp index 785f88afe3d..e77151eab34 100644 --- a/llvm/utils/TableGen/GlobalISelEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp @@ -905,6 +905,7 @@ public: std::unique_ptr popFirstCondition() override; const PredicateMatcher &getFirstCondition() const override; + LLTCodeGen getFirstConditionAsRootType(); bool hasFirstCondition() const override; unsigned getNumOperands() const; StringRef getOpcode() const; @@ -1975,6 +1976,16 @@ unsigned RuleMatcher::getNumOperands() const { return Matchers.front()->getNumOperands(); } +LLTCodeGen RuleMatcher::getFirstConditionAsRootType() { + InstructionMatcher &InsnMatcher = *Matchers.front(); + if (!InsnMatcher.predicates_empty()) + if (const auto *TM = + dyn_cast(&**InsnMatcher.predicates_begin())) + if (TM->getInsnVarID() == 0 && TM->getOpIdx() == 0) + return TM->getTy(); + return {}; +} + /// Generates code to check that the operand is a register defined by an /// instruction that matches the given instruction matcher. /// @@ -4119,6 +4130,27 @@ GlobalISelEmitter::buildMatchTable(MutableArrayRef Rules, } void GroupMatcher::optimize() { + // Make sure we only sort by a specific predicate within a range of rules that + // all have that predicate checked against a specific value (not a wildcard): + auto F = Matchers.begin(); + auto T = F; + auto E = Matchers.end(); + while (T != E) { + while (T != E) { + auto *R = static_cast(*T); + if (!R->getFirstConditionAsRootType().get().isValid()) + break; + ++T; + } + std::stable_sort(F, T, [](Matcher *A, Matcher *B) { + auto *L = static_cast(A); + auto *R = static_cast(B); + return L->getFirstConditionAsRootType() < + R->getFirstConditionAsRootType(); + }); + if (T != E) + F = ++T; + } GlobalISelEmitter::optimizeRules(Matchers, MatcherStorage) .swap(Matchers); } -- cgit v1.2.3