blob: f2ee41d00e43b8fcc74a236465603be68e32a18d [file] [log] [blame]
Jia Liuc5707112012-02-17 08:55:11 +00001//===-- MipsFrameLowering.cpp - Mips Frame Information --------------------===//
Anton Korobeynikov33464912010-11-15 00:06:54 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Anton Korobeynikov33464912010-11-15 00:06:54 +00009//
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000010// This file contains the Mips implementation of TargetFrameLowering class.
Anton Korobeynikov33464912010-11-15 00:06:54 +000011//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Anton Korobeynikov33464912010-11-15 00:06:54 +000013
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000014#include "MipsFrameLowering.h"
Craig Topper79aa3412012-03-17 18:46:09 +000015#include "MipsAnalyzeImmediate.h"
Anton Korobeynikov33464912010-11-15 00:06:54 +000016#include "MipsInstrInfo.h"
17#include "MipsMachineFunction.h"
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000018#include "MCTargetDesc/MipsBaseInfo.h"
Anton Korobeynikov33464912010-11-15 00:06:54 +000019#include "llvm/Function.h"
20#include "llvm/CodeGen/MachineFrameInfo.h"
21#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/MachineModuleInfo.h"
24#include "llvm/CodeGen/MachineRegisterInfo.h"
25#include "llvm/Target/TargetData.h"
26#include "llvm/Target/TargetOptions.h"
27#include "llvm/Support/CommandLine.h"
28
29using namespace llvm;
30
31
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000032//===----------------------------------------------------------------------===//
Anton Korobeynikov33464912010-11-15 00:06:54 +000033//
34// Stack Frame Processing methods
35// +----------------------------+
36//
37// The stack is allocated decrementing the stack pointer on
38// the first instruction of a function prologue. Once decremented,
39// all stack references are done thought a positive offset
40// from the stack/frame pointer, so the stack is considering
41// to grow up! Otherwise terrible hacks would have to be made
42// to get this stack ABI compliant :)
43//
44// The stack frame required by the ABI (after call):
45// Offset
46//
47// 0 ----------
48// 4 Args to pass
49// . saved $GP (used in PIC)
50// . Alloca allocations
51// . Local Area
52// . CPU "Callee Saved" Registers
53// . saved FP
54// . saved RA
55// . FPU "Callee Saved" Registers
56// StackSize -----------
57//
58// Offset - offset from sp after stack allocation on function prologue
59//
60// The sp is the stack pointer subtracted/added from the stack size
61// at the Prologue/Epilogue
62//
63// References to the previous stack (to obtain arguments) are done
64// with offsets that exceeds the stack size: (stacksize+(4*(num_arg-1))
65//
66// Examples:
67// - reference to the actual stack frame
68// for any local area var there is smt like : FI >= 0, StackOffset: 4
69// sw REGX, 4(SP)
70//
71// - reference to previous stack frame
72// suppose there's a load to the 5th arguments : FI < 0, StackOffset: 16.
73// The emitted instruction will be something like:
74// lw REGX, 16+StackSize(SP)
75//
76// Since the total stack size is unknown on LowerFormalArguments, all
77// stack references (ObjectOffset) created to reference the function
78// arguments, are negative numbers. This way, on eliminateFrameIndex it's
79// possible to detect those references and the offsets are adjusted to
80// their real location.
81//
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000082//===----------------------------------------------------------------------===//
Anton Korobeynikov33464912010-11-15 00:06:54 +000083
Anton Korobeynikovd0c38172010-11-18 21:19:35 +000084// hasFP - Return true if the specified function should have a dedicated frame
Akira Hatanaka4552c9a2011-04-15 21:51:11 +000085// pointer register. This is true if the function has variable sized allocas or
86// if frame pointer elimination is disabled.
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000087bool MipsFrameLowering::hasFP(const MachineFunction &MF) const {
Anton Korobeynikovd0c38172010-11-18 21:19:35 +000088 const MachineFrameInfo *MFI = MF.getFrameInfo();
Nick Lewycky8a8d4792011-12-02 22:16:29 +000089 return MF.getTarget().Options.DisableFramePointerElim(MF) ||
90 MFI->hasVarSizedObjects() || MFI->isFrameAddressTaken();
Anton Korobeynikovd0c38172010-11-18 21:19:35 +000091}