LLVM API Documentation

TargetFrameLoweringImpl.cpp
Go to the documentation of this file.
00001 //===----- TargetFrameLoweringImpl.cpp - Implement target frame interface --==//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Implements the layout of a stack frame on the target machine.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Target/TargetFrameLowering.h"
00015 #include "llvm/CodeGen/MachineFrameInfo.h"
00016 #include "llvm/CodeGen/MachineFunction.h"
00017 #include "llvm/Target/TargetMachine.h"
00018 #include "llvm/Target/TargetRegisterInfo.h"
00019 #include "llvm/Target/TargetSubtargetInfo.h"
00020 #include <cstdlib>
00021 using namespace llvm;
00022 
00023 TargetFrameLowering::~TargetFrameLowering() {
00024 }
00025 
00026 /// getFrameIndexOffset - Returns the displacement from the frame register to
00027 /// the stack frame of the specified index. This is the default implementation
00028 /// which is overridden for some targets.
00029 int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
00030                                          int FI) const {
00031   const MachineFrameInfo *MFI = MF.getFrameInfo();
00032   return MFI->getObjectOffset(FI) + MFI->getStackSize() -
00033     getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
00034 }
00035 
00036 int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
00037                                              int FI, unsigned &FrameReg) const {
00038   const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
00039 
00040   // By default, assume all frame indices are referenced via whatever
00041   // getFrameRegister() says. The target can override this if it's doing
00042   // something different.
00043   FrameReg = RI->getFrameRegister(MF);
00044   return getFrameIndexOffset(MF, FI);
00045 }