summaryrefslogtreecommitdiff
path: root/utils/TableGen/DAGISelMatcherOpt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-03-03 06:28:15 +0000
committerChris Lattner <sabre@nondot.org>2010-03-03 06:28:15 +0000
commitcfe2eab7446dedc471592fe702fefef783383171 (patch)
treee9456a5376a26b03b053df780da66c7a3905f63f /utils/TableGen/DAGISelMatcherOpt.cpp
parent30174be37a97b8fbc395e92b5895fb8a89cc8c4e (diff)
downloadllvm-cfe2eab7446dedc471592fe702fefef783383171.tar.gz
llvm-cfe2eab7446dedc471592fe702fefef783383171.tar.bz2
llvm-cfe2eab7446dedc471592fe702fefef783383171.tar.xz
introduce a new SwitchTypeMatcher node (which is analogous to
SwitchOpcodeMatcher) and have DAGISelMatcherOpt form it. This speeds up selection, particularly for X86 which has lots of variants of instructions with only type differences. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97645 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/DAGISelMatcherOpt.cpp')
-rw-r--r--utils/TableGen/DAGISelMatcherOpt.cpp49
1 files changed, 38 insertions, 11 deletions
diff --git a/utils/TableGen/DAGISelMatcherOpt.cpp b/utils/TableGen/DAGISelMatcherOpt.cpp
index a625fa85d4..dc077a9909 100644
--- a/utils/TableGen/DAGISelMatcherOpt.cpp
+++ b/utils/TableGen/DAGISelMatcherOpt.cpp
@@ -14,7 +14,7 @@
#define DEBUG_TYPE "isel-opt"
#include "DAGISelMatcher.h"
#include "CodeGenDAGPatterns.h"
-#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -361,27 +361,39 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
// Check to see if all of the leading entries are now opcode checks. If so,
// we can convert this Scope to be a OpcodeSwitch instead.
- bool AllOpcodeChecks = true;
+ bool AllOpcodeChecks = true, AllTypeChecks = true;
for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) {
- if (isa<CheckOpcodeMatcher>(NewOptionsToMatch[i])) continue;
-
+ if (!isa<CheckOpcodeMatcher>(NewOptionsToMatch[i])) {
#if 0
- if (i > 3) {
- errs() << "FAILING OPC #" << i << "\n";
- NewOptionsToMatch[i]->dump();
+ if (i > 3 && AllOpcodeChecks) {
+ errs() << "FAILING OPC #" << i << "\n";
+ NewOptionsToMatch[i]->dump();
+ }
+#endif
+ AllOpcodeChecks = false;
}
+
+ if (!isa<CheckTypeMatcher>(NewOptionsToMatch[i]) ||
+ // iPTR checks could alias any other case without us knowing, don't
+ // bother with them.
+ cast<CheckTypeMatcher>(NewOptionsToMatch[i])->getType() == MVT::iPTR) {
+#if 0
+ if (i > 3 && AllTypeChecks) {
+ errs() << "FAILING TYPE #" << i << "\n";
+ NewOptionsToMatch[i]->dump();
+ }
#endif
-
- AllOpcodeChecks = false;
- break;
+ AllTypeChecks = false;
+ }
}
+ // TODO: Can also do CheckChildNType.
// If all the options are CheckOpcode's, we can form the SwitchOpcode, woot.
if (AllOpcodeChecks) {
StringSet<> Opcodes;
SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) {
- CheckOpcodeMatcher *COM =cast<CheckOpcodeMatcher>(NewOptionsToMatch[i]);
+ CheckOpcodeMatcher *COM = cast<CheckOpcodeMatcher>(NewOptionsToMatch[i]);
assert(Opcodes.insert(COM->getOpcode().getEnumName()) &&
"Duplicate opcodes not factored?");
Cases.push_back(std::make_pair(&COM->getOpcode(), COM->getNext()));
@@ -391,6 +403,21 @@ static void FactorNodes(OwningPtr<Matcher> &MatcherPtr) {
return;
}
+ // If all the options are CheckType's, we can form the SwitchType, woot.
+ if (AllTypeChecks) {
+ DenseSet<unsigned> Types;
+ SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases;
+ for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) {
+ CheckTypeMatcher *CTM = cast<CheckTypeMatcher>(NewOptionsToMatch[i]);
+ assert(Types.insert(CTM->getType()).second &&
+ "Duplicate types not factored?");
+ Cases.push_back(std::make_pair(CTM->getType(), CTM->getNext()));
+ }
+
+ MatcherPtr.reset(new SwitchTypeMatcher(&Cases[0], Cases.size()));
+ return;
+ }
+
// Reassemble the Scope node with the adjusted children.
Scope->setNumChildren(NewOptionsToMatch.size());