start building the instruction dest pattern correctly. Change the xform
authorChris Lattner <sabre@nondot.org>
Wed, 14 Sep 2005 22:55:26 +0000 (22:55 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Sep 2005 22:55:26 +0000 (22:55 +0000)
functions to preserve the Record for the xform instead of making it into a
function name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23361 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelEmitter.cpp
utils/TableGen/DAGISelEmitter.h

index 847e7ac6631d1a7ef38c66ab2ee71d275277d4ac..952100ced8a4cf93e1469cfc56ca2496e564d164 100644 (file)
@@ -203,8 +203,8 @@ void TreePatternNode::print(std::ostream &OS) const {
   
   if (!PredicateFn.empty())
     OS << "<<P:" << PredicateFn << ">>";
-  if (!TransformFn.empty())
-    OS << "<<X:" << TransformFn << ">>";
+  if (TransformFn)
+    OS << "<<X:" << TransformFn->getName() << ">>";
   if (!getName().empty())
     OS << ":$" << getName();
 
@@ -598,7 +598,7 @@ void DAGISelEmitter::ParseAndResolvePatternFragments(std::ostream &OS) {
     // it.
     Record *Transform = Fragments[i]->getValueAsDef("OperandTransform");
     if (!getSDNodeTransform(Transform).second.empty())    // not noop xform?
-      P->getOnlyTree()->setTransformFn("Transform_"+Transform->getName());
+      P->getOnlyTree()->setTransformFn(Transform);
   }
   
   OS << "\n\n";
@@ -814,7 +814,8 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
     // Loop over the inputs next.  Make a copy of InstInputs so we can destroy
     // the copy while we're checking the inputs.
     std::map<std::string, TreePatternNode*> InstInputsCheck(InstInputs);
-    
+
+    std::vector<TreePatternNode*> ResultNodeOperands;
     for (unsigned i = NumResults, e = CGI.OperandList.size(); i != e; ++i) {
       const std::string &OpName = CGI.OperandList[i].Name;
       if (OpName.empty())
@@ -824,20 +825,26 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
         I->error("Operand $" + OpName +
                  " does not appear in the instruction pattern");
       TreePatternNode *InVal = InstInputsCheck[OpName];
-      InstInputsCheck.erase(OpName);
+      InstInputsCheck.erase(OpName);   // It occurred, remove from map.
       if (CGI.OperandList[i].Ty != InVal->getType())
         I->error("Operand $" + OpName +
                  "'s type disagrees between the operand and pattern");
+      
+      ResultNodeOperands.push_back(InVal->clone());
     }
     
     if (!InstInputsCheck.empty())
       I->error("Input operand $" + InstInputsCheck.begin()->first +
                " occurs in pattern but not in operands list!");
-               
+
+    TreePatternNode *ResultPattern =
+      new TreePatternNode(I->getRecord(), ResultNodeOperands);
+    
     unsigned NumOperands = CGI.OperandList.size()-NumResults;
      
     DEBUG(I->dump());
-    Instructions.push_back(DAGInstruction(I, NumResults, NumOperands));
+    Instructions.push_back(DAGInstruction(I, NumResults, NumOperands,
+                                          ResultPattern));
   }
    
   // If we can, convert the instructions to be patterns that are matched!
@@ -856,7 +863,7 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
       continue;  // Not a set of a single value (not handled so far)
     
     TreePatternNode *SrcPattern = Pattern->getChild(1)->clone();
-    TreePatternNode *DstPattern = SrcPattern->clone();  // FIXME: WRONG
+    TreePatternNode *DstPattern = Instructions[i].getResultPattern();
     PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern));
     DEBUG(std::cerr << "PATTERN TO MATCH: "; SrcPattern->dump();
           std::cerr << "\nRESULT DAG      : ";
index e948ce0618fff6994badac275556efdeb0f18db1..d1381e65eef8a55f51e16ac7317fdb98fe02247d 100644 (file)
@@ -122,14 +122,15 @@ namespace llvm {
     
     /// TransformFn - The transformation function to execute on this node before
     /// it can be substituted into the resulting instruction on a pattern match.
-    std::string TransformFn;
+    Record *TransformFn;
     
     std::vector<TreePatternNode*> Children;
   public:
     TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch) 
-      : Ty(MVT::LAST_VALUETYPE), Operator(Op), Val(0), Children(Ch) {}
+      : Ty(MVT::LAST_VALUETYPE), Operator(Op), Val(0), TransformFn(0),
+        Children(Ch) {}
     TreePatternNode(Init *val)    // leaf ctor
-      : Ty(MVT::LAST_VALUETYPE), Operator(0), Val(val) {}
+      : Ty(MVT::LAST_VALUETYPE), Operator(0), Val(val), TransformFn(0) {}
     ~TreePatternNode();
     
     const std::string &getName() const { return Name; }
@@ -152,8 +153,8 @@ namespace llvm {
     const std::string &getPredicateFn() const { return PredicateFn; }
     void setPredicateFn(const std::string &Fn) { PredicateFn = Fn; }
 
-    const std::string &getTransformFn() const { return TransformFn; }
-    void setTransformFn(const std::string &Fn) { TransformFn = Fn; }
+    Record *getTransformFn() const { return TransformFn; }
+    void setTransformFn(Record *Fn) { TransformFn = Fn; }
     
     void print(std::ostream &OS) const;
     void dump() const;
@@ -278,13 +279,17 @@ namespace llvm {
     TreePattern *Pattern;
     unsigned NumResults;
     unsigned NumOperands;
+    TreePatternNode *ResultPattern;
   public:
-    DAGInstruction(TreePattern *TP, unsigned results, unsigned ops)
-      : Pattern(TP), NumResults(results), NumOperands(ops) {}
+    DAGInstruction(TreePattern *TP, unsigned results, unsigned ops,
+                   TreePatternNode *resultPattern)
+      : Pattern(TP), NumResults(results), NumOperands(ops), 
+        ResultPattern(resultPattern) {}
 
     TreePattern *getPattern() const { return Pattern; }
     unsigned getNumResults() const { return NumResults; }
     unsigned getNumOperands() const { return NumOperands; }
+    TreePatternNode *getResultPattern() const { return ResultPattern; }
   };