From cfe2eab7446dedc471592fe702fefef783383171 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 3 Mar 2010 06:28:15 +0000 Subject: 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 --- utils/TableGen/DAGISelMatcherOpt.cpp | 49 ++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'utils/TableGen/DAGISelMatcherOpt.cpp') diff --git a/utils/TableGen/DAGISelMatcherOpt.cpp b/utils/TableGen/DAGISelMatcherOpt.cpp index a625fa8..dc077a9 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 &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(NewOptionsToMatch[i])) continue; - + if (!isa(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(NewOptionsToMatch[i]) || + // iPTR checks could alias any other case without us knowing, don't + // bother with them. + cast(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, 8> Cases; for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) { - CheckOpcodeMatcher *COM =cast(NewOptionsToMatch[i]); + CheckOpcodeMatcher *COM = cast(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 &MatcherPtr) { return; } + // If all the options are CheckType's, we can form the SwitchType, woot. + if (AllTypeChecks) { + DenseSet Types; + SmallVector, 8> Cases; + for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) { + CheckTypeMatcher *CTM = cast(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()); -- cgit v1.1