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/Target/TargetMachine.h" 18 #include "llvm/Target/TargetRegisterInfo.h" 19 #include <cstdlib> 20 using namespace llvm; 21 ~TargetFrameLowering()22TargetFrameLowering::~TargetFrameLowering() { 23 } 24 25 /// getFrameIndexOffset - Returns the displacement from the frame register to 26 /// the stack frame of the specified index. This is the default implementation 27 /// which is overridden for some targets. getFrameIndexOffset(const MachineFunction & MF,int FI) const28int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF, 29 int FI) const { 30 const MachineFrameInfo *MFI = MF.getFrameInfo(); 31 return MFI->getObjectOffset(FI) + MFI->getStackSize() - 32 getOffsetOfLocalArea() + MFI->getOffsetAdjustment(); 33 } 34 getFrameIndexReference(const MachineFunction & MF,int FI,unsigned & FrameReg) const35int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF, 36 int FI, unsigned &FrameReg) const { 37 const TargetRegisterInfo *RI = MF.getTarget().getRegisterInfo(); 38 39 // By default, assume all frame indices are referenced via whatever 40 // getFrameRegister() says. The target can override this if it's doing 41 // something different. 42 FrameReg = RI->getFrameRegister(MF); 43 return getFrameIndexOffset(MF, FI); 44 } 45