[llvm-commits] [llvm] r128562 - /llvm/trunk/lib/CodeGen/VirtRegRewriter.cpp

Evan Cheng evan.cheng at apple.com
Wed Mar 30 11:34:43 PDT 2011


On Mar 30, 2011, at 11:14 AM, Jakob Stoklund Olesen wrote:

> Author: stoklund
> Date: Wed Mar 30 13:14:07 2011
> New Revision: 128562
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=128562&view=rev
> Log:
> Fix evil VirtRegRewriter bug.
> 
> The rewriter can keep track of multiple stack slots in the same register if they
> happen to have the same value. When an instruction modifies a stack slot by
> defining a register that is mapped to a stack slot, other stack slots in that
> register are no longer valid.
> 
> This is a very rare problem, and I don't have a simple test case. I get the
> impression that VirtRegRewriter knows it is about to be deleted, inventing a
> last opaque problem.

I've heard VirtRegRewriter is implementing a new register allocator that is completely dependent on it.

Evan

> 
> <rdar://problem/9204040>
> 
> Modified:
>    llvm/trunk/lib/CodeGen/VirtRegRewriter.cpp
> 
> Modified: llvm/trunk/lib/CodeGen/VirtRegRewriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/VirtRegRewriter.cpp?rev=128562&r1=128561&r2=128562&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/VirtRegRewriter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/VirtRegRewriter.cpp Wed Mar 30 13:14:07 2011
> @@ -261,6 +261,10 @@
>   /// now).
>   void ModifyStackSlotOrReMat(int SlotOrReMat);
> 
> +  /// ClobberSharingStackSlots - When a register mapped to a stack slot changes,
> +  /// other stack slots sharing the same register are no longer valid.
> +  void ClobberSharingStackSlots(int StackSlot);
> +
>   /// AddAvailableRegsToLiveIn - Availability information is being kept coming
>   /// into the specified MBB. Add available physical registers as potential
>   /// live-in's. If they are reused in the MBB, they will be added to the
> @@ -831,6 +835,26 @@
>   PhysRegsAvailable.erase(I);
> }
> 
> +void AvailableSpills::ClobberSharingStackSlots(int StackSlot) {
> +  std::map<int, unsigned>::iterator It =
> +    SpillSlotsOrReMatsAvailable.find(StackSlot);
> +  if (It == SpillSlotsOrReMatsAvailable.end()) return;
> +  unsigned Reg = It->second >> 1;
> +
> +  // Erase entries in PhysRegsAvailable for other stack slots.
> +  std::multimap<unsigned, int>::iterator I = PhysRegsAvailable.lower_bound(Reg);
> +  while (I != PhysRegsAvailable.end() && I->first == Reg) {
> +    std::multimap<unsigned, int>::iterator NextI = llvm::next(I);
> +    if (I->second != StackSlot) {
> +      DEBUG(dbgs() << "Clobbered sharing SS#" << I->second << " in "
> +                   << PrintReg(Reg, TRI) << '\n');
> +      SpillSlotsOrReMatsAvailable.erase(I->second);
> +      PhysRegsAvailable.erase(I);
> +    }
> +    I = NextI;
> +  }
> +}
> +
> // ************************** //
> // Reuse Info Implementation  //
> // ************************** //
> @@ -2550,6 +2574,10 @@
>         }
>       }
> 
> +      // If StackSlot is available in a register that also holds other stack
> +      // slots, clobber those stack slots now.
> +      Spills.ClobberSharingStackSlots(StackSlot);
> +
>       assert(PhysReg && "VR not assigned a physical register?");
>       MRI->setPhysRegUsed(PhysReg);
>       unsigned RReg = SubIdx ? TRI->getSubReg(PhysReg, SubIdx) : PhysReg;
> 
> 
> _______________________________________________
> 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