[llvm-commits] [llvm] r126956 - in /llvm/trunk: include/llvm/Target/TargetRegisterInfo.h lib/CodeGen/PrologEpilogInserter.cpp

Jim Grosbach grosbach at apple.com
Fri Mar 4 09:42:03 PST 2011


Hi Evan,

The code currently is using a heuristic for where to put the emergency spill slot which works fine most of the time, but the correct answer isn't always the same for all targets, thus a hook to allow a target to specify a preference different from the default. Normally, PEI prefers to locate the emergency spill slot next to the frame pointer if possible and only does otherwise when that won't work (no FP or dynamic stack realignment). This allows a target to say that it wants the slot next to the SP even when it would be possible to put it next to the FP.

There is no target hook for creating the spill slot. Rather, the scavenger has a hook for setting which index should be used for the slot. That slot is created just like any other stack object by the target, and its address is computed by target-independent code (which is the part this patch tweaks) with some special logic for the emergency spill slot.

-Jim


On Mar 4, 2011, at 12:24 AM, Evan Cheng wrote:

> Hi Jim,
> 
> Is this target hook really necessary? Can it be subsumed by hasFP? Isn't there a target hook for creating the emergency slot? Can you explain what the patch is doing?
> 
> Thanks,
> 
> Evan
> 
> On Mar 3, 2011, at 12:01 PM, Jim Grosbach <grosbach at apple.com> wrote:
> 
>> Author: grosbach
>> Date: Thu Mar  3 14:01:52 2011
>> New Revision: 126956
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=126956&view=rev
>> Log:
>> Allow a target to choose whether to prefer the scavenger emergency spill slot
>> be next to the frame pointer or the stack pointer.
>> 
>> 
>> Modified:
>>   llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
>>   llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
>> 
>> Modified: llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegisterInfo.h?rev=126956&r1=126955&r2=126956&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Target/TargetRegisterInfo.h (original)
>> +++ llvm/trunk/include/llvm/Target/TargetRegisterInfo.h Thu Mar  3 14:01:52 2011
>> @@ -631,6 +631,13 @@
>>    return false;
>>  }
>> 
>> +  /// useFPForScavengingIndex - returns true if the target wants to use
>> +  /// frame pointer based accesses to spill to the scavenger emergency spill
>> +  /// slot.
>> +  virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
>> +    return true;
>> +  }
>> +
>>  /// requiresFrameIndexScavenging - returns true if the target requires post
>>  /// PEI scavenging of registers for materializing frame index constants.
>>  virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
>> 
>> Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=126956&r1=126955&r2=126956&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Thu Mar  3 14:01:52 2011
>> @@ -559,7 +559,8 @@
>>  // Make sure the special register scavenging spill slot is closest to the
>>  // frame pointer if a frame pointer is required.
>>  const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
>> -  if (RS && TFI.hasFP(Fn) && !RegInfo->needsStackRealignment(Fn)) {
>> +  if (RS && TFI.hasFP(Fn) && RegInfo->useFPForScavengingIndex(Fn) &&
>> +      !RegInfo->needsStackRealignment(Fn)) {
>>    int SFI = RS->getScavengingFrameIndex();
>>    if (SFI >= 0)
>>      AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign);
>> @@ -641,7 +642,8 @@
>> 
>>  // Make sure the special register scavenging spill slot is closest to the
>>  // stack pointer.
>> -  if (RS && (!TFI.hasFP(Fn) || RegInfo->needsStackRealignment(Fn))) {
>> +  if (RS && (!TFI.hasFP(Fn) || RegInfo->needsStackRealignment(Fn) ||
>> +             !RegInfo->useFPForScavengingIndex(Fn))) {
>>    int SFI = RS->getScavengingFrameIndex();
>>    if (SFI >= 0)
>>      AdjustStackOffset(MFI, SFI, StackGrowsDown, Offset, MaxAlign);
>> @@ -811,7 +813,6 @@
>>    // directly.
>>    for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
>>      MachineInstr *MI = I;
>> -      bool DoIncr = true;
>>      for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
>>        if (MI->getOperand(i).isReg()) {
>>          MachineOperand &MO = MI->getOperand(i);
>> @@ -842,10 +843,8 @@
>> 
>>        }
>>      }
>> -      if (DoIncr) {
>> -        RS->forward(I);
>> -        ++I;
>> -      }
>> +      RS->forward(I);
>> +      ++I;
>>    }
>>  }
>> }
>> 
>> 
>> _______________________________________________
>> 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