diff options
Diffstat (limited to 'contrib/llvm/utils/TableGen/DAGISelMatcherGen.cpp')
| -rw-r--r-- | contrib/llvm/utils/TableGen/DAGISelMatcherGen.cpp | 78 |
1 files changed, 25 insertions, 53 deletions
diff --git a/contrib/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/contrib/llvm/utils/TableGen/DAGISelMatcherGen.cpp index a19b9e4b95c7..ce23651b9682 100644 --- a/contrib/llvm/utils/TableGen/DAGISelMatcherGen.cpp +++ b/contrib/llvm/utils/TableGen/DAGISelMatcherGen.cpp @@ -58,7 +58,7 @@ namespace { /// PatWithNoTypes - This is a clone of Pattern.getSrcPattern() that starts /// out with all of the types removed. This allows us to insert type checks /// as we scan the tree. - TreePatternNode *PatWithNoTypes; + TreePatternNodePtr PatWithNoTypes; /// VariableMap - A map from variable names ('$dst') to the recorded operand /// number that they were captured as. These are biased by 1 to make @@ -101,10 +101,6 @@ namespace { public: MatcherGen(const PatternToMatch &pattern, const CodeGenDAGPatterns &cgp); - ~MatcherGen() { - delete PatWithNoTypes; - } - bool EmitMatcherCode(unsigned Variant); void EmitResultCode(); @@ -134,10 +130,6 @@ namespace { return VarMapEntry-1; } - /// GetInstPatternNode - Get the pattern for an instruction. - const TreePatternNode *GetInstPatternNode(const DAGInstruction &Ins, - const TreePatternNode *N); - void EmitResultOperand(const TreePatternNode *N, SmallVectorImpl<unsigned> &ResultOps); void EmitResultOfNamedOperand(const TreePatternNode *N, @@ -521,7 +513,8 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) { } // Emit the matcher for the pattern structure and types. - EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes, Pattern.ForceMode); + EmitMatchCode(Pattern.getSrcPattern(), PatWithNoTypes.get(), + Pattern.ForceMode); // If the pattern has a predicate on it (e.g. only enabled when a subtarget // feature is around, do the check). @@ -533,7 +526,7 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) { // because they are generally more expensive to evaluate and more difficult to // factor. for (unsigned i = 0, e = MatchedComplexPatterns.size(); i != e; ++i) { - const TreePatternNode *N = MatchedComplexPatterns[i].first; + auto N = MatchedComplexPatterns[i].first; // Remember where the results of this match get stuck. if (N->isLeaf()) { @@ -664,28 +657,6 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N, N->dump(); } -/// GetInstPatternNode - Get the pattern for an instruction. -/// -const TreePatternNode *MatcherGen:: -GetInstPatternNode(const DAGInstruction &Inst, const TreePatternNode *N) { - const TreePattern *InstPat = Inst.getPattern(); - - // FIXME2?: Assume actual pattern comes before "implicit". - TreePatternNode *InstPatNode; - if (InstPat) - InstPatNode = InstPat->getTree(0); - else if (/*isRoot*/ N == Pattern.getDstPattern()) - InstPatNode = Pattern.getSrcPattern(); - else - return nullptr; - - if (InstPatNode && !InstPatNode->isLeaf() && - InstPatNode->getOperator()->getName() == "set") - InstPatNode = InstPatNode->getChild(InstPatNode->getNumChildren()-1); - - return InstPatNode; -} - static bool mayInstNodeLoadOrStore(const TreePatternNode *N, const CodeGenDAGPatterns &CGP) { @@ -723,25 +694,6 @@ EmitResultInstructionAsOperand(const TreePatternNode *N, CodeGenInstruction &II = CGT.getInstruction(Op); const DAGInstruction &Inst = CGP.getInstruction(Op); - // If we can, get the pattern for the instruction we're generating. We derive - // a variety of information from this pattern, such as whether it has a chain. - // - // FIXME2: This is extremely dubious for several reasons, not the least of - // which it gives special status to instructions with patterns that Pat<> - // nodes can't duplicate. - const TreePatternNode *InstPatNode = GetInstPatternNode(Inst, N); - - // NodeHasChain - Whether the instruction node we're creating takes chains. - bool NodeHasChain = InstPatNode && - InstPatNode->TreeHasProperty(SDNPHasChain, CGP); - - // Instructions which load and store from memory should have a chain, - // regardless of whether they happen to have an internal pattern saying so. - if (Pattern.getSrcPattern()->TreeHasProperty(SDNPHasChain, CGP) - && (II.hasCtrlDep || II.mayLoad || II.mayStore || II.canFoldAsLoad || - II.hasSideEffects)) - NodeHasChain = true; - bool isRoot = N == Pattern.getDstPattern(); // TreeHasOutGlue - True if this tree has glue. @@ -784,7 +736,7 @@ EmitResultInstructionAsOperand(const TreePatternNode *N, const DAGDefaultOperand &DefaultOp = CGP.getDefaultOperand(OperandNode); for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i) - EmitResultOperand(DefaultOp.DefaultOps[i], InstOps); + EmitResultOperand(DefaultOp.DefaultOps[i].get(), InstOps); continue; } @@ -895,6 +847,26 @@ EmitResultInstructionAsOperand(const TreePatternNode *N, NumNodesThatLoadOrStore != 1)); } + // Determine whether we need to attach a chain to this node. + bool NodeHasChain = false; + if (Pattern.getSrcPattern()->TreeHasProperty(SDNPHasChain, CGP)) { + // For some instructions, we were able to infer from the pattern whether + // they should have a chain. Otherwise, attach the chain to the root. + // + // FIXME2: This is extremely dubious for several reasons, not the least of + // which it gives special status to instructions with patterns that Pat<> + // nodes can't duplicate. + if (II.hasChain_Inferred) + NodeHasChain = II.hasChain; + else + NodeHasChain = isRoot; + // Instructions which load and store from memory should have a chain, + // regardless of whether they happen to have a pattern saying so. + if (II.hasCtrlDep || II.mayLoad || II.mayStore || II.canFoldAsLoad || + II.hasSideEffects) + NodeHasChain = true; + } + assert((!ResultVTs.empty() || TreeHasOutGlue || NodeHasChain) && "Node has no result"); |
