blob: e3f01912b872a51fe11d41071a7f7fd49777741b [file] [log] [blame]
Nick Lewycky028700f2011-12-15 22:58:58 +00001//===----- TargetFrameLoweringImpl.cpp - Implement target frame interface --==//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
Misha Brukmanb8bda132004-03-11 23:52:43 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Brukmanf976c852005-04-21 22:55:34 +00007//
Misha Brukmanb8bda132004-03-11 23:52:43 +00008//===----------------------------------------------------------------------===//
9//
10// Implements the layout of a stack frame on the target machine.
11//
12//===----------------------------------------------------------------------===//
13
Chandler Carruthd04a8d42012-12-03 16:50:05 +000014#include "llvm/Target/TargetFrameLowering.h"
Anton Korobeynikov0dbe54e2010-11-20 16:14:57 +000015#include "llvm/CodeGen/MachineFrameInfo.h"
16#include "llvm/CodeGen/MachineFunction.h"
Anton Korobeynikov82f58742010-11-20 15:59:32 +000017#include "llvm/Target/TargetRegisterInfo.h"
Stephen Hines37ed9c12014-12-01 14:51:49 -080018#include "llvm/Target/TargetSubtargetInfo.h"
Misha Brukmanb8bda132004-03-11 23:52:43 +000019#include <cstdlib>
Misha Brukmanb8bda132004-03-11 23:52:43 +000020using namespace llvm;
21
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000022TargetFrameLowering::~TargetFrameLowering() {
Reid Spencera1aad3b2005-04-25 02:55:55 +000023}
Anton Korobeynikovd9e33852010-11-18 23:25:52 +000024
Anton Korobeynikov82f58742010-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 Korobeynikov16c29b52011-01-10 12:39:04 +000028int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
Stephen Hines37ed9c12014-12-01 14:51:49 -080029 int FI) const {
Anton Korobeynikov82f58742010-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 Korobeynikov16c29b52011-01-10 12:39:04 +000035int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
36 int FI, unsigned &FrameReg) const {
Stephen Hines37ed9c12014-12-01 14:51:49 -080037 const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
Anton Korobeynikov82f58742010-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}
Stephen Hinesebe69fe2015-03-23 12:10:34 -070045
46bool TargetFrameLowering::needsFrameIndexResolution(
47 const MachineFunction &MF) const {
48 return MF.getFrameInfo()->hasStackObjects();
49}