Make tblgen emit:

tblgen: In ZAPNOTi: Cannot use 'IZAPX' in an input pattern!
for a bad pattern, instead of an ugly assertion.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23854 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-10-21 01:19:59 +00:00
parent 405e3ecb56
commit edbd8711de
2 changed files with 26 additions and 11 deletions

View File

@ -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<TreePatternNode*> 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();

View File

@ -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.
///