diff options
author | Roman Tereshin <rtereshin@apple.com> | 2018-05-23 21:30:16 +0000 |
---|---|---|
committer | Roman Tereshin <rtereshin@apple.com> | 2018-05-23 21:30:16 +0000 |
commit | 9a9fa49cd27166009891a38d138b66f9b2583aed (patch) | |
tree | 825949ee267248ece8028c63d4ee3b1bb627c320 /llvm/utils/TableGen/GlobalISelEmitter.cpp | |
parent | 4c4a2ba35390d6cfb7e23387f24811ebdfe68d2b (diff) | |
download | bcm5719-llvm-9a9fa49cd27166009891a38d138b66f9b2583aed.tar.gz bcm5719-llvm-9a9fa49cd27166009891a38d138b66f9b2583aed.zip |
[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
Diffstat (limited to 'llvm/utils/TableGen/GlobalISelEmitter.cpp')
-rw-r--r-- | llvm/utils/TableGen/GlobalISelEmitter.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
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<PredicateMatcher> 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<LLTOperandMatcher>(&**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<RuleMatcher> 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<RuleMatcher *>(*T); + if (!R->getFirstConditionAsRootType().get().isValid()) + break; + ++T; + } + std::stable_sort(F, T, [](Matcher *A, Matcher *B) { + auto *L = static_cast<RuleMatcher *>(A); + auto *R = static_cast<RuleMatcher *>(B); + return L->getFirstConditionAsRootType() < + R->getFirstConditionAsRootType(); + }); + if (T != E) + F = ++T; + } GlobalISelEmitter::optimizeRules<GroupMatcher>(Matchers, MatcherStorage) .swap(Matchers); } |