From 1f39e2910b896dddaa649e72e2bdab1fa91be6c1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 14 Sep 2005 00:09:24 +0000 Subject: [PATCH] start parsing instructions into patterns, start doing many more checks of 'set's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23343 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/DAGISelEmitter.cpp | 60 ++++++++++++++++++++++++++++--- utils/TableGen/DAGISelEmitter.h | 5 +++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index dd4256bc703..22031b3f034 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -654,17 +654,66 @@ void DAGISelEmitter::ParseAndResolveInstructions() { I->error("Could not infer all types in pattern!"); } - // Verify that the top-level forms in the instruction are of void type. - for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j) - if (I->getTree(j)->getType() != MVT::isVoid) { + // Verify that the top-level forms in the instruction are of void type, and + // figure out how many of the instruction operands are destinations. + for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j) { + TreePatternNode *Pat = I->getTree(j); + if (Pat->getType() != MVT::isVoid) { I->dump(); I->error("Top-level forms in instruction pattern should have" " void types"); } - + + // Investigate sets. + if (Pat->getOperator()->getName() == "set") { + if (Pat->getNumChildren() == 0) + I->error("set requires operands!"); + else if (Pat->getNumChildren() & 1) + I->error("set requires an even number of operands"); + + // Check the set destinations. + unsigned NumValues = Pat->getNumChildren()/2; + for (unsigned i = 0; i != NumValues; ++i) { + TreePatternNode *Dest = Pat->getChild(i); + if (!Dest->isLeaf()) + I->error("set destination should be a virtual register!"); + + DefInit *Val = dynamic_cast(Dest->getLeafValue()); + if (!Val) + I->error("set destination should be a virtual register!"); + + if (!Val->getDef()->isSubClassOf("RegisterClass")) + I->error("set destination should be a virtual register!"); + } + } + } + DEBUG(I->dump()); Instructions.push_back(I); } + + // If we can, convert the instructions to be a patterns that are matched! + for (unsigned i = 0, e = Instructions.size(); i != e; ++i) { + TreePattern *I = Instructions[i]; + + if (I->getNumTrees() != 1) { + std::cerr << "CANNOT HANDLE: " << I->getRecord()->getName() << " yet!"; + continue; + } + TreePatternNode *Pattern = I->getTree(0); + if (Pattern->getOperator()->getName() != "set") + continue; // Not a set (store or something?) + + if (Pattern->getNumChildren() != 2) + continue; // Not a set of a single value (not handled so far) + + TreePatternNode *SrcPattern = Pattern->getChild(1)->clone(); + TreePatternNode *DstPattern = SrcPattern->clone(); // FIXME: WRONG + PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern)); + DEBUG(std::cerr << "PATTERN TO MATCH: "; SrcPattern->dump(); + std::cerr << "\nRESULT DAG : "; + DstPattern->dump(); std::cerr << "\n"); + } } void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { @@ -697,6 +746,9 @@ void DAGISelEmitter::run(std::ostream &OS) { EmitSourceFileHeader("DAG Instruction Selector for the " + Target.getName() + " target", OS); + OS << "// *** NOTE: This file is #included into the middle of the target\n" + << "// *** instruction selector class. These functions are really " + << "methods.\n\n"; ParseNodeInfo(); ParseNodeTransforms(OS); ParseAndResolvePatternFragments(OS); diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index d9668552db8..a2409bb8550 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -286,6 +286,11 @@ class DAGISelEmitter : public TableGenBackend { std::map > SDNodeXForms; std::map PatternFragments; std::vector Instructions; + + /// PatternsToMatch - All of the things we are matching on the DAG. The first + /// value is the pattern to match, the second pattern is the result to + /// emit. + std::vector > PatternsToMatch; public: DAGISelEmitter(RecordKeeper &R) : Records(R) {} -- 2.34.1