LLVM  3.7.0
TargetFrameLoweringImpl.cpp
Go to the documentation of this file.
1 //===----- TargetFrameLoweringImpl.cpp - Implement target frame interface --==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implements the layout of a stack frame on the target machine.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/ADT/BitVector.h"
20 #include "llvm/IR/Function.h"
23 #include <cstdlib>
24 using namespace llvm;
25 
27 }
28 
29 /// The default implementation just looks at attribute "no-frame-pointer-elim".
31  auto Attr = MF.getFunction()->getFnAttribute("no-frame-pointer-elim");
32  return Attr.getValueAsString() == "true";
33 }
34 
35 /// getFrameIndexOffset - Returns the displacement from the frame register to
36 /// the stack frame of the specified index. This is the default implementation
37 /// which is overridden for some targets.
39  int FI) const {
40  const MachineFrameInfo *MFI = MF.getFrameInfo();
41  return MFI->getObjectOffset(FI) + MFI->getStackSize() -
43 }
44 
46  int FI, unsigned &FrameReg) const {
48 
49  // By default, assume all frame indices are referenced via whatever
50  // getFrameRegister() says. The target can override this if it's doing
51  // something different.
52  FrameReg = RI->getFrameRegister(MF);
53  return getFrameIndexOffset(MF, FI);
54 }
55 
57  const MachineFunction &MF) const {
58  return MF.getFrameInfo()->hasStackObjects();
59 }
60 
62  BitVector &SavedRegs,
63  RegScavenger *RS) const {
64  // Get the callee saved register list...
65  const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
66  const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF);
67 
68  // Early exit if there are no callee saved registers.
69  if (!CSRegs || CSRegs[0] == 0)
70  return;
71 
72  SavedRegs.resize(TRI.getNumRegs());
73 
74  // In Naked functions we aren't going to save any registers.
76  return;
77 
78  // Functions which call __builtin_unwind_init get all their registers saved.
79  bool CallsUnwindInit = MF.getMMI().callsUnwindInit();
80  const MachineRegisterInfo &MRI = MF.getRegInfo();
81  for (unsigned i = 0; CSRegs[i]; ++i) {
82  unsigned Reg = CSRegs[i];
83  if (CallsUnwindInit || MRI.isPhysRegModified(Reg))
84  SavedRegs.set(Reg);
85  }
86 }
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition: BitVector.h:192
BitVector & set()
Definition: BitVector.h:218
bool isPhysRegModified(unsigned PhysReg) const
Return true if the specified register is modified in this function.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:225
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
Naked function.
Definition: Attributes.h:81
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
bool hasStackObjects() const
Return true if there are any stack objects in this function.
int getOffsetAdjustment() const
Return the correction for frame offsets.
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
getCalleeSavedRegs - Return a null-terminated list of all of the callee saved registers on this targe...
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
virtual int getFrameIndexOffset(const MachineFunction &MF, int FI) const
getFrameIndexOffset - Returns the displacement from the frame register to the stack frame of the spec...
virtual bool noFramePointerElim(const MachineFunction &MF) const
Return true if the target needs to disable frame pointer elimination.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:217
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:140
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
MachineModuleInfo & getMMI() const