diff options
| -rw-r--r-- | llvm/utils/TableGen/DAGISelEmitter.cpp | 60 | ||||
| -rw-r--r-- | llvm/utils/TableGen/DAGISelEmitter.h | 5 | 
2 files changed, 61 insertions, 4 deletions
| diff --git a/llvm/utils/TableGen/DAGISelEmitter.cpp b/llvm/utils/TableGen/DAGISelEmitter.cpp index dd4256bc703..22031b3f034 100644 --- a/llvm/utils/TableGen/DAGISelEmitter.cpp +++ b/llvm/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<DefInit*>(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/llvm/utils/TableGen/DAGISelEmitter.h b/llvm/utils/TableGen/DAGISelEmitter.h index d9668552db8..a2409bb8550 100644 --- a/llvm/utils/TableGen/DAGISelEmitter.h +++ b/llvm/utils/TableGen/DAGISelEmitter.h @@ -286,6 +286,11 @@ class DAGISelEmitter : public TableGenBackend {    std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;    std::map<Record*, TreePattern*> PatternFragments;    std::vector<TreePattern*> 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<std::pair<TreePatternNode*, TreePatternNode*> > PatternsToMatch;  public:    DAGISelEmitter(RecordKeeper &R) : Records(R) {} | 

