blob: 81611677299540beb6139a31f5dd493567073817 [file] [log] [blame]
Nick Lewyckyc3890d22015-07-29 22:32:47 +00001//===-- ARMMachineFunctionInfo.h - ARM machine function info ----*- C++ -*-===//
Jim Grosbachf24f9d92009-08-11 15:33:49 +00002//
Evan Cheng10043e22007-01-19 07:51:42 +00003// 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 Grosbachf24f9d92009-08-11 15:33:49 +00007//
Evan Cheng10043e22007-01-19 07:51:42 +00008//===----------------------------------------------------------------------===//
9//
10// This file declares ARM-specific per-machine-function information.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
15#define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
Evan Cheng10043e22007-01-19 07:51:42 +000016
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "llvm/ADT/DenseMap.h"
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000018#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000019#include "llvm/CodeGen/MachineFunction.h"
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000020#include "llvm/Support/ErrorHandling.h"
21#include <utility>
Evan Cheng10043e22007-01-19 07:51:42 +000022
23namespace llvm {
24
Bob Wilsonb7a3c422011-01-15 00:09:18 +000025/// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
26/// contains private ARM-specific information for each MachineFunction.
Evan Cheng10043e22007-01-19 07:51:42 +000027class ARMFunctionInfo : public MachineFunctionInfo {
David Blaikiea379b1812011-12-20 02:50:00 +000028 virtual void anchor();
Evan Cheng10043e22007-01-19 07:51:42 +000029
30 /// isThumb - True if this function is compiled under Thumb mode.
Dale Johannesened0ecdb2007-04-23 20:07:25 +000031 /// Used to initialized Align, so must precede it.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000032 bool isThumb = false;
Evan Cheng10043e22007-01-19 07:51:42 +000033
David Goodwin27303cd2009-06-30 18:04:13 +000034 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
35 /// to determine if function is compiled under Thumb mode, for that use
36 /// 'isThumb'.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000037 bool hasThumb2 = false;
David Goodwin27303cd2009-06-30 18:04:13 +000038
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +000039 /// StByValParamsPadding - For parameter that is split between
40 /// GPRs and memory; while recovering GPRs part, when
Mark Seabornbe266aa2014-02-16 18:59:48 +000041 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +000042 /// we need to insert gap before parameter start address. It allows to
43 /// "attach" GPR-part to the part that was passed via stack.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000044 unsigned StByValParamsPadding = 0;
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +000045
Evan Cheng10043e22007-01-19 07:51:42 +000046 /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
47 ///
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000048 unsigned ArgRegsSaveSize = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000049
Jonathan Roelofsef84bda2014-08-05 21:32:21 +000050 /// ReturnRegsCount - Number of registers used up in the return.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000051 unsigned ReturnRegsCount = 0;
Jonathan Roelofsef84bda2014-08-05 21:32:21 +000052
Evan Chengaa24f082007-01-20 02:09:25 +000053 /// HasStackFrame - True if this function has a stack frame. Set by
JF Bastienc8f48c12015-07-14 23:06:07 +000054 /// determineCalleeSaves().
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000055 bool HasStackFrame = false;
Evan Cheng10043e22007-01-19 07:51:42 +000056
Evan Cheng3f251fb2010-08-10 19:30:19 +000057 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
58 /// emitPrologue.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000059 bool RestoreSPFromFP = false;
Evan Cheng3f251fb2010-08-10 19:30:19 +000060
Evan Cheng6f059e32007-03-01 08:26:31 +000061 /// LRSpilledForFarJump - True if the LR register has been for spilled to
62 /// enable far jump.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000063 bool LRSpilledForFarJump = false;
Evan Cheng43e85182007-01-29 22:22:24 +000064
Evan Chengaa24f082007-01-20 02:09:25 +000065 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
Evan Cheng10043e22007-01-19 07:51:42 +000066 /// spill stack offset.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000067 unsigned FramePtrSpillOffset = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000068
Jim Grosbach0b7fda22010-11-02 17:35:25 +000069 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
70 /// register spills areas. For Mac OS X:
Evan Cheng10043e22007-01-19 07:51:42 +000071 ///
Jim Grosbach0b7fda22010-11-02 17:35:25 +000072 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
73 /// --------------------------------------------
74 /// GPR callee-saved (2) : r8, r10, r11
Evan Cheng10043e22007-01-19 07:51:42 +000075 /// --------------------------------------------
76 /// DPR callee-saved : d8 - d15
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000077 ///
78 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
79 /// Some may be spilled after the stack has been realigned.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000080 unsigned GPRCS1Offset = 0;
81 unsigned GPRCS2Offset = 0;
82 unsigned DPRCSOffset = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000083
Jim Grosbach0b7fda22010-11-02 17:35:25 +000084 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
85 /// areas.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000086 unsigned GPRCS1Size = 0;
87 unsigned GPRCS2Size = 0;
88 unsigned DPRCSAlignGapSize = 0;
89 unsigned DPRCSSize = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000090
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000091 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
92 /// the aligned portion of the stack frame. This is always a contiguous
93 /// sequence of D-registers starting from d8.
94 ///
95 /// We do not keep track of the frame indices used for these registers - they
96 /// behave like any other frame index in the aligned stack frame. These
97 /// registers also aren't included in DPRCSSize above.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000098 unsigned NumAlignedDPRCS2Regs = 0;
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000099
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000100 unsigned PICLabelUId = 0;
Evan Cheng454ff532008-11-08 00:51:41 +0000101
Dan Gohman31ae5862010-04-17 14:41:14 +0000102 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000103 int VarArgsFrameIndex = 0;
Dan Gohman31ae5862010-04-17 14:41:14 +0000104
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000105 /// HasITBlocks - True if IT blocks have been inserted.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000106 bool HasITBlocks = false;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000107
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000108 /// CPEClones - Track constant pool entries clones created by Constant Island
109 /// pass.
110 DenseMap<unsigned, unsigned> CPEClones;
111
Oliver Stannardb14c6252014-04-02 16:10:33 +0000112 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
113 /// being passed on the stack
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000114 unsigned ArgumentStackSize = 0;
Oliver Stannardb14c6252014-04-02 16:10:33 +0000115
Chris Bieneman03695ab2014-07-15 17:18:41 +0000116 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
117 /// coalesced weights.
118 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
119
Manman Ren5e9e65e2016-01-12 00:47:18 +0000120 /// True if this function has a subset of CSRs that is handled explicitly via
121 /// copies.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000122 bool IsSplitCSR = false;
Manman Ren5e9e65e2016-01-12 00:47:18 +0000123
James Molloy9abb2fa2016-09-26 07:26:24 +0000124 /// Globals that have had their storage promoted into the constant pool.
125 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
126
127 /// The amount the literal pool has been increasedby due to promoted globals.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000128 int PromotedGlobalsIncrease = 0;
James Molloy9abb2fa2016-09-26 07:26:24 +0000129
Evan Cheng10043e22007-01-19 07:51:42 +0000130public:
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000131 ARMFunctionInfo() = default;
Evan Cheng10043e22007-01-19 07:51:42 +0000132
Eric Christopher3d19f132014-06-18 22:48:09 +0000133 explicit ARMFunctionInfo(MachineFunction &MF);
Evan Cheng10043e22007-01-19 07:51:42 +0000134
135 bool isThumbFunction() const { return isThumb; }
David Goodwin22c2fba2009-07-08 23:10:31 +0000136 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
David Goodwin27303cd2009-06-30 18:04:13 +0000137 bool isThumb2Function() const { return isThumb && hasThumb2; }
Evan Cheng10043e22007-01-19 07:51:42 +0000138
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +0000139 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
140 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
141
Tim Northover8cda34f2015-03-11 18:54:22 +0000142 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000143 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
Evan Cheng10043e22007-01-19 07:51:42 +0000144
Jonathan Roelofsef84bda2014-08-05 21:32:21 +0000145 unsigned getReturnRegsCount() const { return ReturnRegsCount; }
146 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
147
Evan Chengaa24f082007-01-20 02:09:25 +0000148 bool hasStackFrame() const { return HasStackFrame; }
149 void setHasStackFrame(bool s) { HasStackFrame = s; }
Evan Cheng43e85182007-01-29 22:22:24 +0000150
Evan Cheng3f251fb2010-08-10 19:30:19 +0000151 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
152 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
153
Evan Cheng6f059e32007-03-01 08:26:31 +0000154 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
155 void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
Evan Cheng43e85182007-01-29 22:22:24 +0000156
Evan Cheng10043e22007-01-19 07:51:42 +0000157 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
158 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000159
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +0000160 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
161 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
162
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000163 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
164 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
Evan Cheng10043e22007-01-19 07:51:42 +0000165 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
166
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000167 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
168 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
Evan Cheng10043e22007-01-19 07:51:42 +0000169 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
170
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000171 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
172 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
Tim Northover228c9432014-11-05 00:27:13 +0000173 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
Evan Cheng10043e22007-01-19 07:51:42 +0000174 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
175
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000176 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
177 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
Tim Northover228c9432014-11-05 00:27:13 +0000178 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
Evan Cheng10043e22007-01-19 07:51:42 +0000179 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
180
Oliver Stannardb14c6252014-04-02 16:10:33 +0000181 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
182 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
183
Evan Chengdfce83c2011-01-17 08:03:18 +0000184 void initPICLabelUId(unsigned UId) {
185 PICLabelUId = UId;
Evan Cheng454ff532008-11-08 00:51:41 +0000186 }
187
Evan Chengdfce83c2011-01-17 08:03:18 +0000188 unsigned getNumPICLabels() const {
189 return PICLabelUId;
Evan Cheng454ff532008-11-08 00:51:41 +0000190 }
191
Evan Chengdfce83c2011-01-17 08:03:18 +0000192 unsigned createPICLabelUId() {
193 return PICLabelUId++;
Evan Cheng454ff532008-11-08 00:51:41 +0000194 }
Dan Gohman31ae5862010-04-17 14:41:14 +0000195
196 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
197 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000198
199 bool hasITBlocks() const { return HasITBlocks; }
200 void setHasITBlocks(bool h) { HasITBlocks = h; }
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000201
Manman Ren5e9e65e2016-01-12 00:47:18 +0000202 bool isSplitCSR() const { return IsSplitCSR; }
203 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
204
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000205 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
206 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
Craig Topper2a30d782014-06-18 05:05:13 +0000207 llvm_unreachable("Duplicate entries!");
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000208 }
209
210 unsigned getOriginalCPIdx(unsigned CloneIdx) const {
211 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
212 if (I != CPEClones.end())
213 return I->second;
214 else
215 return -1U;
216 }
Chris Bieneman03695ab2014-07-15 17:18:41 +0000217
218 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
219 MachineBasicBlock* MBB) {
220 auto It = CoalescedWeights.find(MBB);
221 if (It == CoalescedWeights.end()) {
222 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
223 }
224 return It;
225 }
James Molloy9abb2fa2016-09-26 07:26:24 +0000226
227 /// Indicate to the backend that \c GV has had its storage changed to inside
228 /// a constant pool. This means it no longer needs to be emitted as a
229 /// global variable.
230 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) {
231 PromotedGlobals.insert(GV);
232 }
233 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() {
234 return PromotedGlobals;
235 }
236 int getPromotedConstpoolIncrease() const {
237 return PromotedGlobalsIncrease;
238 }
239 void setPromotedConstpoolIncrease(int Sz) {
240 PromotedGlobalsIncrease = Sz;
241 }
Evan Cheng10043e22007-01-19 07:51:42 +0000242};
Evan Cheng10043e22007-01-19 07:51:42 +0000243
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000244} // end namespace llvm
245
246#endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H