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

Chris Lattner lattner at cs.uiuc.edu
Thu Aug 18 14:36:58 PDT 2005



Changes in directory llvm/utils/TableGen:

InstrInfoEmitter.cpp updated: 1.19 -> 1.20
InstrInfoEmitter.h updated: 1.8 -> 1.9
---
Log message:

When emitting implicit use/def lists, only emit each unique list once.  Though
LLVM is able to merge identical static const globals, GCC isn't, and this caused
some bloat in the generated data.  This has a marginal effect on PPC, shrinking
the implicit sets from 10->4, but shrinks X86 from 179 to 23, a much bigger
reduction.

This should speed up the register allocator as well by reducing the dcache
footprint for this static data.



---
Diffs of the changes:  (+47 -20)

 InstrInfoEmitter.cpp |   59 +++++++++++++++++++++++++++++++++++----------------
 InstrInfoEmitter.h   |    8 +++++-
 2 files changed, 47 insertions(+), 20 deletions(-)


Index: llvm/utils/TableGen/InstrInfoEmitter.cpp
diff -u llvm/utils/TableGen/InstrInfoEmitter.cpp:1.19 llvm/utils/TableGen/InstrInfoEmitter.cpp:1.20
--- llvm/utils/TableGen/InstrInfoEmitter.cpp:1.19	Thu Aug 18 14:45:37 2005
+++ llvm/utils/TableGen/InstrInfoEmitter.cpp	Thu Aug 18 16:36:47 2005
@@ -46,14 +46,21 @@
   OS << "} // End llvm namespace \n";
 }
 
-void InstrInfoEmitter::printDefList(ListInit *LI, const std::string &Name,
-                                    std::ostream &OS) const {
-  OS << "static const unsigned " << Name << "[] = { ";
-  for (unsigned j = 0, e = LI->getSize(); j != e; ++j)
-    if (DefInit *DI = dynamic_cast<DefInit*>(LI->getElement(j)))
-      OS << getQualifiedName(DI->getDef()) << ", ";
+static std::vector<Record*> GetDefList(ListInit *LI, const std::string &Name) {
+  std::vector<Record*> Result;
+  for (unsigned i = 0, e = LI->getSize(); i != e; ++i)
+    if (DefInit *DI = dynamic_cast<DefInit*>(LI->getElement(i)))
+      Result.push_back(DI->getDef());
     else
       throw "Illegal value in '" + Name + "' list!";
+  return Result;
+}
+
+void InstrInfoEmitter::printDefList(const std::vector<Record*> &Uses,
+                                    unsigned Num, std::ostream &OS) const {
+  OS << "static const unsigned ImplicitList" << Num << "[] = { ";
+  for (unsigned i = 0, e = Uses.size(); i != e; ++i)
+    OS << getQualifiedName(Uses[i]) << ", ";
   OS << "0 };\n";
 }
 
@@ -69,34 +76,50 @@
   Record *PHI = InstrInfo->getValueAsDef("PHIInst");
 
   // Emit empty implicit uses and defs lists
-  OS << "static const unsigned EmptyImpUses[] = { 0 };\n"
-     << "static const unsigned EmptyImpDefs[] = { 0 };\n";
+  OS << "static const unsigned EmptyImpList[] = { 0 };\n";
 
-  // Emit all of the instruction's implicit uses and defs...
+  // Keep track of all of the def lists we have emitted already.
+  std::map<std::vector<Record*>, unsigned> EmittedLists;
+  std::map<ListInit*, unsigned> ListNumbers;
+  unsigned ListNumber = 0;
+ 
+  // Emit all of the instruction's implicit uses and defs.
   for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
          E = Target.inst_end(); II != E; ++II) {
     Record *Inst = II->second.TheDef;
     ListInit *LI = Inst->getValueAsListInit("Uses");
-    if (LI->getSize()) printDefList(LI, Inst->getName()+"ImpUses", OS);
+    if (LI->getSize()) {
+      std::vector<Record*> Uses = GetDefList(LI, Inst->getName());
+      unsigned &IL = EmittedLists[Uses];
+      if (!IL) printDefList(Uses, IL = ++ListNumber, OS);
+      ListNumbers[LI] = IL;
+    }
     LI = Inst->getValueAsListInit("Defs");
-    if (LI->getSize()) printDefList(LI, Inst->getName()+"ImpDefs", OS);
+    if (LI->getSize()) {
+      std::vector<Record*> Uses = GetDefList(LI, Inst->getName());
+      unsigned &IL = EmittedLists[Uses];
+      if (!IL) printDefList(Uses, IL = ++ListNumber, OS);
+      ListNumbers[LI] = IL;
+    }
   }
 
   OS << "\nstatic const TargetInstrDescriptor " << TargetName
      << "Insts[] = {\n";
