[llvm-commits] [llvm] r87026 - in /llvm/trunk: include/llvm/Target/TargetInstrInfo.h lib/Target/X86/X86InstrInfo.cpp lib/Target/X86/X86InstrInfo.h

Evan Cheng evan.cheng at apple.com
Thu Nov 12 16:57:24 PST 2009


Why can't you just rely on memoperands?

Evan

On Nov 12, 2009, at 12:55 PM, David Greene wrote:

> Author: greened
> Date: Thu Nov 12 14:55:29 2009
> New Revision: 87026
>
> URL: http://llvm.org/viewvc/llvm-project?rev=87026&view=rev
> Log:
>
> Add hasLoadFromStackSlot and hasStoreToStackSlot to return whether a
> machine instruction loads or stores from/to a stack slot.  Unlike
> isLoadFromStackSlot and isStoreFromStackSlot, the instruction may be
> something other than a pure load/store (e.g. it may be an arithmetic
> operation with a memory operand).  This helps AsmPrinter determine  
> when
> to print a spill/reload comment.
>
> This is only a hint since we may not be able to figure this out in all
> cases.  As such, it should not be relied upon for correctness.
>
> Implement for X86.  Return false by default for other architectures.
>
> Modified:
>  llvm/trunk/include/llvm/Target/TargetInstrInfo.h
>  llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
>  llvm/trunk/lib/Target/X86/X86InstrInfo.h
>
> Modified: llvm/trunk/include/llvm/Target/TargetInstrInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetInstrInfo.h?rev=87026&r1=87025&r2=87026&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/include/llvm/Target/TargetInstrInfo.h (original)
> +++ llvm/trunk/include/llvm/Target/TargetInstrInfo.h Thu Nov 12  
> 14:55:29 2009
> @@ -170,6 +170,17 @@
>                                      int &FrameIndex) const {
>   return 0;
> }
> +
> +  /// hasLoadFromStackSlot - If the specified machine instruction has
> +  /// a load from a stack slot, return true along with the FrameIndex
> +  /// of the loaded stack slot.  If not, return false.  Unlike
> +  /// isLoadFromStackSlot, this returns true for any instructions  
> that
> +  /// loads from the stack.  This is just a hint, as some cases may  
> be
> +  /// missed.
> +  virtual bool hasLoadFromStackSlot(const MachineInstr *MI,
> +                                    int &FrameIndex) const {
> +    return 0;
> +  }
>
> /// isStoreToStackSlot - If the specified machine instruction is a  
> direct
> /// store to a stack slot, return the virtual or physical register  
> number of
> @@ -181,6 +192,17 @@
>   return 0;
> }
>
> +  /// hasStoreToStackSlot - If the specified machine instruction  
> has a
> +  /// store to a stack slot, return true along with the FrameIndex of
> +  /// the loaded stack slot.  If not, return false.  Unlike
> +  /// isStoreToStackSlot, this returns true for any instructions that
> +  /// loads from the stack.  This is just a hint, as some cases may  
> be
> +  /// missed.
> +  virtual bool hasStoreToStackSlot(const MachineInstr *MI,
> +                                   int &FrameIndex) const {
> +    return 0;
> +  }
> +
> /// reMaterialize - Re-issue the specified 'original' instruction at  
> the
> /// specific location targeting a new destination register.
> virtual void reMaterialize(MachineBasicBlock &MBB,
>
> Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=87026&r1=87025&r2=87026&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
> +++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Thu Nov 12 14:55:29  
> 2009
> @@ -26,11 +26,15 @@
> #include "llvm/CodeGen/MachineInstrBuilder.h"
> #include "llvm/CodeGen/MachineRegisterInfo.h"
> #include "llvm/CodeGen/LiveVariables.h"
> +#include "llvm/CodeGen/PseudoSourceValue.h"
> #include "llvm/Support/CommandLine.h"
> #include "llvm/Support/ErrorHandling.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/Target/TargetOptions.h"
> #include "llvm/MC/MCAsmInfo.h"
> +
> +#include <limits>
> +
> using namespace llvm;
>
> static cl::opt<bool>
> @@ -707,6 +711,21 @@
> }
> }
>
> +/// isFrameOperand - Return true and the FrameIndex if the specified
> +/// operand and follow operands form a reference to the stack frame.
> +bool X86InstrInfo::isFrameOperand(const MachineInstr *MI, unsigned  
> int Op,
> +                                  int &FrameIndex) const {
> +  if (MI->getOperand(Op).isFI() && MI->getOperand(Op+1).isImm() &&
> +      MI->getOperand(Op+2).isReg() && MI->getOperand(Op+3).isImm() &&
> +      MI->getOperand(Op+1).getImm() == 1 &&
> +      MI->getOperand(Op+2).getReg() == 0 &&
> +      MI->getOperand(Op+3).getImm() == 0) {
> +    FrameIndex = MI->getOperand(Op).getIndex();
> +    return true;
> +  }
> +  return false;
> +}
> +
> unsigned X86InstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
>                                          int &FrameIndex) const {
> switch (MI->getOpcode()) {
> @@ -723,19 +742,32 @@
> case X86::MOVDQArm:
> case X86::MMX_MOVD64rm:
> case X86::MMX_MOVQ64rm:
> -    if (MI->getOperand(1).isFI() && MI->getOperand(2).isImm() &&
> -        MI->getOperand(3).isReg() && MI->getOperand(4).isImm() &&
> -        MI->getOperand(2).getImm() == 1 &&
> -        MI->getOperand(3).getReg() == 0 &&
> -        MI->getOperand(4).getImm() == 0) {
> -      FrameIndex = MI->getOperand(1).getIndex();
> +    if (isFrameOperand(MI, 1, FrameIndex)) {
>     return MI->getOperand(0).getReg();
>   }
> +    // Check for post-frame index elimination operations
> +    return hasLoadFromStackSlot(MI, FrameIndex);
>   break;
> }
> return 0;
> }
>
> +bool X86InstrInfo::hasLoadFromStackSlot(const MachineInstr *MI,
> +                                        int &FrameIndex) const {
> +  for (MachineInstr::mmo_iterator o = MI->memoperands_begin(),
> +         oe = MI->memoperands_end();
> +       o != oe;
> +       ++o) {
> +    if ((*o)->isLoad() && (*o)->getValue())
> +      if (const FixedStackPseudoSourceValue *Value =
> +          dyn_cast<const FixedStackPseudoSourceValue>((*o)->getValue 
> ())) {
> +        FrameIndex = Value->getFrameIndex();
> +        return true;
> +      }
> +  }
> +  return false;
> +}
> +
> unsigned X86InstrInfo::isStoreToStackSlot(const MachineInstr *MI,
>                                         int &FrameIndex) const {
> switch (MI->getOpcode()) {
> @@ -753,19 +785,32 @@
> case X86::MMX_MOVD64mr:
> case X86::MMX_MOVQ64mr:
> case X86::MMX_MOVNTQmr:
> -    if (MI->getOperand(0).isFI() && MI->getOperand(1).isImm() &&
> -        MI->getOperand(2).isReg() && MI->getOperand(3).isImm() &&
> -        MI->getOperand(1).getImm() == 1 &&
> -        MI->getOperand(2).getReg() == 0 &&
> -        MI->getOperand(3).getImm() == 0) {
> -      FrameIndex = MI->getOperand(0).getIndex();
> +    if (isFrameOperand(MI, 0, FrameIndex)) {
>     return MI->getOperand(X86AddrNumOperands).getReg();
>   }
> +    // Check for post-frame index elimination operations
> +    return hasStoreToStackSlot(MI, FrameIndex);
>   break;
> }
> return 0;
> }
>
> +bool X86InstrInfo::hasStoreToStackSlot(const MachineInstr *MI,
> +                                       int &FrameIndex) const {
> +  for (MachineInstr::mmo_iterator o = MI->memoperands_begin(),
> +         oe = MI->memoperands_end();
> +       o != oe;
> +       ++o) {
> +    if ((*o)->isStore() && (*o)->getValue())
> +      if (const FixedStackPseudoSourceValue *Value =
> +          dyn_cast<const FixedStackPseudoSourceValue>((*o)->getValue 
> ())) {
> +        FrameIndex = Value->getFrameIndex();
> +        return true;
> +      }
> +  }
> +  return false;
> +}
> +
> /// regIsPICBase - Return true if register is PIC base (i.e.g  
> defined by
> /// X86::MOVPC32r.
> static bool regIsPICBase(unsigned BaseReg, const MachineRegisterInfo  
> &MRI) {
>
> Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.h?rev=87026&r1=87025&r2=87026&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Target/X86/X86InstrInfo.h (original)
> +++ llvm/trunk/lib/Target/X86/X86InstrInfo.h Thu Nov 12 14:55:29 2009
> @@ -449,8 +449,25 @@
>                          unsigned &SrcSubIdx, unsigned &DstSubIdx)  
> const;
>
> unsigned isLoadFromStackSlot(const MachineInstr *MI, int  
> &FrameIndex) const;
> +
> +  /// hasLoadFromStackSlot - If the specified machine instruction has
> +  /// a load from a stack slot, return true along with the FrameIndex
> +  /// of the loaded stack slot.  If not, return false.  Unlike
> +  /// isLoadFromStackSlot, this returns true for any instructions  
> that
> +  /// loads from the stack.  This is a hint only and may not catch  
> all
> +  /// cases.
> +  bool hasLoadFromStackSlot(const MachineInstr *MI, int  
> &FrameIndex) const;
> +
> unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex)  
> const;
>
> +  /// hasStoreToStackSlot - If the specified machine instruction  
> has a
> +  /// store to a stack slot, return true along with the FrameIndex of
> +  /// the loaded stack slot.  If not, return false.  Unlike
> +  /// isStoreToStackSlot, this returns true for any instructions that
> +  /// loads from the stack.  This is a hint only and may not catch  
> all
> +  /// cases.
> +  bool hasStoreToStackSlot(const MachineInstr *MI, int &FrameIndex)  
> const;
> +
> bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
>                                        AliasAnalysis *AA) const;
> void reMaterialize(MachineBasicBlock &MBB,  
> MachineBasicBlock::iterator MI,
> @@ -610,6 +627,11 @@
>                                    unsigned OpNum,
>                                    const  
> SmallVectorImpl<MachineOperand> &MOs,
>                                    unsigned Size, unsigned  
> Alignment) const;
> +
> +  /// isFrameOperand - Return true and the FrameIndex if the  
> specified
> +  /// operand and follow operands form a reference to the stack  
> frame.
> +  bool isFrameOperand(const MachineInstr *MI, unsigned int Op,
> +                      int &FrameIndex) const;
> };
>
> } // End llvm namespace
>
>
> _______________________________________________
> 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