blob: dad51b9560054d1fe469fc3e47aba4085c32904d [file] [log] [blame]
Misha Brukmanb8bda132004-03-11 23:52:43 +00001//===-- TargetFrameInfo.cpp - Implement machine frame interface -*- C++ -*-===//
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 Korobeynikov82f58742010-11-20 15:59:32 +000014#include "llvm/Codegen/MachineFrameInfo.h"
15#include "llvm/Codegen/MachineFunction.h"
Misha Brukmanb8bda132004-03-11 23:52:43 +000016#include "llvm/Target/TargetFrameInfo.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
Chris Lattnerfb1fcf02006-08-03 18:55:44 +000023TargetFrameInfo::~TargetFrameInfo() {
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
29TargetFrameInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const {
30 // Default is to do nothing.
31}
Anton Korobeynikov82f58742010-11-20 15:59:32 +000032
33/// getFrameIndexOffset - Returns the displacement from the frame register to
34/// the stack frame of the specified index. This is the default implementation
35/// which is overridden for some targets.
36int TargetFrameInfo::getFrameIndexOffset(const MachineFunction &MF,
37 int FI) const {
38 const MachineFrameInfo *MFI = MF.getFrameInfo();
39 return MFI->getObjectOffset(FI) + MFI->getStackSize() -
40 getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
41}
42
43int TargetFrameInfo::getFrameIndexReference(const MachineFunction &MF, int FI,
44 unsigned &FrameReg) const {
45 const TargetRegisterInfo *RI = MF.getTarget().getRegisterInfo();
46
47 // By default, assume all frame indices are referenced via whatever
48 // getFrameRegister() says. The target can override this if it's doing
49 // something different.
50 FrameReg = RI->getFrameRegister(MF);
51 return getFrameIndexOffset(MF, FI);
52}