-  emitRecord(Target.getPHIInstruction(), 0, InstrInfo, OS);
+  emitRecord(Target.getPHIInstruction(), 0, InstrInfo, ListNumbers, OS);
 
   unsigned i = 0;
   for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
          E = Target.inst_end(); II != E; ++II)
     if (II->second.TheDef != PHI)
-      emitRecord(II->second, ++i, InstrInfo, OS);
+      emitRecord(II->second, ++i, InstrInfo, ListNumbers, OS);
   OS << "};\n";
   OS << "} // End llvm namespace \n";
 }
 
 void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
-                                  Record *InstrInfo, std::ostream &OS) {
+                                  Record *InstrInfo,
+                                  std::map<ListInit*, unsigned> &ListNumbers,
+                                  std::ostream &OS) {
   OS << "  { \"";
   if (Inst.Name.empty())
     OS << Inst.TheDef->getName();
@@ -134,15 +157,15 @@
   // Emit the implicit uses and defs lists...
   LI = Inst.TheDef->getValueAsListInit("Uses");
   if (!LI->getSize())
-    OS << "EmptyImpUses, ";
+    OS << "EmptyImpList, ";
   else
-    OS << Inst.TheDef->getName() << "ImpUses, ";
+    OS << "ImplicitList" << ListNumbers[LI] << ", ";
 
   LI = Inst.TheDef->getValueAsListInit("Defs");
   if (!LI->getSize())
-    OS << "EmptyImpDefs ";
+    OS << "EmptyImpList ";
   else
-    OS << Inst.TheDef->getName() << "ImpDefs ";
+    OS << "ImplicitList" << ListNumbers[LI] << " ";
 
   OS << " },  // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
 }


Index: llvm/utils/TableGen/InstrInfoEmitter.h
diff -u llvm/utils/TableGen/InstrInfoEmitter.h:1.8 llvm/utils/TableGen/InstrInfoEmitter.h:1.9
--- llvm/utils/TableGen/InstrInfoEmitter.h:1.8	Thu Apr 21 19:00:35 2005
+++ llvm/utils/TableGen/InstrInfoEmitter.h	Thu Aug 18 16:36:47 2005
@@ -16,6 +16,8 @@
 #define INSTRINFO_EMITTER_H
 
 #include "TableGenBackend.h"
+#include <vector>
+#include <map>
 
 namespace llvm {
 
@@ -35,10 +37,12 @@
   // runEnums - Print out enum values for all of the instructions.
   void runEnums(std::ostream &OS);
 private:
-  void printDefList(ListInit *LI, const std::string &Name,
+  void printDefList(const std::vector<Record*> &Uses, unsigned Num,
                     std::ostream &OS) const;
   void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
-                  Record *InstrInfo, std::ostream &OS);
+                  Record *InstrInfo, 
+                  std::map<ListInit*, unsigned> &ListNumbers,
+                  std::ostream &OS);
   void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
                         std::ostream &OS);
 };






More information about the llvm-commits mailing list