From 8bda5afd91797d6475fcdda99750bfdf530c609f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 21 Oct 2005 01:19:59 +0000 Subject: [PATCH] Make tblgen emit: tblgen: In ZAPNOTi: Cannot use 'IZAPX' in an input pattern! for a bad pattern, instead of an ugly assertion. llvm-svn: 23854 --- llvm/utils/TableGen/DAGISelEmitter.cpp | 24 ++++++++++++++++-------- llvm/utils/TableGen/DAGISelEmitter.h | 13 ++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/llvm/utils/TableGen/DAGISelEmitter.cpp b/llvm/utils/TableGen/DAGISelEmitter.cpp index 8fbbb05f0f8a..baf6b4873cb0 100644 --- a/llvm/utils/TableGen/DAGISelEmitter.cpp +++ b/llvm/utils/TableGen/DAGISelEmitter.cpp @@ -573,19 +573,22 @@ bool TreePatternNode::canPatternMatch(std::string &Reason, DAGISelEmitter &ISE){ // TreePattern implementation // -TreePattern::TreePattern(Record *TheRec, ListInit *RawPat, +TreePattern::TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, DAGISelEmitter &ise) : TheRecord(TheRec), ISE(ise) { + isInputPattern = isInput; for (unsigned i = 0, e = RawPat->getSize(); i != e; ++i) Trees.push_back(ParseTreePattern((DagInit*)RawPat->getElement(i))); } -TreePattern::TreePattern(Record *TheRec, DagInit *Pat, +TreePattern::TreePattern(Record *TheRec, DagInit *Pat, bool isInput, DAGISelEmitter &ise) : TheRecord(TheRec), ISE(ise) { + isInputPattern = isInput; Trees.push_back(ParseTreePattern(Pat)); } -TreePattern::TreePattern(Record *TheRec, TreePatternNode *Pat, +TreePattern::TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput, DAGISelEmitter &ise) : TheRecord(TheRec), ISE(ise) { + isInputPattern = isInput; Trees.push_back(Pat); } @@ -638,6 +641,11 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) { Operator->getName() != "set") error("Unrecognized node '" + Operator->getName() + "'!"); + // Check to see if this is something that is illegal in an input pattern. + if (isInputPattern && (Operator->isSubClassOf("Instruction") || + Operator->isSubClassOf("SDNodeXForm"))) + error("Cannot use '" + Operator->getName() + "' in an input pattern!"); + std::vector Children; for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) { @@ -780,7 +788,7 @@ void DAGISelEmitter::ParsePatternFragments(std::ostream &OS) { OS << "\n// Predicate functions.\n"; for (unsigned i = 0, e = Fragments.size(); i != e; ++i) { DagInit *Tree = Fragments[i]->getValueAsDag("Fragment"); - TreePattern *P = new TreePattern(Fragments[i], Tree, *this); + TreePattern *P = new TreePattern(Fragments[i], Tree, true, *this); PatternFragments[Fragments[i]] = P; // Validate the argument list, converting it to map, to discard duplicates. @@ -1016,7 +1024,7 @@ void DAGISelEmitter::ParseInstructions() { } // Parse the instruction. - TreePattern *I = new TreePattern(Instrs[i], LI, *this); + TreePattern *I = new TreePattern(Instrs[i], LI, true, *this); // Inline pattern fragments into it. I->InlinePatternFragments(); @@ -1133,7 +1141,7 @@ void DAGISelEmitter::ParseInstructions() { // Use a temporary tree pattern to infer all types and make sure that the // constructed result is correct. This depends on the instruction already // being inserted into the Instructions map. - TreePattern Temp(I->getRecord(), ResultPattern, *this); + TreePattern Temp(I->getRecord(), ResultPattern, false, *this); Temp.InferAllTypes(); DAGInstruction &TheInsertedInst = Instructions.find(I->getRecord())->second; @@ -1175,7 +1183,7 @@ void DAGISelEmitter::ParsePatterns() { for (unsigned i = 0, e = Patterns.size(); i != e; ++i) { DagInit *Tree = Patterns[i]->getValueAsDag("PatternToMatch"); - TreePattern *Pattern = new TreePattern(Patterns[i], Tree, *this); + TreePattern *Pattern = new TreePattern(Patterns[i], Tree, true, *this); // Inline pattern fragments into it. Pattern->InlinePatternFragments(); @@ -1189,7 +1197,7 @@ void DAGISelEmitter::ParsePatterns() { if (LI->getSize() == 0) continue; // no pattern. // Parse the instruction. - TreePattern *Result = new TreePattern(Patterns[i], LI, *this); + TreePattern *Result = new TreePattern(Patterns[i], LI, false, *this); // Inline pattern fragments into it. Result->InlinePatternFragments(); diff --git a/llvm/utils/TableGen/DAGISelEmitter.h b/llvm/utils/TableGen/DAGISelEmitter.h index dbedbce2d2fe..dc9d1f7d6006 100644 --- a/llvm/utils/TableGen/DAGISelEmitter.h +++ b/llvm/utils/TableGen/DAGISelEmitter.h @@ -258,13 +258,20 @@ namespace llvm { /// ISE - the DAG isel emitter coordinating this madness. /// DAGISelEmitter &ISE; + + /// isInputPattern - True if this is an input pattern, something to match. + /// False if this is an output pattern, something to emit. + bool isInputPattern; public: /// TreePattern constructor - Parse the specified DagInits into the /// current record. - TreePattern(Record *TheRec, ListInit *RawPat, DAGISelEmitter &ise); - TreePattern(Record *TheRec, DagInit *Pat, DAGISelEmitter &ise); - TreePattern(Record *TheRec, TreePatternNode *Pat, DAGISelEmitter &ise); + TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, + DAGISelEmitter &ise); + TreePattern(Record *TheRec, DagInit *Pat, bool isInput, + DAGISelEmitter &ise); + TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput, + DAGISelEmitter &ise); /// getTrees - Return the tree patterns which corresponds to this pattern. ///