1 //===----- TargetFrameLoweringImpl.cpp - Implement target frame interface --==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implements the layout of a stack frame on the target machine.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Target/TargetFrameLowering.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/Target/TargetRegisterInfo.h"
19 #include "llvm/Target/TargetSubtargetInfo.h"
23 TargetFrameLowering::~TargetFrameLowering() {
26 /// The default implementation just looks at attribute "no-frame-pointer-elim".
27 bool TargetFrameLowering::noFramePointerElim(const MachineFunction &MF) const {
28 auto Attr = MF.getFunction()->getFnAttribute("no-frame-pointer-elim");
29 return Attr.getValueAsString() == "true";
32 /// getFrameIndexOffset - Returns the displacement from the frame register to
33 /// the stack frame of the specified index. This is the default implementation
34 /// which is overridden for some targets.
35 int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
37 const MachineFrameInfo *MFI = MF.getFrameInfo();
38 return MFI->getObjectOffset(FI) + MFI->getStackSize() -
39 getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
42 int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
43 int FI, unsigned &FrameReg) const {
44 const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
46 // By default, assume all frame indices are referenced via whatever
47 // getFrameRegister() says. The target can override this if it's doing
48 // something different.
49 FrameReg = RI->getFrameRegister(MF);
50 return getFrameIndexOffset(MF, FI);
53 bool TargetFrameLowering::needsFrameIndexResolution(
54 const MachineFunction &MF) const {
55 return MF.getFrameInfo()->hasStackObjects();