blob: 19fd581c7dd5cb65deceae56378cc1508463b0a6 [file] [log] [blame]
Anton Korobeynikov16c29b52011-01-10 12:39:04 +00001//===----- TargetFrameLowering.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
Anton Korobeynikov0dbe54e2010-11-20 16:14:57 +000014#include "llvm/CodeGen/MachineFrameInfo.h"
15#include "llvm/CodeGen/MachineFunction.h"
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000016#include "llvm/Target/TargetFrameLowering.h"
Anton Korobeynikov82f58742010-11-20 15:59:32 +000017#include "llvm/Target/TargetMachine.h"
18#include "llvm/Target/TargetRegisterInfo.h"
19
Misha Brukmanb8bda132004-03-11 23:52:43 +000020#include <cstdlib>
Misha Brukmanb8bda132004-03-11 23:52:43 +000021using namespace llvm;
22
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000023TargetFrameLowering::~TargetFrameLowering() {
Reid Spencera1aad3b2005-04-25 02:55:55 +000024}
Anton Korobeynikovd9e33852010-11-18 23:25:52 +000025
26/// getInitialFrameState - Returns a list of machine moves that are assumed
27/// on entry to a function.
28void
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000029TargetFrameLowering::getInitialFrameState(std::vector<MachineMove> &Moves)
30 const {
Anton Korobeynikovd9e33852010-11-18 23:25:52 +000031 // Default is to do nothing.
32}
Anton Korobeynikov82f58742010-11-20 15:59:32 +000033
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.
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000037int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
Anton Korobeynikov82f58742010-11-20 15:59:32 +000038 int FI) const {
39 const MachineFrameInfo *MFI = MF.getFrameInfo();
40 return MFI->getObjectOffset(FI) + MFI->getStackSize() -
41 getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
42}
43
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000044int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
45 int FI, unsigned &FrameReg) const {
Anton Korobeynikov82f58742010-11-20 15:59:32 +000046 const TargetRegisterInfo *RI = MF.getTarget().getRegisterInfo();
47
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);
53}