Stop resetting NoFramePointerElim in TargetMachine::resetTargetOptions.
[oota-llvm.git] / lib / CodeGen / TargetFrameLoweringImpl.cpp
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/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"
20 #include <cstdlib>
21 using namespace llvm;
22
23 TargetFrameLowering::~TargetFrameLowering() {
24 }
25
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";
30 }
31
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,
36                                              int FI) const {
37   const MachineFrameInfo *MFI = MF.getFrameInfo();
38   return MFI->getObjectOffset(FI) + MFI->getStackSize() -
39     getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
40 }
41
42 int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
43                                              int FI, unsigned &FrameReg) const {
44   const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
45
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);
51 }
52
53 bool TargetFrameLowering::needsFrameIndexResolution(
54     const MachineFunction &MF) const {
55   return MF.getFrameInfo()->hasStackObjects();
56 }