Misha Brukman | b8bda13 | 2004-03-11 23:52:43 +0000 | [diff] [blame] | 1 | //===-- TargetFrameInfo.cpp - Implement machine frame interface -*- C++ -*-===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Misha Brukman | b8bda13 | 2004-03-11 23:52:43 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Misha Brukman | b8bda13 | 2004-03-11 23:52:43 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implements the layout of a stack frame on the target machine. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Anton Korobeynikov | 82f5874 | 2010-11-20 15:59:32 +0000 | [diff] [blame^] | 14 | #include "llvm/Codegen/MachineFrameInfo.h" |
| 15 | #include "llvm/Codegen/MachineFunction.h" |
Misha Brukman | b8bda13 | 2004-03-11 23:52:43 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetFrameInfo.h" |
Anton Korobeynikov | 82f5874 | 2010-11-20 15:59:32 +0000 | [diff] [blame^] | 17 | #include "llvm/Target/TargetMachine.h" |
| 18 | #include "llvm/Target/TargetRegisterInfo.h" |
| 19 | |
Misha Brukman | b8bda13 | 2004-03-11 23:52:43 +0000 | [diff] [blame] | 20 | #include <cstdlib> |
Misha Brukman | b8bda13 | 2004-03-11 23:52:43 +0000 | [diff] [blame] | 21 | using namespace llvm; |
| 22 | |
Chris Lattner | fb1fcf0 | 2006-08-03 18:55:44 +0000 | [diff] [blame] | 23 | TargetFrameInfo::~TargetFrameInfo() { |
Reid Spencer | a1aad3b | 2005-04-25 02:55:55 +0000 | [diff] [blame] | 24 | } |
Anton Korobeynikov | d9e3385 | 2010-11-18 23:25:52 +0000 | [diff] [blame] | 25 | |
| 26 | /// getInitialFrameState - Returns a list of machine moves that are assumed |
| 27 | /// on entry to a function. |
| 28 | void |
| 29 | TargetFrameInfo::getInitialFrameState(std::vector<MachineMove> &Moves) const { |
| 30 | // Default is to do nothing. |
| 31 | } |
Anton Korobeynikov | 82f5874 | 2010-11-20 15:59:32 +0000 | [diff] [blame^] | 32 | |
| 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. |
| 36 | int 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 | |
| 43 | int 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 | } |