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

Chris Lattner sabre at nondot.org
Wed Jan 10 19:54:42 PST 2007



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.243 -> 1.244
---
Log message:

Recommit my previous patch with a bugfix: printInfoComment works on both
local and global values.


---
Diffs of the changes:  (+67 -63)

 AsmWriter.cpp |  130 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 67 insertions(+), 63 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.243 llvm/lib/VMCore/AsmWriter.cpp:1.244
--- llvm/lib/VMCore/AsmWriter.cpp:1.243	Wed Jan 10 03:18:16 2007
+++ llvm/lib/VMCore/AsmWriter.cpp	Wed Jan 10 21:54:27 2007
@@ -75,9 +75,9 @@
 /// @{
 public:
   /// Return the slot number of the specified value in it's type
-  /// plane.  Its an error to ask for something not in the SlotMachine.
-  /// Its an error to ask for a Type*
-  int getSlot(const Value *V);
+  /// plane.  If something is not in the SlotMachine, return -1.
+  int getLocalSlot(const Value *V);
+  int getGlobalSlot(const GlobalValue *V);
 
 /// @}
 /// @name Mutators
@@ -597,13 +597,20 @@
     } else {
       int Slot;
       if (Machine) {
-        Slot = Machine->getSlot(V);
+        if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
+          Slot = Machine->getGlobalSlot(GV);
+        else
+          Slot = Machine->getLocalSlot(V);
       } else {
         Machine = createSlotMachine(V);
-        if (Machine)
-          Slot = Machine->getSlot(V);
-        else
+        if (Machine) {
+          if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
+            Slot = Machine->getGlobalSlot(GV);
+          else
+            Slot = Machine->getLocalSlot(V);
+        } else {
           Slot = -1;
+        }
         delete Machine;
       }
       if (Slot != -1)
@@ -1042,7 +1049,7 @@
     Out << "\n" << getLLVMName(BB->getName(), false) << ':';
   } else if (!BB->use_empty()) {      // Don't print block # of no uses...
     Out << "\n; <label>:";
-    int Slot = Machine.getSlot(BB);
+    int Slot = Machine.getLocalSlot(BB);
     if (Slot != -1)
       Out << Slot;
     else
@@ -1091,7 +1098,11 @@
     printType(V.getType()) << '>';
 
     if (!V.hasName()) {
-      int SlotNum = Machine.getSlot(&V);
+      int SlotNum;
+      if (const GlobalValue *GV = dyn_cast<GlobalValue>(&V))
+        SlotNum = Machine.getGlobalSlot(GV);
+      else
+        SlotNum = Machine.getLocalSlot(&V);
       if (SlotNum == -1)
         Out << ":<badref>";
       else
@@ -1405,7 +1416,7 @@
 {
 }
 
-inline void SlotMachine::initialize(void) {
+inline void SlotMachine::initialize() {
   if (TheModule) {
     processModule();
     TheModule = 0; ///< Prevent re-processing next time we're called.
@@ -1463,7 +1474,7 @@
 }
 
 /// Clean up after incorporating a function. This is the only way to get out of
-/// the function incorporation state that affects getSlot/Create*Slot. Function
+/// the function incorporation state that affects get*Slot/Create*Slot. Function
 /// incorporation state is indicated by TheFunction != 0.
 void SlotMachine::purgeFunction() {
   SC_DEBUG("begin purgeFunction!\n");
@@ -1473,64 +1484,57 @@
   SC_DEBUG("end purgeFunction!\n");
 }
 
-/// Get the slot number for a value. This function will assert if you
-/// 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) &&
-    "Can't insert a non-GlobalValue Constant into SlotMachine");
+/// getGlobalSlot - Get the slot number of a global value.
+int SlotMachine::getGlobalSlot(const GlobalValue *V) {
+  // Check for uninitialized state and do lazy initialization.
+  initialize();
+  
+  // Find the type plane in the module map
+  TypedPlanes::const_iterator MI = mMap.find(V->getType());
+  if (MI == mMap.end()) return -1;
+  
+  // Lookup the value in the module plane's map.
+  ValueMap::const_iterator MVI = MI->second.map.find(V);
+  return MVI != MI->second.map.end() ? MVI->second : -1;
+}
 
-  // Check for uninitialized state and do lazy initialization
-  this->initialize();
 
-  // Get the type of the value
-  const Type* VTy = V->getType();
+/// getLocalSlot - Get the slot number for a value that is local to a function.
+int SlotMachine::getLocalSlot(const Value *V) {
+  assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!");
 
-  // Find the type plane in the module map
-  TypedPlanes::const_iterator MI = mMap.find(VTy);
+  // Check for uninitialized state and do lazy initialization.
+  initialize();
 
-  if (TheFunction) {
-    // Lookup the type in the function map too
-    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 doesn't exist in the function map
-      if (FVI == FI->second.map.end()) {
-        // Look up the value in the module map.
-        if (MI == mMap.end()) return -1;
-        ValueMap::const_iterator MVI = MI->second.map.find(V);
-        // If we didn't find it, it wasn't inserted
-        if (MVI == MI->second.map.end()) return -1;
-        assert(MVI != MI->second.map.end() && "Value not found");
-        // We found it only at the module level
-        return MVI->second;
+  // Get the type of the value
+  const Type *VTy = V->getType();
 
-      // else the value exists in the function map
-      } else {
-        // Return the slot number as the module's contribution to
-        // the type plane plus the index in the function's contribution
-        // to the type plane.
-        if (MI != mMap.end())
-          return MI->second.next_slot + FVI->second;
-        else
-          return FVI->second;
-      }
-    }
+  TypedPlanes::const_iterator FI = fMap.find(VTy);
+  if (FI == fMap.end()) return -1;
+  
+  // Lookup the Value in the function and module maps.
+  ValueMap::const_iterator FVI = FI->second.map.find(V);
+  TypedPlanes::const_iterator MI = mMap.find(VTy);
+  
+  // If the value doesn't exist in the function map
+  if (FVI == FI->second.map.end()) {
+    // Look up the value in the module map.
+    if (MI == mMap.end()) return -1;
+    ValueMap::const_iterator MVI = MI->second.map.find(V);
+    // If we didn't find it, it wasn't inserted
+    if (MVI == MI->second.map.end()) return -1;
+    assert(MVI != MI->second.map.end() && "Value not found");
+    // We found it only at the module level
+    return MVI->second;
   }
-
-  // N.B. Can get here only if either !TheFunction or the function doesn't
-  // have a corresponding type plane for the Value
-
-  // Make sure the type plane exists
-  if (MI == mMap.end()) return -1;
-  // Lookup the value in the module's map
-  ValueMap::const_iterator MVI = MI->second.map.find(V);
-  // Make sure we found it.
-  if (MVI == MI->second.map.end()) return -1;
-  // Return it.
-  return MVI->second;
+  
+  // Return the slot number as the module's contribution to
+  // the type plane plus the index in the function's contribution
+  // to the type plane.
+  if (MI != mMap.end())
+    return MI->second.next_slot + FVI->second;
+  else
+    return FVI->second;
 }
 
 






More information about the llvm-commits mailing list