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

Reid Spencer rspencer at reidspencer.com
Wed Jan 10 01:20:41 PST 2007


Chris,

This patch broke most tests. I reverted it so that some of the nightly
testers won't get too damaged. I tried a couple things to work around
the assert but it seems there are bigger issues. Revert was the only
thing I could do in a timely fashion. 

Reid.

On Wed, 2007-01-10 at 01:02 -0600, Chris Lattner wrote:
> 
> Changes in directory llvm/lib/VMCore:
> 
> AsmWriter.cpp updated: 1.241 -> 1.242
> ---
> Log message:
> 
> Last refactoring before PR645: http://llvm.org/PR645 : split up getSlot into getLocalSlot and getGlobalSlot.
> No functionality change.
> 
> 
> ---
> Diffs of the changes:  (+63 -63)
> 
>  AsmWriter.cpp |  126 +++++++++++++++++++++++++++++-----------------------------
>  1 files changed, 63 insertions(+), 63 deletions(-)
> 
> 
> Index: llvm/lib/VMCore/AsmWriter.cpp
> diff -u llvm/lib/VMCore/AsmWriter.cpp:1.241 llvm/lib/VMCore/AsmWriter.cpp:1.242
> --- llvm/lib/VMCore/AsmWriter.cpp:1.241	Wed Jan 10 00:43:26 2007
> +++ llvm/lib/VMCore/AsmWriter.cpp	Wed Jan 10 01:01:46 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,7 @@
>      printType(V.getType()) << '>';
>  
>      if (!V.hasName()) {
> -      int SlotNum = Machine.getSlot(&V);
> +      int SlotNum = Machine.getLocalSlot(&V);
>        if (SlotNum == -1)
>          Out << ":<badref>";
>        else
> @@ -1405,7 +1412,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 +1470,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 +1480,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;
>  }
>  
> 
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list