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

Chris Lattner lattner at cs.uiuc.edu
Sat Oct 15 18:42:10 PDT 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.57 -> 1.58
DAGISelEmitter.h updated: 1.32 -> 1.33
---
Log message:

Make the generated code significantly more memory efficient, by using 
SelectNodeTo instead of getTargetNode when possible.


---
Diffs of the changes:  (+37 -14)

 DAGISelEmitter.cpp |   49 ++++++++++++++++++++++++++++++++++++-------------
 DAGISelEmitter.h   |    2 +-
 2 files changed, 37 insertions(+), 14 deletions(-)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.57 llvm/utils/TableGen/DAGISelEmitter.cpp:1.58
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.57	Sat Oct 15 16:34:21 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Sat Oct 15 20:41:58 2005
@@ -1554,9 +1554,10 @@
 unsigned DAGISelEmitter::
 CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
                      std::map<std::string,std::string> &VariableMap, 
-                     std::ostream &OS) {
+                     std::ostream &OS, bool isRoot) {
   // This is something selected from the pattern we matched.
   if (!N->getName().empty()) {
+    assert(!isRoot && "Root of pattern cannot be a leaf!");
     std::string &Val = VariableMap[N->getName()];
     assert(!Val.empty() &&
            "Variable referenced but not defined and not caught earlier!");
@@ -1603,12 +1604,33 @@
     CodeGenInstruction &II = Target.getInstruction(Op->getName());
     unsigned ResNo = Ctr++;
     
-    OS << "      SDOperand Tmp" << ResNo << " = CurDAG->getTargetNode("
-       << II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
-       << getEnumName(N->getType());
-    for (unsigned i = 0, e = Ops.size(); i != e; ++i)
-      OS << ", Tmp" << Ops[i];
-    OS << ");\n";
+    if (!isRoot) {
+      OS << "      SDOperand Tmp" << ResNo << " = CurDAG->getTargetNode("
+         << II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
+         << getEnumName(N->getType());
+      for (unsigned i = 0, e = Ops.size(); i != e; ++i)
+        OS << ", Tmp" << Ops[i];
+      OS << ");\n";
+    } else {
+      // If this instruction is the root, and if there is only one use of it,
+      // use SelectNodeTo instead of getTargetNode to avoid an allocation.
+      OS << "      if (N.Val->hasOneUse()) {\n";
+      OS << "        CurDAG->SelectNodeTo(N.Val, "
+         << II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
+         << getEnumName(N->getType());
+      for (unsigned i = 0, e = Ops.size(); i != e; ++i)
+        OS << ", Tmp" << Ops[i];
+      OS << ");\n";
+      OS << "        return N;\n";
+      OS << "      } else {\n";
+      OS << "        return CodeGenMap[N] = CurDAG->getTargetNode("
+      << II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
+      << getEnumName(N->getType());
+      for (unsigned i = 0, e = Ops.size(); i != e; ++i)
+        OS << ", Tmp" << Ops[i];
+      OS << ");\n";
+      OS << "      }\n";
+    }
     return ResNo;
   } else if (Op->isSubClassOf("SDNodeXForm")) {
     assert(N->getNumChildren() == 1 && "node xform should have one child!");
@@ -1617,6 +1639,10 @@
     unsigned ResNo = Ctr++;
     OS << "      SDOperand Tmp" << ResNo << " = Transform_" << Op->getName()
        << "(Tmp" << OpVal << ".Val);\n";
+    if (isRoot) {
+      OS << "      CodeGenMap[N] = Tmp" << ResNo << ";\n";
+      OS << "      return Tmp" << ResNo << ";\n";
+    }
     return ResNo;
   } else {
     N->dump();
@@ -1712,13 +1738,10 @@
     // an unresolved type to add a check for, this returns true and we iterate,
     // otherwise we are done.
   } while (InsertOneTypeCheck(Pat, Pattern.first, "N", PatternNo, OS));
-    
-  unsigned TmpNo = 0;
-  unsigned Res = CodeGenPatternResult(Pattern.second, TmpNo, VariableMap, OS);
   
-  // Add the result to the map if it has multiple uses.
-  OS << "      if (!N.Val->hasOneUse()) CodeGenMap[N] = Tmp" << Res << ";\n";
-  OS << "      return Tmp" << Res << ";\n";
+  unsigned TmpNo = 0;
+  CodeGenPatternResult(Pattern.second, TmpNo,
+                       VariableMap, OS, true /*the root*/);
   delete Pat;
   
   OS << "    }\n  P" << PatternNo << "Fail:\n";


Index: llvm/utils/TableGen/DAGISelEmitter.h
diff -u llvm/utils/TableGen/DAGISelEmitter.h:1.32 llvm/utils/TableGen/DAGISelEmitter.h:1.33
--- llvm/utils/TableGen/DAGISelEmitter.h:1.32	Fri Oct 14 01:12:03 2005
+++ llvm/utils/TableGen/DAGISelEmitter.h	Sat Oct 15 20:41:58 2005
@@ -411,7 +411,7 @@
                            unsigned PatternNo, std::ostream &OS);
   unsigned CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
                                 std::map<std::string,std::string> &VariableMap, 
-                                std::ostream &OS);      
+                                std::ostream &OS, bool isRoot = false);      
   void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
   void EmitInstructionSelector(std::ostream &OS);
 };






More information about the llvm-commits mailing list