blob: 1557d10238e913415a8d7ef6d06c6e293fce25a4 [file] [log] [blame]
Nick Lewyckyc9e935c2011-12-15 22:58:58 +00001//===----- TargetFrameLoweringImpl.cpp - Implement target frame interface --==//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
Misha Brukman505a0832004-03-11 23:52:43 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
Misha Brukman505a0832004-03-11 23:52:43 +00008//===----------------------------------------------------------------------===//
9//
10// Implements the layout of a stack frame on the target machine.
11//
12//===----------------------------------------------------------------------===//
13
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "llvm/Target/TargetFrameLowering.h"
Anton Korobeynikov36590fc2010-11-20 16:14:57 +000015#include "llvm/CodeGen/MachineFrameInfo.h"
16#include "llvm/CodeGen/MachineFunction.h"
Anton Korobeynikov46877782010-11-20 15:59:32 +000017#include "llvm/Target/TargetRegisterInfo.h"
Eric Christopherd9134482014-08-04 21:25:23 +000018#include "llvm/Target/TargetSubtargetInfo.h"
Misha Brukman505a0832004-03-11 23:52:43 +000019#include <cstdlib>
Misha Brukman505a0832004-03-11 23:52:43 +000020using namespace llvm;
21
Anton Korobeynikov2f931282011-01-10 12:39:04 +000022TargetFrameLowering::~TargetFrameLowering() {
Reid Spencerff7b16c2005-04-25 02:55:55 +000023}
Anton Korobeynikov14ee3442010-11-18 23:25:52 +000024
Anton Korobeynikov46877782010-11-20 15:59:32 +000025/// 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.
Anton Korobeynikov2f931282011-01-10 12:39:04 +000028int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
Eric Christopher307c2cb2014-10-14 07:22:08 +000029 int FI) const {
Anton Korobeynikov46877782010-11-20 15:59:32 +000030 const MachineFrameInfo *MFI = MF.getFrameInfo();
31 return MFI->getObjectOffset(FI) + MFI->getStackSize() -
32 getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
33}
34
Anton Korobeynikov2f931282011-01-10 12:39:04 +000035int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
36 int FI, unsigned &FrameReg) const {
Eric Christopherfc6de422014-08-05 02:39:49 +000037 const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
Anton Korobeynikov46877782010-11-20 15:59:32 +000038
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}