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

Chris Lattner sabre at nondot.org
Fri Feb 9 20:22:46 PST 2007



Changes in directory llvm/lib/Bytecode/Writer:

SlotCalculator.cpp updated: 1.87 -> 1.88
SlotCalculator.h updated: 1.32 -> 1.33
---
Log message:

merge doInsertValue into insertValue


---
Diffs of the changes:  (+43 -54)

 SlotCalculator.cpp |   96 +++++++++++++++++++++++------------------------------
 SlotCalculator.h   |    1 
 2 files changed, 43 insertions(+), 54 deletions(-)


Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.87 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.88
--- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.87	Fri Feb  9 22:19:31 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp	Fri Feb  9 22:22:30 2007
@@ -375,15 +375,55 @@
   assert(getSlot(V) == -1 && "Value is already in the table!");
 
   // If this node does not contribute to a plane, ignore the node.
-  if (V->getType() == Type::VoidTy) {         // Ignore void type nodes
+  const Type *Typ = V->getType();
+  if (Typ == Type::VoidTy) {         // Ignore void type nodes
     SC_DEBUG("ignored value " << *V << "\n");
     return -1;
   }
 
-  // Okay, everything is happy, actually insert the silly value now...
-  return doInsertValue(V);
+  unsigned Ty;
+  
+  if (Typ->isDerivedType()) {
+    int ValSlot = getTypeSlot(Typ);
+    if (ValSlot == -1) {                // Have we already entered this type?
+      // Nope, this is the first we have seen the type, process it.
+      ValSlot = insertType(Typ);
+      assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
+    }
+    Ty = (unsigned)ValSlot;
+  } else {
+    Ty = Typ->getTypeID();
+  }
+  
+  if (Table.size() <= Ty)    // Make sure we have the type plane allocated...
+    Table.resize(Ty+1, TypePlane());
+  
+  // If this is the first value to get inserted into the type plane, make sure
+  // to insert the implicit null value...
+  if (Table[Ty].empty() && hasNullValue(Typ)) {
+    Value *ZeroInitializer = Constant::getNullValue(Typ);
+    
+    // If we are pushing zeroinit, it will be handled below.
+    if (V != ZeroInitializer) {
+      Table[Ty].push_back(ZeroInitializer);
+      NodeMap[ZeroInitializer] = 0;
+    }
+  }
+  
+  // Insert node into table and NodeMap...
+  unsigned DestSlot = NodeMap[V] = Table[Ty].size();
+  Table[Ty].push_back(V);
+  
+  SC_DEBUG("  Inserting value [" << Ty << "] = " << *V << " slot=" <<
+           DestSlot << " [");
+  // G = Global, C = Constant, T = Type, F = Function, o = other
+  SC_DEBUG((isa<GlobalVariable>(V) ? "G" : (isa<Constant>(V) ? "C" :
+                                            (isa<Function>(V) ? "F" : "o"))));
+  SC_DEBUG("]\n");
+  return (int)DestSlot;
 }
 
+
 int SlotCalculator::getOrCreateTypeSlot(const Type* T) {
   int SlotNo = getTypeSlot(T);        // Check to see if it's already in!
   if (SlotNo != -1) return SlotNo;
@@ -421,56 +461,6 @@
   return ResultSlot;
 }
 
-// doInsertValue - This is a small helper function to be called only
-// be insertValue.
-//
-int SlotCalculator::doInsertValue(const Value *D) {
-  const Type *Typ = D->getType();
-  unsigned Ty;
-
-  // Used for debugging DefSlot=-1 assertion...
-  //if (Typ == Type::TypeTy)
-  //  llvm_cerr << "Inserting type '"<<cast<Type>(D)->getDescription() <<"'!\n";
-
-  if (Typ->isDerivedType()) {
-    int ValSlot = getTypeSlot(Typ);
-    if (ValSlot == -1) {                // Have we already entered this type?
-      // Nope, this is the first we have seen the type, process it.
-      ValSlot = insertType(Typ);
-      assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
-    }
-    Ty = (unsigned)ValSlot;
-  } else {
-    Ty = Typ->getTypeID();
-  }
-
-  if (Table.size() <= Ty)    // Make sure we have the type plane allocated...
-    Table.resize(Ty+1, TypePlane());
-
-  // If this is the first value to get inserted into the type plane, make sure
-  // to insert the implicit null value...
-  if (Table[Ty].empty() && hasNullValue(Typ)) {
-    Value *ZeroInitializer = Constant::getNullValue(Typ);
-
-    // If we are pushing zeroinit, it will be handled below.
-    if (D != ZeroInitializer) {
-      Table[Ty].push_back(ZeroInitializer);
-      NodeMap[ZeroInitializer] = 0;
-    }
-  }
-
-  // Insert node into table and NodeMap...
-  unsigned DestSlot = NodeMap[D] = Table[Ty].size();
-  Table[Ty].push_back(D);
-
-  SC_DEBUG("  Inserting value [" << Ty << "] = " << *D << " slot=" <<
-           DestSlot << " [");
-  // G = Global, C = Constant, T = Type, F = Function, o = other
-  SC_DEBUG((isa<GlobalVariable>(D) ? "G" : (isa<Constant>(D) ? "C" :
-           (isa<Function>(D) ? "F" : "o"))));
-  SC_DEBUG("]\n");
-  return (int)DestSlot;
-}
 
 // doInsertType - This is a small helper function to be called only
 // be insertType.


Index: llvm/lib/Bytecode/Writer/SlotCalculator.h
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.32 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.33
--- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.32	Fri Feb  9 22:19:31 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.h	Fri Feb  9 22:22:30 2007
@@ -126,7 +126,6 @@
   int insertType(const Type *T);
 
   // doInsertValue - Small helper function to be called only be insertVal.
-  int doInsertValue(const Value *V);
   int doInsertType(const Type *T);
 
   // processModule - Process all of the module level function declarations and






More information about the llvm-commits mailing list