blob: b2232c6573cecf1e57678f34a79d0e4963cf8fd7 [file] [log] [blame]
Akira Hatanakae2489122011-04-15 21:51:11 +00001//===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=//
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +00009//
10// This file declares the Mips specific subclass of MachineFunctionInfo.
11//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000013
14#ifndef MIPS_MACHINE_FUNCTION_INFO_H
15#define MIPS_MACHINE_FUNCTION_INFO_H
16
Akira Hatanaka51c70c62012-06-14 01:15:36 +000017#include "MipsSubtarget.h"
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000018#include "llvm/CodeGen/MachineFunction.h"
Bruno Cardoso Lopesf55a7852007-08-28 05:04:41 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
Akira Hatanaka51c70c62012-06-14 01:15:36 +000020#include "llvm/Target/TargetFrameLowering.h"
21#include "llvm/Target/TargetMachine.h"
Craig Topperb25fda92012-03-17 18:46:09 +000022#include <utility>
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000023
24namespace llvm {
25
26/// MipsFunctionInfo - This class is derived from MachineFunction private
27/// Mips target-specific information for each MachineFunction.
28class MipsFunctionInfo : public MachineFunctionInfo {
David Blaikiea379b1812011-12-20 02:50:00 +000029 virtual void anchor();
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000030
Akira Hatanaka4c406e72011-06-21 00:40:49 +000031 MachineFunction& MF;
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000032 /// SRetReturnReg - Some subtargets require that sret lowering includes
33 /// returning the value of the returned struct in a register. This field
34 /// holds the virtual register into which the sret argument is passed.
35 unsigned SRetReturnReg;
36
Dan Gohmand5ca70642009-06-03 20:30:14 +000037 /// GlobalBaseReg - keeps track of the virtual register initialized for
38 /// use as the global base register. This is used for PIC in some PIC
39 /// relocation models.
40 unsigned GlobalBaseReg;
41
Dan Gohman31ae5862010-04-17 14:41:14 +000042 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
43 int VarArgsFrameIndex;
44
Akira Hatanakad738c0f2011-05-20 01:17:58 +000045 // Range of frame object indices.
46 // InArgFIRange: Range of indices of all frame objects created during call to
47 // LowerFormalArguments.
48 // OutArgFIRange: Range of indices of all frame objects created during call to
Jia Liuf54f60f2012-02-28 07:46:26 +000049 // LowerCall except for the frame object for restoring $gp.
Akira Hatanakad738c0f2011-05-20 01:17:58 +000050 std::pair<int, int> InArgFIRange, OutArgFIRange;
Akira Hatanaka51c70c62012-06-14 01:15:36 +000051 int GlobalRegFI;
Jia Liuf54f60f2012-02-28 07:46:26 +000052 mutable int DynAllocFI; // Frame index of dynamically allocated stack area.
Akira Hatanaka92a26d42011-05-25 17:52:48 +000053 unsigned MaxCallFrameSize;
Bruno Cardoso Lopes98fc4c82011-05-31 02:54:07 +000054
Akira Hatanakaa25fe222012-03-27 19:08:42 +000055 bool EmitNOAT;
56
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000057public:
Che-Liang Chioue084cff2010-09-28 10:06:53 +000058 MipsFunctionInfo(MachineFunction& MF)
Akira Hatanaka4c406e72011-06-21 00:40:49 +000059 : MF(MF), SRetReturnReg(0), GlobalBaseReg(0),
Akira Hatanakad738c0f2011-05-20 01:17:58 +000060 VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)),
Akira Hatanaka51c70c62012-06-14 01:15:36 +000061 OutArgFIRange(std::make_pair(-1, 0)), GlobalRegFI(0), DynAllocFI(0),
Akira Hatanakaa25fe222012-03-27 19:08:42 +000062 MaxCallFrameSize(0), EmitNOAT(false)
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +000063 {}
64
Akira Hatanakad738c0f2011-05-20 01:17:58 +000065 bool isInArgFI(int FI) const {
66 return FI <= InArgFIRange.first && FI >= InArgFIRange.second;
67 }
68 void setLastInArgFI(int FI) { InArgFIRange.second = FI; }
69
Jia Liuf54f60f2012-02-28 07:46:26 +000070 bool isOutArgFI(int FI) const {
Akira Hatanakad738c0f2011-05-20 01:17:58 +000071 return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second;
72 }
73 void extendOutArgFIRange(int FirstFI, int LastFI) {
74 if (!OutArgFIRange.second)
75 // this must be the first time this function was called.
76 OutArgFIRange.first = FirstFI;
77 OutArgFIRange.second = LastFI;
78 }
79
Akira Hatanaka51c70c62012-06-14 01:15:36 +000080 bool isGlobalRegFI(int FI) const {
81 return GlobalRegFI && (FI == GlobalRegFI);
82 }
83
84 int getGlobalRegFI() const {
85 return GlobalRegFI;
86 }
87
88 int initGlobalRegFI() {
89 const TargetMachine &TM = MF.getTarget();
90 unsigned RegSize = TM.getSubtarget<MipsSubtarget>().isABI_N64() ? 8 : 4;
91 int64_t StackAlignment = TM.getFrameLowering()->getStackAlignment();
92 uint64_t Offset = RoundUpToAlignment(MaxCallFrameSize, StackAlignment);
93
94 GlobalRegFI = MF.getFrameInfo()->CreateFixedObject(RegSize, Offset, true);
95 return GlobalRegFI;
96 }
97
Akira Hatanaka4c406e72011-06-21 00:40:49 +000098 // The first call to this function creates a frame object for dynamically
99 // allocated stack area.
100 int getDynAllocFI() const {
101 if (!DynAllocFI)
102 DynAllocFI = MF.getFrameInfo()->CreateFixedObject(4, 0, true);
103
104 return DynAllocFI;
105 }
106 bool isDynAllocFI(int FI) const { return DynAllocFI && DynAllocFI == FI; }
107
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000108 unsigned getSRetReturnReg() const { return SRetReturnReg; }
109 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
Dan Gohmand5ca70642009-06-03 20:30:14 +0000110
Akira Hatanakab049aef2012-02-24 22:34:47 +0000111 bool globalBaseRegSet() const;
112 unsigned getGlobalBaseReg();
Dan Gohman31ae5862010-04-17 14:41:14 +0000113
114 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
115 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Akira Hatanakad738c0f2011-05-20 01:17:58 +0000116
Akira Hatanaka92a26d42011-05-25 17:52:48 +0000117 unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; }
118 void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
Akira Hatanakaa25fe222012-03-27 19:08:42 +0000119
120 bool getEmitNOAT() const { return EmitNOAT; }
121 void setEmitNOAT() { EmitNOAT = true; }
Bruno Cardoso Lopes753e3702007-07-11 22:44:21 +0000122};
123
124} // end of namespace llvm
125
Bruno Cardoso Lopesf55a7852007-08-28 05:04:41 +0000126#endif // MIPS_MACHINE_FUNCTION_INFO_H