[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp

Chris Lattner sabre at nondot.org
Mon Jan 8 23:56:05 PST 2007



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.237 -> 1.238
---
Log message:

Split CreateSlot into two versions, one for globals and one for function-local
values


---
Diffs of the changes:  (+68 -61)

 AsmWriter.cpp |  129 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 68 insertions(+), 61 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.237 llvm/lib/VMCore/AsmWriter.cpp:1.238
--- llvm/lib/VMCore/AsmWriter.cpp:1.237	Tue Jan  9 01:46:21 2007
+++ llvm/lib/VMCore/AsmWriter.cpp	Tue Jan  9 01:55:49 2007
@@ -102,9 +102,11 @@
   /// This function does the actual initialization.
   inline void initialize();
 
-  /// CreateSlot - If the specified Value* doesn't have a name, assign it a slot
-  /// number.
-  void CreateSlot(const Value *V);
+  /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
+  void CreateModuleSlot(const GlobalValue *V);
+  
+  /// CreateFunctionSlot - Insert the specified Value* into the slot table.
+  void CreateFunctionSlot(const Value *V);
 
   /// Insert a value into the value table.
   void insertValue(const Value *V);
@@ -1424,13 +1426,13 @@
   for (Module::const_global_iterator I = TheModule->global_begin(),
        E = TheModule->global_end(); I != E; ++I)
     if (!I->hasName()) 
-      CreateSlot(I);
+      CreateModuleSlot(I);
 
   // Add all the unnamed functions to the table.
   for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
        I != E; ++I)
     if (!I->hasName())
-      CreateSlot(I);
+      CreateModuleSlot(I);
 
   SC_DEBUG("end processModule!\n");
 }
@@ -1444,7 +1446,7 @@
   for(Function::const_arg_iterator AI = TheFunction->arg_begin(),
       AE = TheFunction->arg_end(); AI != AE; ++AI)
     if (!AI->hasName())
-      CreateSlot(AI);
+      CreateFunctionSlot(AI);
 
   SC_DEBUG("Inserting Instructions:\n");
 
@@ -1452,10 +1454,10 @@
   for (Function::const_iterator BB = TheFunction->begin(),
        E = TheFunction->end(); BB != E; ++BB) {
     if (!BB->hasName())
-      CreateSlot(BB);
+      CreateFunctionSlot(BB);
     for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
       if (I->getType() != Type::VoidTy && !I->hasName())
-        CreateSlot(I);
+        CreateFunctionSlot(I);
   }
 
   FunctionProcessed = true;
@@ -1464,7 +1466,7 @@
 }
 
 /// Clean up after incorporating a function. This is the only way to get out of
-/// the function incorporation state that affects getSlot/CreateSlot. Function
+/// the function incorporation state that affects getSlot/Create*Slot. Function
 /// incorporation state is indicated by TheFunction != 0.
 void SlotMachine::purgeFunction() {
   SC_DEBUG("begin purgeFunction!\n");
@@ -1475,7 +1477,7 @@
 }
 
 /// Get the slot number for a value. This function will assert if you
-/// ask for a Value that hasn't previously been inserted with CreateSlot.
+/// ask for a Value that hasn't previously been inserted with Create*Slot.
 int SlotMachine::getSlot(const Value *V) {
   assert(V && "Can't get slot for null Value");
   assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
@@ -1535,68 +1537,73 @@
 }
 
 
+/// CreateModuleSlot - Insert the specified GlobalValue* into the slot table.
+void SlotMachine::CreateModuleSlot(const GlobalValue *V) {
+  assert(!V->hasName() && "Doesn't need a slot!");
+  const Type *VTy = V->getType();
+  
+  // Look up the type plane for the Value's type from the module map
+  TypedPlanes::const_iterator MI = mMap.find(VTy);
+  
+  // If the module map's type plane is not for the Value's type
+  if (MI != mMap.end()) {
+    // Lookup the value in the module's map
+    ValueMap::const_iterator MVI = MI->second.map.find(V);
+    if (MVI != MI->second.map.end())
+      return;
+  }
+  
+  return insertValue(V);
+}
+
+
 /// CreateSlot - Create a new slot for the specified value if it has no name.
