blob: 8a3f50aa9565c646f3d2d069e2797ac5b6a81328 [file] [log] [blame]
Jim Laskey48850c12006-11-16 22:43:37 +00001//===-- PPCMachineFunctionInfo.h - Private data used for PowerPC --*- C++ -*-=//
2//
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.
Jim Laskey48850c12006-11-16 22:43:37 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the PowerPC specific subclass of MachineFunctionInfo.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
15#define LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H
Jim Laskey48850c12006-11-16 22:43:37 +000016
Eugene Zelenko8187c192017-01-13 00:58:58 +000017#include "llvm/ADT/SmallVector.h"
Jim Laskey48850c12006-11-16 22:43:37 +000018#include "llvm/CodeGen/MachineFunction.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000019#include "llvm/CodeGen/TargetCallingConv.h"
Jim Laskey48850c12006-11-16 22:43:37 +000020
21namespace llvm {
22
23/// PPCFunctionInfo - This class is derived from MachineFunction private
24/// PowerPC target-specific information for each MachineFunction.
25class PPCFunctionInfo : public MachineFunctionInfo {
David Blaikiea379b1812011-12-20 02:50:00 +000026 virtual void anchor();
27
Jim Laskey48850c12006-11-16 22:43:37 +000028 /// FramePointerSaveIndex - Frame index of where the old frame pointer is
29 /// stored. Also used as an anchor for instructions that need to be altered
30 /// when using frame pointers (dyna_add, dyna_sub.)
Eugene Zelenko8187c192017-01-13 00:58:58 +000031 int FramePointerSaveIndex = 0;
Fangrui Songf78650a2018-07-30 19:41:25 +000032
Chris Lattnerf6a81562007-12-08 06:59:59 +000033 /// ReturnAddrSaveIndex - Frame index of where the return address is stored.
Jim Laskeyb6e200b2007-02-27 11:55:45 +000034 ///
Eugene Zelenko8187c192017-01-13 00:58:58 +000035 int ReturnAddrSaveIndex = 0;
Chris Lattnerf6a81562007-12-08 06:59:59 +000036
Hal Finkela7c54e82013-07-17 00:45:52 +000037 /// Frame index where the old base pointer is stored.
Eugene Zelenko8187c192017-01-13 00:58:58 +000038 int BasePointerSaveIndex = 0;
Hal Finkela7c54e82013-07-17 00:45:52 +000039
Justin Hibbits654346e2015-01-10 01:57:21 +000040 /// Frame index where the old PIC base pointer is stored.
Eugene Zelenko8187c192017-01-13 00:58:58 +000041 int PICBasePointerSaveIndex = 0;
Justin Hibbits654346e2015-01-10 01:57:21 +000042
Dale Johannesen3863f8e2008-10-24 21:24:23 +000043 /// MustSaveLR - Indicates whether LR is defined (or clobbered) in the current
44 /// function. This is only valid after the initial scan of the function by
45 /// PEI.
46 bool MustSaveLR;
Jim Laskey48850c12006-11-16 22:43:37 +000047
Nemanja Ivanovicbcc82c92018-02-23 23:08:34 +000048 /// Do we have to disable shrink-wrapping? This has to be set if we emit any
49 /// instructions that clobber LR in the entry block because discovering this
50 /// in PEI is too late (happens after shrink-wrapping);
51 bool ShrinkWrapDisabled = false;
52
Hal Finkelbb420f12013-03-15 05:06:04 +000053 /// Does this function have any stack spills.
Eugene Zelenko8187c192017-01-13 00:58:58 +000054 bool HasSpills = false;
Hal Finkelbb420f12013-03-15 05:06:04 +000055
Hal Finkelfcc51d42013-03-17 04:43:44 +000056 /// Does this function spill using instructions with only r+r (not r+i)
57 /// forms.
Eugene Zelenko8187c192017-01-13 00:58:58 +000058 bool HasNonRISpills = false;
Hal Finkelfcc51d42013-03-17 04:43:44 +000059
Bill Wendling632ea652008-03-03 22:19:16 +000060 /// SpillsCR - Indicates whether CR is spilled in the current function.
Eugene Zelenko8187c192017-01-13 00:58:58 +000061 bool SpillsCR = false;
Bill Wendling632ea652008-03-03 22:19:16 +000062
Hal Finkelcc1eeda2013-03-23 22:06:03 +000063 /// Indicates whether VRSAVE is spilled in the current function.
Eugene Zelenko8187c192017-01-13 00:58:58 +000064 bool SpillsVRSAVE = false;
Hal Finkelcc1eeda2013-03-23 22:06:03 +000065
Chris Lattnerf6a81562007-12-08 06:59:59 +000066 /// LRStoreRequired - The bool indicates whether there is some explicit use of
67 /// the LR/LR8 stack slot that is not obvious from scanning the code. This
68 /// requires that the code generator produce a store of LR to the stack on
69 /// entry, even though LR may otherwise apparently not be used.
Eugene Zelenko8187c192017-01-13 00:58:58 +000070 bool LRStoreRequired = false;
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +000071
Hal Finkele6698d52015-02-01 15:03:28 +000072 /// This function makes use of the PPC64 ELF TOC base pointer (register r2).
Eugene Zelenko8187c192017-01-13 00:58:58 +000073 bool UsesTOCBasePtr = false;
Hal Finkele6698d52015-02-01 15:03:28 +000074
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +000075 /// MinReservedArea - This is the frame size that is at least reserved in a
76 /// potential caller (parameter+linkage area).
Eugene Zelenko8187c192017-01-13 00:58:58 +000077 unsigned MinReservedArea = 0;
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +000078
79 /// TailCallSPDelta - Stack pointer delta used when tail calling. Maximum
80 /// amount the stack pointer is adjusted to make the frame bigger for tail
81 /// calls. Used for creating an area before the register spill area.
Eugene Zelenko8187c192017-01-13 00:58:58 +000082 int TailCallSPDelta = 0;
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +000083
84 /// HasFastCall - Does this function contain a fast call. Used to determine
85 /// how the caller's stack pointer should be calculated (epilog/dynamicalloc).
Eugene Zelenko8187c192017-01-13 00:58:58 +000086 bool HasFastCall = false;
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +000087
Dan Gohman31ae5862010-04-17 14:41:14 +000088 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
Eugene Zelenko8187c192017-01-13 00:58:58 +000089 int VarArgsFrameIndex = 0;
90
Dan Gohman31ae5862010-04-17 14:41:14 +000091 /// VarArgsStackOffset - StackOffset for start of stack
92 /// arguments.
Eugene Zelenko8187c192017-01-13 00:58:58 +000093
94 int VarArgsStackOffset = 0;
95
Dan Gohman31ae5862010-04-17 14:41:14 +000096 /// VarArgsNumGPR - Index of the first unused integer
97 /// register for parameter passing.
Eugene Zelenko8187c192017-01-13 00:58:58 +000098 unsigned VarArgsNumGPR = 0;
99
Dan Gohman31ae5862010-04-17 14:41:14 +0000100 /// VarArgsNumFPR - Index of the first unused double
101 /// register for parameter passing.
Eugene Zelenko8187c192017-01-13 00:58:58 +0000102 unsigned VarArgsNumFPR = 0;
Dan Gohman31ae5862010-04-17 14:41:14 +0000103
Bill Schmidtc68c6df2013-02-24 17:34:50 +0000104 /// CRSpillFrameIndex - FrameIndex for CR spill slot for 32-bit SVR4.
Eugene Zelenko8187c192017-01-13 00:58:58 +0000105 int CRSpillFrameIndex = 0;
Bill Schmidtc68c6df2013-02-24 17:34:50 +0000106
Hal Finkel67369882013-04-15 02:07:05 +0000107 /// If any of CR[2-4] need to be saved in the prologue and restored in the
108 /// epilogue then they are added to this array. This is used for the
109 /// 64-bit SVR4 ABI.
110 SmallVector<unsigned, 3> MustSaveCRs;
111
Hal Finkel3ee2af72014-07-18 23:29:49 +0000112 /// Hold onto our MachineFunction context.
113 MachineFunction &MF;
114
115 /// Whether this uses the PIC Base register or not.
Eugene Zelenko8187c192017-01-13 00:58:58 +0000116 bool UsesPICBase = false;
Hal Finkel3ee2af72014-07-18 23:29:49 +0000117
Chuang-Yu Cheng98c18942016-04-08 12:04:32 +0000118 /// True if this function has a subset of CSRs that is handled explicitly via
119 /// copies
Eugene Zelenko8187c192017-01-13 00:58:58 +0000120 bool IsSplitCSR = false;
Chuang-Yu Cheng98c18942016-04-08 12:04:32 +0000121
Hiroshi Inouee3a3e3c2017-10-16 04:12:57 +0000122 /// We keep track attributes for each live-in virtual registers
123 /// to use SExt/ZExt flags in later optimization.
124 std::vector<std::pair<unsigned, ISD::ArgFlagsTy>> LiveInAttrs;
125
Jim Laskey48850c12006-11-16 22:43:37 +0000126public:
Eugene Zelenko8187c192017-01-13 00:58:58 +0000127 explicit PPCFunctionInfo(MachineFunction &MF) : MF(MF) {}
Jim Laskey48850c12006-11-16 22:43:37 +0000128
129 int getFramePointerSaveIndex() const { return FramePointerSaveIndex; }
130 void setFramePointerSaveIndex(int Idx) { FramePointerSaveIndex = Idx; }
Fangrui Songf78650a2018-07-30 19:41:25 +0000131
Chris Lattnerf6a81562007-12-08 06:59:59 +0000132 int getReturnAddrSaveIndex() const { return ReturnAddrSaveIndex; }
133 void setReturnAddrSaveIndex(int idx) { ReturnAddrSaveIndex = idx; }
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +0000134
Hal Finkela7c54e82013-07-17 00:45:52 +0000135 int getBasePointerSaveIndex() const { return BasePointerSaveIndex; }
136 void setBasePointerSaveIndex(int Idx) { BasePointerSaveIndex = Idx; }
137
Justin Hibbits654346e2015-01-10 01:57:21 +0000138 int getPICBasePointerSaveIndex() const { return PICBasePointerSaveIndex; }
139 void setPICBasePointerSaveIndex(int Idx) { PICBasePointerSaveIndex = Idx; }
140
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +0000141 unsigned getMinReservedArea() const { return MinReservedArea; }
142 void setMinReservedArea(unsigned size) { MinReservedArea = size; }
143
144 int getTailCallSPDelta() const { return TailCallSPDelta; }
145 void setTailCallSPDelta(int size) { TailCallSPDelta = size; }
146
Dale Johannesen3863f8e2008-10-24 21:24:23 +0000147 /// MustSaveLR - This is set when the prolog/epilog inserter does its initial
148 /// scan of the function. It is true if the LR/LR8 register is ever explicitly
149 /// defined/clobbered in the machine function (e.g. by calls and movpctolr,
150 /// which is used in PIC generation), or if the LR stack slot is explicitly
151 /// referenced by builtin_return_address.
152 void setMustSaveLR(bool U) { MustSaveLR = U; }
153 bool mustSaveLR() const { return MustSaveLR; }
Jim Laskey48850c12006-11-16 22:43:37 +0000154
Nemanja Ivanovicbcc82c92018-02-23 23:08:34 +0000155 /// We certainly don't want to shrink wrap functions if we've emitted a
156 /// MovePCtoLR8 as that has to go into the entry, so the prologue definitely
157 /// has to go into the entry block.
158 void setShrinkWrapDisabled(bool U) { ShrinkWrapDisabled = U; }
159 bool shrinkWrapDisabled() const { return ShrinkWrapDisabled; }
160
Hal Finkelbb420f12013-03-15 05:06:04 +0000161 void setHasSpills() { HasSpills = true; }
162 bool hasSpills() const { return HasSpills; }
163
Hal Finkelfcc51d42013-03-17 04:43:44 +0000164 void setHasNonRISpills() { HasNonRISpills = true; }
165 bool hasNonRISpills() const { return HasNonRISpills; }
166
Bill Wendling632ea652008-03-03 22:19:16 +0000167 void setSpillsCR() { SpillsCR = true; }
168 bool isCRSpilled() const { return SpillsCR; }
169
Hal Finkelcc1eeda2013-03-23 22:06:03 +0000170 void setSpillsVRSAVE() { SpillsVRSAVE = true; }
171 bool isVRSAVESpilled() const { return SpillsVRSAVE; }
172
Chris Lattnerf6a81562007-12-08 06:59:59 +0000173 void setLRStoreRequired() { LRStoreRequired = true; }
174 bool isLRStoreRequired() const { return LRStoreRequired; }
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +0000175
Hal Finkele6698d52015-02-01 15:03:28 +0000176 void setUsesTOCBasePtr() { UsesTOCBasePtr = true; }
177 bool usesTOCBasePtr() const { return UsesTOCBasePtr; }
178
Arnold Schwaighoferbe0de342008-04-30 09:16:33 +0000179 void setHasFastCall() { HasFastCall = true; }
180 bool hasFastCall() const { return HasFastCall;}
Dan Gohman31ae5862010-04-17 14:41:14 +0000181
182 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
183 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
184
185 int getVarArgsStackOffset() const { return VarArgsStackOffset; }
186 void setVarArgsStackOffset(int Offset) { VarArgsStackOffset = Offset; }
187
188 unsigned getVarArgsNumGPR() const { return VarArgsNumGPR; }
189 void setVarArgsNumGPR(unsigned Num) { VarArgsNumGPR = Num; }
190
191 unsigned getVarArgsNumFPR() const { return VarArgsNumFPR; }
192 void setVarArgsNumFPR(unsigned Num) { VarArgsNumFPR = Num; }
Bill Schmidtc68c6df2013-02-24 17:34:50 +0000193
Hiroshi Inouee3a3e3c2017-10-16 04:12:57 +0000194 /// This function associates attributes for each live-in virtual register.
195 void addLiveInAttr(unsigned VReg, ISD::ArgFlagsTy Flags) {
196 LiveInAttrs.push_back(std::make_pair(VReg, Flags));
197 }
198
Hiroshi Inoue0f7f59f2018-06-13 08:54:13 +0000199 /// This function returns true if the specified vreg is
Hiroshi Inouee3a3e3c2017-10-16 04:12:57 +0000200 /// a live-in register and sign-extended.
201 bool isLiveInSExt(unsigned VReg) const;
202
Hiroshi Inoue0f7f59f2018-06-13 08:54:13 +0000203 /// This function returns true if the specified vreg is
Hiroshi Inouee3a3e3c2017-10-16 04:12:57 +0000204 /// a live-in register and zero-extended.
205 bool isLiveInZExt(unsigned VReg) const;
206
Bill Schmidtc68c6df2013-02-24 17:34:50 +0000207 int getCRSpillFrameIndex() const { return CRSpillFrameIndex; }
208 void setCRSpillFrameIndex(int idx) { CRSpillFrameIndex = idx; }
Hal Finkel67369882013-04-15 02:07:05 +0000209
Craig Topperb94011f2013-07-14 04:42:23 +0000210 const SmallVectorImpl<unsigned> &
Hal Finkel67369882013-04-15 02:07:05 +0000211 getMustSaveCRs() const { return MustSaveCRs; }
212 void addMustSaveCR(unsigned Reg) { MustSaveCRs.push_back(Reg); }
Hal Finkel3ee2af72014-07-18 23:29:49 +0000213
214 void setUsesPICBase(bool uses) { UsesPICBase = uses; }
215 bool usesPICBase() const { return UsesPICBase; }
216
Chuang-Yu Cheng98c18942016-04-08 12:04:32 +0000217 bool isSplitCSR() const { return IsSplitCSR; }
218 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
219
Hal Finkel3ee2af72014-07-18 23:29:49 +0000220 MCSymbol *getPICOffsetSymbol() const;
Ulrich Weigand46ff7ec2016-01-13 13:12:23 +0000221
222 MCSymbol *getGlobalEPSymbol() const;
223 MCSymbol *getLocalEPSymbol() const;
224 MCSymbol *getTOCOffsetSymbol() const;
Jim Laskey48850c12006-11-16 22:43:37 +0000225};
226
Eugene Zelenko8187c192017-01-13 00:58:58 +0000227} // end namespace llvm
Jim Laskey48850c12006-11-16 22:43:37 +0000228
Eugene Zelenko8187c192017-01-13 00:58:58 +0000229#endif // LLVM_LIB_TARGET_POWERPC_PPCMACHINEFUNCTIONINFO_H