inline hasNullValue, rename some variables, simplify some code.
authorChris Lattner <sabre@nondot.org>
Sat, 10 Feb 2007 04:29:03 +0000 (04:29 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 10 Feb 2007 04:29:03 +0000 (04:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34118 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bytecode/Writer/SlotCalculator.cpp
lib/Bytecode/Writer/SlotCalculator.h

index 0b148ec1767ccf854748bdad7ce37eff8936d1b4..8de1d67f2924b1e4bc0f52ad7dc0588eaa0c587e 100644 (file)
@@ -314,11 +314,6 @@ void SlotCalculator::purgeFunction() {
   SC_DEBUG("end purgeFunction!\n");
 }
 
-static inline bool hasNullValue(const Type *Ty) {
-  return Ty != Type::LabelTy && Ty != Type::VoidTy && !isa<OpaqueType>(Ty);
-}
-
-
 int SlotCalculator::getSlot(const Value *V) const {
   std::map<const Value*, unsigned>::const_iterator I = NodeMap.find(V);
   if (I != NodeMap.end())
@@ -336,7 +331,8 @@ int SlotCalculator::getTypeSlot(const Type*T) const {
 }
 
 int SlotCalculator::getOrCreateSlot(const Value *V) {
-  if (V->getType() == Type::VoidTy) return -1;
+  const Type *Ty = V->getType();
+  if (Ty == Type::VoidTy) return -1;
 
   int SlotNo = getSlot(V);        // Check to see if it's already in!
   if (SlotNo != -1) return SlotNo;
@@ -367,43 +363,42 @@ int SlotCalculator::getOrCreateSlot(const Value *V) {
       }
     }
 
-  const Type *Typ = V->getType();
-  assert(Typ != Type::VoidTy && "Can't handle voidty");
-
-  unsigned Ty;
-  
-  if (Typ->isDerivedType()) {
-    int ValSlot = getTypeSlot(Typ);
+  unsigned TyPlane;
+  if (Ty->isDerivedType()) {
+    int ValSlot = getTypeSlot(Ty);
     if (ValSlot == -1) {                // Have we already entered this type?
       // Nope, this is the first we have seen the type, process it.
-      ValSlot = insertType(Typ);
+      ValSlot = insertType(Ty);
       assert(ValSlot != -1 && "ProcessType returned -1 for a type?");
     }
-    Ty = (unsigned)ValSlot;
+    TyPlane = (unsigned)ValSlot;
   } else {
-    Ty = Typ->getTypeID();
+    TyPlane = Ty->getTypeID();
   }
   
-  if (Table.size() <= Ty)    // Make sure we have the type plane allocated...
-    Table.resize(Ty+1, TypePlane());
+  if (Table.size() <= TyPlane)    // Make sure we have the type plane allocated.
+    Table.resize(TyPlane+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;
+  // to insert the implicit null value.
+  if (Table[TyPlane].empty()) {
+    // Label's and opaque types can't have a null value.
+    if (Ty != Type::LabelTy && !isa<OpaqueType>(Ty)) {
+      Value *ZeroInitializer = Constant::getNullValue(Ty);
+      
+      // If we are pushing zeroinit, it will be handled below.
+      if (V != ZeroInitializer) {
+        Table[TyPlane].push_back(ZeroInitializer);
+        NodeMap[ZeroInitializer] = 0;
+      }
     }
   }
   
   // Insert node into table and NodeMap...
-  unsigned DestSlot = NodeMap[V] = Table[Ty].size();
-  Table[Ty].push_back(V);
+  unsigned DestSlot = NodeMap[V] = Table[TyPlane].size();
+  Table[TyPlane].push_back(V);
   
-  SC_DEBUG("  Inserting value [" << Ty << "] = " << *V << " slot=" <<
+  SC_DEBUG("  Inserting value [" << TyPlane << "] = " << *V << " slot=" <<
            DestSlot << " [");
   // G = Global, C = Constant, T = Type, F = Function, o = other
   SC_DEBUG((isa<GlobalVariable>(V) ? "G" : (isa<Constant>(V) ? "C" :
index 10e2e0e96f93e8108af5481c1f18d1bf2eb09aeb..8837a6013ebc38e8b38860bc55aacbbb3db5b86f 100644 (file)
@@ -122,7 +122,6 @@ private:
   // slot that it occupies, or -1 if the declaration is to be ignored
   // because of the IgnoreNamedNodes flag.
   //
-  int insertValue(const Value *V);
   int insertType(const Type *T);
 
   // doInsertValue - Small helper function to be called only be insertVal.