-void SlotMachine::CreateSlot(const Value *V) {
-  const Type* VTy = V->getType();
+void SlotMachine::CreateFunctionSlot(const Value *V) {
+  const Type *VTy = V->getType();
   assert(VTy != Type::VoidTy && !V->hasName() && "Doesn't need a slot!");
-  assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
-    "Can't insert a non-GlobalValue Constant into SlotMachine");
+  assert(!isa<Constant>(V) && "Can't insert a Constants into SlotMachine");
 
   // Look up the type plane for the Value's type from the module map
   TypedPlanes::const_iterator MI = mMap.find(VTy);
 
-  if (TheFunction) {
-    // Get the type plane for the Value's type from the function map
-    TypedPlanes::const_iterator FI = fMap.find(VTy);
-    // If there is a corresponding type plane in the function map
-    if (FI != fMap.end()) {
-      // Lookup the Value in the function map.
-      ValueMap::const_iterator FVI = FI->second.map.find(V);
-      // If the value exists in the function map, we're done.
-      if (FVI != FI->second.map.end())
-        return;
-      
-      // If there is no corresponding type plane in the module map
-      if (MI == mMap.end())
-        return insertValue(V);
-      // Look up the value in the module map
-      ValueMap::const_iterator MVI = MI->second.map.find(V);
-      // If we found it, it was already inserted
-      if (MVI != MI->second.map.end())
-        return;
+  // Get the type plane for the Value's type from the function map
+  TypedPlanes::const_iterator FI = fMap.find(VTy);
+  // If there is a corresponding type plane in the function map
+  if (FI != fMap.end()) {
+    // Lookup the Value in the function map.
+    ValueMap::const_iterator FVI = FI->second.map.find(V);
+    // If the value exists in the function map, we're done.
+    if (FVI != FI->second.map.end())
+      return;
+    
+    // If there is no corresponding type plane in the module map
+    if (MI == mMap.end())
       return insertValue(V);
-
-    // else there is not a corresponding type plane in the function map
-    } else {
-      // If the type plane doesn't exists at the module level
-      if (MI == mMap.end()) {
-        return insertValue(V);
-      // else type plane exists at the module level, examine it
-      } else {
-        // Look up the value in the module's map
-        ValueMap::const_iterator MVI = MI->second.map.find(V);
-        // If we didn't find it there either
-        if (MVI == MI->second.map.end())
-          // Return the slot number as the module's contribution to
-          // the type plane plus the index of the function map insertion.
-          return insertValue(V);
-        else
-          return;
-      }
-    }
-  }
-
-  // N.B. Can only get here if TheFunction == 0
-
-  // If the module map's type plane is not for the Value's type
-  if (MI != mMap.end()) {
-    // Lookup the value in the module's map
+    // Look up the value in the module map
     ValueMap::const_iterator MVI = MI->second.map.find(V);
+    // If we found it, it was already inserted
     if (MVI != MI->second.map.end())
       return;
+    return insertValue(V);
+  }
+  
+  // Otherwise, there is no corresponding type plane in the function map yet.
+    
+  // If the type plane doesn't exists at the module level
+  if (MI == mMap.end()) {
+    return insertValue(V);
+  // else type plane exists at the module level, examine it
+  } else {
+    // Look up the value in the module's map
+    ValueMap::const_iterator MVI = MI->second.map.find(V);
+    // If we didn't find it there either
+    if (MVI == MI->second.map.end())
+      // Return the slot number as the module's contribution to
+      // the type plane plus the index of the function map insertion.
+      return insertValue(V);
+    else
+      return;
   }
-
-  return insertValue(V);
 }
 
 






More information about the llvm-commits mailing list