LLVM  8.0.0svn
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 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/BitVector.h"
21 #include "llvm/IR/Attributes.h"
22 #include "llvm/IR/CallingConv.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/MC/MCRegisterInfo.h"
25 #include "llvm/Support/Compiler.h"
29 using namespace llvm;
33 /// The default implementation just looks at attribute "no-frame-pointer-elim".
35  auto Attr = MF.getFunction().getFnAttribute("no-frame-pointer-elim");
36  return Attr.getValueAsString() == "true";
37 }
40  assert(MF.getFunction().hasFnAttribute(Attribute::NoReturn) &&
41  MF.getFunction().hasFnAttribute(Attribute::NoUnwind) &&
42  !MF.getFunction().hasFnAttribute(Attribute::UWTable));
43  return false;
44 }
46 /// Returns the displacement from the frame register to the stack
47 /// frame of the specified index, along with the frame register used
48 /// (in output arg FrameReg). This is the default implementation which
49 /// is overridden for some targets.
51  int FI, unsigned &FrameReg) const {
52  const MachineFrameInfo &MFI = MF.getFrameInfo();
55  // By default, assume all frame indices are referenced via whatever
56  // getFrameRegister() says. The target can override this if it's doing
57  // something different.
58  FrameReg = RI->getFrameRegister(MF);
60  return MFI.getObjectOffset(FI) + MFI.getStackSize() -
62 }
65  const MachineFunction &MF) const {
66  return MF.getFrameInfo().hasStackObjects();
67 }
70  BitVector &SavedRegs,
71  RegScavenger *RS) const {
74  // Resize before the early returns. Some backends expect that
75  // SavedRegs.size() == TRI.getNumRegs() after this call even if there are no
76  // saved registers.
77  SavedRegs.resize(TRI.getNumRegs());
79  // When interprocedural register allocation is enabled caller saved registers
80  // are preferred over callee saved registers.
82  return;
84  // Get the callee saved register list...
85  const MCPhysReg *CSRegs = MF.getRegInfo().getCalleeSavedRegs();
87  // Early exit if there are no callee saved registers.
88  if (!CSRegs || CSRegs[0] == 0)
89  return;
91  // In Naked functions we aren't going to save any registers.
92  if (MF.getFunction().hasFnAttribute(Attribute::Naked))
93  return;
95  // Noreturn+nounwind functions never restore CSR, so no saves are needed.
96  // Purely noreturn functions may still return through throws, so those must
97  // save CSR for caller exception handlers.
98  //
99  // If the function uses longjmp to break out of its current path of
100  // execution we do not need the CSR spills either: setjmp stores all CSRs
101  // it was called with into the jmp_buf, which longjmp then restores.
102  if (MF.getFunction().hasFnAttribute(Attribute::NoReturn) &&
103  MF.getFunction().hasFnAttribute(Attribute::NoUnwind) &&
104  !MF.getFunction().hasFnAttribute(Attribute::UWTable) &&
106  return;
108  // Functions which call __builtin_unwind_init get all their registers saved.
109  bool CallsUnwindInit = MF.callsUnwindInit();
110  const MachineRegisterInfo &MRI = MF.getRegInfo();
111  for (unsigned i = 0; CSRegs[i]; ++i) {
112  unsigned Reg = CSRegs[i];
113  if (CallsUnwindInit || MRI.isPhysRegModified(Reg))
114  SavedRegs.set(Reg);
115  }
116 }
119  const MachineFunction &MF) const {
120  // When HHVM function is called, the stack is skewed as the return address
121  // is removed from the stack before we enter the function.
123  return MF.getTarget().getAllocaPointerSize();
125  return 0;
126 }
129  llvm_unreachable("getInitialCFAOffset() not implemented!");
130 }
133  const {
134  llvm_unreachable("getInitialCFARegister() not implemented!");
135 }
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition: BitVector.h:372
BitVector & set()
Definition: BitVector.h:398
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
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...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
bool isPhysRegModified(unsigned PhysReg, bool SkipNoReturnDef=false) const
Return true if the specified register is modified in this function.
unsigned Reg
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:321
unsigned const TargetRegisterInfo * TRI
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition: Compiler.h:192
static bool isSafeForNoCSROpt(const Function &F)
Check if given function is safe for not having callee saved registers.
unsigned EnableIPRA
This flag enables InterProcedural Register Allocation (IPRA).
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
This file contains the simple types necessary to represent the attributes associated with functions a...
virtual bool noFramePointerElim(const MachineFunction &MF) const
Return true if the target needs to disable frame pointer elimination.
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.
virtual unsigned getStackAlignmentSkew(const MachineFunction &MF) const
Return the skew that has to be applied to stack alignment under certain conditions (e...
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
Definition: CallingConv.h:164
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
unsigned getAllocaPointerSize() const
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:213
bool callsUnwindInit() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
virtual bool enableCalleeSaveSkip(const MachineFunction &MF) const
Returns true if the target can safely skip saving callee-saved registers for noreturn nounwind functi...
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:195
TargetOptions Options
Definition: TargetMachine.h:97
int getOffsetAdjustment() const
Return the correction for frame offsets.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:331
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
virtual int getInitialCFAOffset(const MachineFunction &MF) const
Return initial CFA offset value i.e.
virtual unsigned getInitialCFARegister(const MachineFunction &MF) const
Return initial CFA register value i.e.