[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp DAGISelEmitter.h

Chris Lattner lattner at cs.uiuc.edu
Tue Sep 13 14:51:11 PDT 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.10 -> 1.11
DAGISelEmitter.h updated: 1.9 -> 1.10
---
Log message:

Start parsing node transformation information


---
Diffs of the changes:  (+46 -6)

 DAGISelEmitter.cpp |   43 +++++++++++++++++++++++++++++++++++++------
 DAGISelEmitter.h   |    9 +++++++++
 2 files changed, 46 insertions(+), 6 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.10 llvm/utils/TableGen/DAGISelEmitter.cpp:1.11
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.10	Tue Sep 13 16:20:49 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Tue Sep 13 16:51:00 2005
@@ -202,7 +202,9 @@
   }
   
   if (!PredicateFn.empty())
-    OS << "<<" << PredicateFn << ">>";
+    OS << "<<P:" << PredicateFn << ">>";
+  if (!TransformFn.empty())
+    OS << "<<X:" << TransformFn << ">>";
   if (!getName().empty())
     OS << ":$" << getName();
 
@@ -227,6 +229,7 @@
   New->setName(getName());
   New->setType(getType());
   New->setPredicateFn(getPredicateFn());
+  New->setTransformFn(getTransformFn());
   return New;
 }
 
@@ -494,6 +497,35 @@
   }
 }
 
+/// ParseNodeTransforms - Parse all SDNodeXForm instances into the SDNodeXForms
+/// map, and emit them to the file as functions.
+void DAGISelEmitter::ParseNodeTransforms(std::ostream &OS) {
+  OS << "\n// Node transformations.\n";
+  std::vector<Record*> Xforms = Records.getAllDerivedDefinitions("SDNodeXForm");
+  while (!Xforms.empty()) {
+    Record *XFormNode = Xforms.back();
+    Record *SDNode = XFormNode->getValueAsDef("Opcode");
+    std::string Code = XFormNode->getValueAsCode("XFormFunction");
+    SDNodeXForms.insert(std::make_pair(XFormNode,
+                                       std::make_pair(SDNode, Code)));
+
+    if (!Code.empty()) {
+      std::string ClassName = getSDNodeInfo(SDNode).getSDClassName();
+      const char *C2 = ClassName == "SDNode" ? "N" : "inN";
+
+      OS << "static inline SDOperand Transform_" << XFormNode->getName()
+         << "(SDNode *" << C2 << ") {\n";
+      if (ClassName != "SDNode")
+        OS << "  " << ClassName << " *N = cast<" << ClassName << ">(inN);\n";
+      OS << Code << "\n}\n";
+    }
+
+    Xforms.pop_back();
+  }
+}
+
+
+
 /// ParseAndResolvePatternFragments - Parse all of the PatFrag definitions in
 /// the .td file, building up the PatternFragments map.  After we've collected
 /// them all, inline fragments together as necessary, so that there are no
@@ -546,9 +578,8 @@
 
     // If there is a code init for this fragment, emit the predicate code and
     // keep track of the fact that this fragment uses it.
-    CodeInit *CI =
-      dynamic_cast<CodeInit*>(Fragments[i]->getValueInit("Predicate"));
-    if (!CI->getValue().empty()) {
+    std::string Code = Fragments[i]->getValueAsCode("Predicate");
+    if (!Code.empty()) {
       assert(!P->getOnlyTree()->isLeaf() && "Can't be a leaf!");
       std::string ClassName =
         getSDNodeInfo(P->getOnlyTree()->getOperator()).getSDClassName();
@@ -558,7 +589,7 @@
          << "(SDNode *" << C2 << ") {\n";
       if (ClassName != "SDNode")
         OS << "  " << ClassName << " *N = cast<" << ClassName << ">(inN);\n";
-      OS << CI->getValue() << "\n}\n";
+      OS << Code << "\n}\n";
       P->getOnlyTree()->setPredicateFn("Predicate_"+Fragments[i]->getName());
     }
   }
@@ -657,12 +688,12 @@
      << "}\n";
 }
 
-
 void DAGISelEmitter::run(std::ostream &OS) {
   EmitSourceFileHeader("DAG Instruction Selector for the " + Target.getName() +
                        " target", OS);
   
   ParseNodeInfo();
+  ParseNodeTransforms(OS);
   ParseAndResolvePatternFragments(OS);
   ParseAndResolveInstructions();
   


Index: llvm/utils/TableGen/DAGISelEmitter.h
diff -u llvm/utils/TableGen/DAGISelEmitter.h:1.9 llvm/utils/TableGen/DAGISelEmitter.h:1.10
--- llvm/utils/TableGen/DAGISelEmitter.h:1.9	Tue Sep 13 16:20:49 2005
+++ llvm/utils/TableGen/DAGISelEmitter.h	Tue Sep 13 16:51:00 2005
@@ -120,6 +120,10 @@
     /// for a match.  If this string is empty, no predicate is involved.
     std::string PredicateFn;
     
+    /// 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;
+    
     std::vector<TreePatternNode*> Children;
   public:
     TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch) 
@@ -147,6 +151,9 @@
     
     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; }
     
     void print(std::ostream &OS) const;
     void dump() const;
@@ -276,6 +283,7 @@
   CodeGenTarget Target;
 
   std::map<Record*, SDNodeInfo> SDNodes;
+  std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
   std::map<Record*, TreePattern*> PatternFragments;
   std::vector<TreePattern*> Instructions;
 public:
@@ -296,6 +304,7 @@
   
 private:
   void ParseNodeInfo();
+  void ParseNodeTransforms(std::ostream &OS);
   void ParseAndResolvePatternFragments(std::ostream &OS);
   void ParseAndResolveInstructions();
   void EmitInstructionSelector(std::ostream &OS);






More information about the llvm-commits mailing list