1 //===----- TargetFrameLowering.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/CodeGen/MachineFrameInfo.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/Target/TargetFrameLowering.h"
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetRegisterInfo.h"
23 TargetFrameLowering::~TargetFrameLowering() {
26 /// getInitialFrameState - Returns a list of machine moves that are assumed
27 /// on entry to a function.
29 TargetFrameLowering::getInitialFrameState(std::vector<MachineMove> &Moves)
31 // Default is to do nothing.
34 /// getFrameIndexOffset - Returns the displacement from the frame register to
35 /// the stack frame of the specified index. This is the default implementation
36 /// which is overridden for some targets.
37 int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
39 const MachineFrameInfo *MFI = MF.getFrameInfo();
40 return MFI->getObjectOffset(FI) + MFI->getStackSize() -
41 getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
44 int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
45 int FI, unsigned &FrameReg) const {
46 const TargetRegisterInfo *RI = MF.getTarget().getRegisterInfo();
48 // By default, assume all frame indices are referenced via whatever
49 // getFrameRegister() says. The target can override this if it's doing
50 // something different.
51 FrameReg = RI->getFrameRegister(MF);
52 return getFrameIndexOffset(MF, FI);