From 0614b628cf8245541f0f6842b2f024c5ba9a7967 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 2 Nov 2005 06:49:14 +0000 Subject: [PATCH] Add support for immediates directly in the pattern, this allows itanium to define: def : Pat<(i1 1), (CMPEQ r0, r0)>; git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24149 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/DAGISelEmitter.cpp | 34 ++++++++++++++++++++++++++++--- utils/TableGen/DAGISelEmitter.h | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 2fc324dff6f..29206ce3b4c 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -621,6 +621,10 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) { New = new TreePatternNode(DI); } else if (DagInit *DI = dynamic_cast(Arg)) { New = ParseTreePattern(DI); + } else if (IntInit *II = dynamic_cast(Arg)) { + New = new TreePatternNode(II); + if (!Dag->getArgName(0).empty()) + error("Constant int argument should not have a name!"); } else { Arg->dump(); error("Unknown leaf value for tree pattern!"); @@ -1521,7 +1525,16 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N, const std::string &RootName, std::map &VarMap, unsigned PatternNo, std::ostream &OS) { - assert(!N->isLeaf() && "Cannot match against a leaf!"); + if (N->isLeaf()) { + if (IntInit *II = dynamic_cast(N->getLeafValue())) { + OS << " if (cast(" << RootName + << ")->getSignExtended() != " << II->getValue() << ")\n" + << " goto P" << PatternNo << "Fail;\n"; + return; + } + assert(0 && "Cannot match this as a leaf value!"); + abort(); + } // If this node has a name associated with it, capture it in VarMap. If // we already saw this in the pattern, emit code to verify dagness. @@ -1762,6 +1775,12 @@ static bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other, return false; } +Record *DAGISelEmitter::getSDNodeNamed(const std::string &Name) const { + Record *N = Records.getDef(Name); + assert(N && N->isSubClassOf("SDNode") && "Bad argument"); + return N; +} + /// EmitCodeForPattern - Given a pattern to match, emit code to the specified /// stream to match the pattern, and generate the code for the match if it /// succeeds. @@ -1897,8 +1916,17 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { std::map, CompareByRecordName> PatternsByOpcode; for (unsigned i = 0, e = PatternsToMatch.size(); i != e; ++i) - PatternsByOpcode[PatternsToMatch[i].first->getOperator()] - .push_back(&PatternsToMatch[i]); + if (!PatternsToMatch[i].first->isLeaf()) { + PatternsByOpcode[PatternsToMatch[i].first->getOperator()] + .push_back(&PatternsToMatch[i]); + } else { + if (IntInit *II = + dynamic_cast(PatternsToMatch[i].first->getLeafValue())) { + PatternsByOpcode[getSDNodeNamed("imm")].push_back(&PatternsToMatch[i]); + } else { + assert(0 && "Unknown leaf value"); + } + } // Loop over all of the case statements. for (std::map, diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index dc9d1f7d600..be307141d82 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -382,6 +382,8 @@ public: const CodeGenTarget &getTargetInfo() const { return Target; } + Record *getSDNodeNamed(const std::string &Name) const; + const SDNodeInfo &getSDNodeInfo(Record *R) const { assert(SDNodes.count(R) && "Unknown node!"); return SDNodes.find(R)->second; -- 2.34.1