[llvm-commits] CVS: llvm/lib/Bytecode/Writer/SlotCalculator.h Writer.cpp WriterInternals.h

Chris Lattner sabre at nondot.org
Fri Feb 9 23:43:15 PST 2007



Changes in directory llvm/lib/Bytecode/Writer:

SlotCalculator.h updated: 1.49 -> 1.50
Writer.cpp updated: 1.164 -> 1.165
WriterInternals.h updated: 1.31 -> 1.32
---
Log message:

Change the table datastructure to be a vector<smallvector>, instead of
vector<vector> to avoid allocations.  This speeds up bcwriting of 447.dealII
from 0.8276 to 0.7637s (8.4%).

This concludes this round of proding the bcwriter into submission.  Final
speedup from 24.4s to 0.7637s (32x).



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

 SlotCalculator.h  |    6 ++++--
 Writer.cpp        |   17 +++++++++--------
 WriterInternals.h |    7 +------
 3 files changed, 14 insertions(+), 16 deletions(-)


Index: llvm/lib/Bytecode/Writer/SlotCalculator.h
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.49 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.50
--- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.49	Sat Feb 10 01:06:46 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.h	Sat Feb 10 01:42:59 2007
@@ -21,6 +21,7 @@
 #define LLVM_ANALYSIS_SLOTCALCULATOR_H
 
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
 #include <vector>
 
 namespace llvm {
@@ -44,9 +45,10 @@
 
 class SlotCalculator {
   const Module *TheModule;
-
+public:
   typedef std::vector<const Type*> TypeList;
-  typedef std::vector<const Value*> TypePlane;
+  typedef SmallVector<const Value*, 16> TypePlane;
+private:
   std::vector<TypePlane> Table;
   TypeList Types;
   typedef DenseMap<const Value*, unsigned> NodeMapType;


Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.164 llvm/lib/Bytecode/Writer/Writer.cpp:1.165
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.164	Sat Feb 10 01:31:44 2007
+++ llvm/lib/Bytecode/Writer/Writer.cpp	Sat Feb 10 01:42:59 2007
@@ -812,21 +812,22 @@
 // Helper function for outputConstants().
 // Writes out all the constants in the plane Plane starting at entry StartNo.
 //
-void BytecodeWriter::outputConstantsInPlane(const std::vector<const Value*>
-                                            &Plane, unsigned StartNo) {
+void BytecodeWriter::outputConstantsInPlane(const Value *const *Plane,
+                                            unsigned PlaneSize,
+                                            unsigned StartNo) {
   unsigned ValNo = StartNo;
 
   // Scan through and ignore function arguments, global values, and constant
   // strings.
-  for (; ValNo < Plane.size() &&
+  for (; ValNo < PlaneSize &&
          (isa<Argument>(Plane[ValNo]) || isa<GlobalValue>(Plane[ValNo]) ||
           (isa<ConstantArray>(Plane[ValNo]) &&
            cast<ConstantArray>(Plane[ValNo])->isString())); ValNo++)
     /*empty*/;
 
   unsigned NC = ValNo;              // Number of constants
-  for (; NC < Plane.size() && (isa<Constant>(Plane[NC]) || 
-                               isa<InlineAsm>(Plane[NC])); NC++)
+  for (; NC < PlaneSize && (isa<Constant>(Plane[NC]) || 
+                              isa<InlineAsm>(Plane[NC])); NC++)
     /*empty*/;
   NC -= ValNo;                      // Convert from index into count
   if (NC == 0) return;              // Skip empty type planes...
@@ -839,7 +840,7 @@
   output_vbr(NC);
 
   // Put out the Type ID Number.
-  output_typeid(Table.getTypeSlot(Plane.front()->getType()));
+  output_typeid(Table.getTypeSlot(Plane[0]->getType()));
 
   for (unsigned i = ValNo; i < ValNo+NC; ++i) {
     const Value *V = Plane[i];
@@ -864,7 +865,7 @@
   outputConstantStrings();
 
   for (unsigned pno = 0; pno != NumPlanes; pno++) {
-    const std::vector<const Value*> &Plane = Table.getPlane(pno);
+    const SlotCalculator::TypePlane &Plane = Table.getPlane(pno);
     if (!Plane.empty()) {              // Skip empty type planes...
       unsigned ValNo = 0;
       if (hasNullValue(Plane[0]->getType())) {
@@ -873,7 +874,7 @@
       }
 
       // Write out constants in the plane
-      outputConstantsInPlane(Plane, ValNo);
+      outputConstantsInPlane(&Plane[0], Plane.size(), ValNo);
     }
   }
 }


Index: llvm/lib/Bytecode/Writer/WriterInternals.h
diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.31 llvm/lib/Bytecode/Writer/WriterInternals.h:1.32
--- llvm/lib/Bytecode/Writer/WriterInternals.h:1.31	Fri Feb  9 01:54:13 2007
+++ llvm/lib/Bytecode/Writer/WriterInternals.h	Sat Feb 10 01:42:59 2007
@@ -35,11 +35,6 @@
   void outputConstants();
   void outputConstantStrings();
   void outputFunction(const Function *F);
-  void outputCompactionTable();
-  void outputCompactionTypes(unsigned StartNo);
-  void outputCompactionTablePlane(unsigned PlaneNo,
-                                  const std::vector<const Value*> &TypePlane,
-                                  unsigned StartNo);
   void outputInstructions(const Function *F);
   void outputInstruction(const Instruction &I);
   void outputInstructionFormat0(const Instruction *I, unsigned Opcode,
@@ -66,7 +61,7 @@
   void outputTypeSymbolTable(const TypeSymbolTable &TST);
   void outputValueSymbolTable(const ValueSymbolTable &ST);
   void outputTypes(unsigned StartNo);
-  void outputConstantsInPlane(const std::vector<const Value*> &Plane,
+  void outputConstantsInPlane(const Value *const*Plane, unsigned PlaneSize,
                               unsigned StartNo);
   void outputConstant(const Constant *CPV);
   void outputInlineAsm(const InlineAsm *IA);






More information about the llvm-commits mailing list