blob: e80c2c6412321dcc38291ef6fc0f0d671149f4c0 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Jim Grosbachf24f9d92009-08-11 15:33:49 +00006//
Evan Cheng10043e22007-01-19 07:51:42 +00007//===----------------------------------------------------------------------===//
8//
9// This file declares ARM-specific per-machine-function information.
10//
11//===----------------------------------------------------------------------===//
12
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000013#ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
14#define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H
Evan Cheng10043e22007-01-19 07:51:42 +000015
Chandler Carruthd9903882015-01-14 11:23:27 +000016#include "llvm/ADT/DenseMap.h"
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000017#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000018#include "llvm/CodeGen/MachineFunction.h"
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000019#include "llvm/Support/ErrorHandling.h"
20#include <utility>
Evan Cheng10043e22007-01-19 07:51:42 +000021
22namespace llvm {
23
Bob Wilsonb7a3c422011-01-15 00:09:18 +000024/// ARMFunctionInfo - This class is derived from MachineFunctionInfo and
25/// contains private ARM-specific information for each MachineFunction.
Evan Cheng10043e22007-01-19 07:51:42 +000026class ARMFunctionInfo : public MachineFunctionInfo {
David Blaikiea379b1812011-12-20 02:50:00 +000027 virtual void anchor();
Evan Cheng10043e22007-01-19 07:51:42 +000028
29 /// isThumb - True if this function is compiled under Thumb mode.
Dale Johannesened0ecdb2007-04-23 20:07:25 +000030 /// Used to initialized Align, so must precede it.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000031 bool isThumb = false;
Evan Cheng10043e22007-01-19 07:51:42 +000032
David Goodwin27303cd2009-06-30 18:04:13 +000033 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use
34 /// to determine if function is compiled under Thumb mode, for that use
35 /// 'isThumb'.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000036 bool hasThumb2 = false;
David Goodwin27303cd2009-06-30 18:04:13 +000037
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +000038 /// StByValParamsPadding - For parameter that is split between
39 /// GPRs and memory; while recovering GPRs part, when
Mark Seabornbe266aa2014-02-16 18:59:48 +000040 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0,
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +000041 /// we need to insert gap before parameter start address. It allows to
42 /// "attach" GPR-part to the part that was passed via stack.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000043 unsigned StByValParamsPadding = 0;
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +000044
Evan Cheng10043e22007-01-19 07:51:42 +000045 /// VarArgsRegSaveSize - Size of the register save area for vararg functions.
46 ///
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000047 unsigned ArgRegsSaveSize = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000048
Jonathan Roelofsef84bda2014-08-05 21:32:21 +000049 /// ReturnRegsCount - Number of registers used up in the return.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000050 unsigned ReturnRegsCount = 0;
Jonathan Roelofsef84bda2014-08-05 21:32:21 +000051
Evan Chengaa24f082007-01-20 02:09:25 +000052 /// HasStackFrame - True if this function has a stack frame. Set by
JF Bastienc8f48c12015-07-14 23:06:07 +000053 /// determineCalleeSaves().
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000054 bool HasStackFrame = false;
Evan Cheng10043e22007-01-19 07:51:42 +000055
Evan Cheng3f251fb2010-08-10 19:30:19 +000056 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by
57 /// emitPrologue.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000058 bool RestoreSPFromFP = false;
Evan Cheng3f251fb2010-08-10 19:30:19 +000059
Evan Cheng6f059e32007-03-01 08:26:31 +000060 /// LRSpilledForFarJump - True if the LR register has been for spilled to
61 /// enable far jump.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000062 bool LRSpilledForFarJump = false;
Evan Cheng43e85182007-01-29 22:22:24 +000063
Eli Friedman2596e8b2019-03-19 21:48:08 +000064 /// LRSpilled - True if the LR register has been for spilled for
65 /// any reason, so it's legal to emit an ARM::tBfar (i.e. "bl").
66 bool LRSpilled = false;
67
Evan Chengaa24f082007-01-20 02:09:25 +000068 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
Evan Cheng10043e22007-01-19 07:51:42 +000069 /// spill stack offset.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000070 unsigned FramePtrSpillOffset = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000071
Jim Grosbach0b7fda22010-11-02 17:35:25 +000072 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
73 /// register spills areas. For Mac OS X:
Evan Cheng10043e22007-01-19 07:51:42 +000074 ///
Jim Grosbach0b7fda22010-11-02 17:35:25 +000075 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
76 /// --------------------------------------------
77 /// GPR callee-saved (2) : r8, r10, r11
Evan Cheng10043e22007-01-19 07:51:42 +000078 /// --------------------------------------------
79 /// DPR callee-saved : d8 - d15
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000080 ///
81 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
82 /// Some may be spilled after the stack has been realigned.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000083 unsigned GPRCS1Offset = 0;
84 unsigned GPRCS2Offset = 0;
85 unsigned DPRCSOffset = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000086
Jim Grosbach0b7fda22010-11-02 17:35:25 +000087 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
88 /// areas.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000089 unsigned GPRCS1Size = 0;
90 unsigned GPRCS2Size = 0;
91 unsigned DPRCSAlignGapSize = 0;
92 unsigned DPRCSSize = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000093
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000094 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
95 /// the aligned portion of the stack frame. This is always a contiguous
96 /// sequence of D-registers starting from d8.
97 ///
98 /// We do not keep track of the frame indices used for these registers - they
99 /// behave like any other frame index in the aligned stack frame. These
100 /// registers also aren't included in DPRCSSize above.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000101 unsigned NumAlignedDPRCS2Regs = 0;
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +0000102
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000103 unsigned PICLabelUId = 0;
Evan Cheng454ff532008-11-08 00:51:41 +0000104
Dan Gohman31ae5862010-04-17 14:41:14 +0000105 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000106 int VarArgsFrameIndex = 0;
Dan Gohman31ae5862010-04-17 14:41:14 +0000107
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000108 /// HasITBlocks - True if IT blocks have been inserted.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000109 bool HasITBlocks = false;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000110
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000111 /// CPEClones - Track constant pool entries clones created by Constant Island
112 /// pass.
113 DenseMap<unsigned, unsigned> CPEClones;
114
Oliver Stannardb14c6252014-04-02 16:10:33 +0000115 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
116 /// being passed on the stack
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000117 unsigned ArgumentStackSize = 0;
Oliver Stannardb14c6252014-04-02 16:10:33 +0000118
Chris Bieneman03695ab2014-07-15 17:18:41 +0000119 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
120 /// coalesced weights.
121 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
122
Manman Ren5e9e65e2016-01-12 00:47:18 +0000123 /// True if this function has a subset of CSRs that is handled explicitly via
124 /// copies.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000125 bool IsSplitCSR = false;
Manman Ren5e9e65e2016-01-12 00:47:18 +0000126
James Molloy9abb2fa2016-09-26 07:26:24 +0000127 /// Globals that have had their storage promoted into the constant pool.
128 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
129
130 /// The amount the literal pool has been increasedby due to promoted globals.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000131 int PromotedGlobalsIncrease = 0;
Fangrui Songf78650a2018-07-30 19:41:25 +0000132
Oliver Stannard6771a892019-07-22 08:44:36 +0000133 /// True if r0 will be preserved by a call to this function (e.g. C++
134 /// con/destructors).
135 bool PreservesR0 = false;
136
Evan Cheng10043e22007-01-19 07:51:42 +0000137public:
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000138 ARMFunctionInfo() = default;
Evan Cheng10043e22007-01-19 07:51:42 +0000139
Eric Christopher3d19f132014-06-18 22:48:09 +0000140 explicit ARMFunctionInfo(MachineFunction &MF);
Evan Cheng10043e22007-01-19 07:51:42 +0000141
142 bool isThumbFunction() const { return isThumb; }
David Goodwin22c2fba2009-07-08 23:10:31 +0000143 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
David Goodwin27303cd2009-06-30 18:04:13 +0000144 bool isThumb2Function() const { return isThumb && hasThumb2; }
Evan Cheng10043e22007-01-19 07:51:42 +0000145
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +0000146 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
147 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
148
Tim Northover8cda34f2015-03-11 18:54:22 +0000149 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000150 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
Evan Cheng10043e22007-01-19 07:51:42 +0000151
Jonathan Roelofsef84bda2014-08-05 21:32:21 +0000152 unsigned getReturnRegsCount() const { return ReturnRegsCount; }
153 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
154
Evan Chengaa24f082007-01-20 02:09:25 +0000155 bool hasStackFrame() const { return HasStackFrame; }
156 void setHasStackFrame(bool s) { HasStackFrame = s; }
Evan Cheng43e85182007-01-29 22:22:24 +0000157
Evan Cheng3f251fb2010-08-10 19:30:19 +0000158 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
159 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
160
Eli Friedman2596e8b2019-03-19 21:48:08 +0000161 bool isLRSpilled() const { return LRSpilled; }
162 void setLRIsSpilled(bool s) { LRSpilled = s; }
163
Evan Cheng6f059e32007-03-01 08:26:31 +0000164 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
165 void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
Evan Cheng43e85182007-01-29 22:22:24 +0000166
Evan Cheng10043e22007-01-19 07:51:42 +0000167 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
168 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000169
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +0000170 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
171 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
172
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000173 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
174 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
Evan Cheng10043e22007-01-19 07:51:42 +0000175 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
176
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000177 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
178 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
Evan Cheng10043e22007-01-19 07:51:42 +0000179 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
180
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000181 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
182 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
Tim Northover228c9432014-11-05 00:27:13 +0000183 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
Evan Cheng10043e22007-01-19 07:51:42 +0000184 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
185
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000186 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
187 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
Tim Northover228c9432014-11-05 00:27:13 +0000188 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
Evan Cheng10043e22007-01-19 07:51:42 +0000189 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
190
Oliver Stannardb14c6252014-04-02 16:10:33 +0000191 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
192 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
193
Evan Chengdfce83c2011-01-17 08:03:18 +0000194 void initPICLabelUId(unsigned UId) {
195 PICLabelUId = UId;
Evan Cheng454ff532008-11-08 00:51:41 +0000196 }
197
Evan Chengdfce83c2011-01-17 08:03:18 +0000198 unsigned getNumPICLabels() const {
199 return PICLabelUId;
Evan Cheng454ff532008-11-08 00:51:41 +0000200 }
201
Evan Chengdfce83c2011-01-17 08:03:18 +0000202 unsigned createPICLabelUId() {
203 return PICLabelUId++;
Evan Cheng454ff532008-11-08 00:51:41 +0000204 }
Dan Gohman31ae5862010-04-17 14:41:14 +0000205
206 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
207 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000208
209 bool hasITBlocks() const { return HasITBlocks; }
210 void setHasITBlocks(bool h) { HasITBlocks = h; }
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000211
Manman Ren5e9e65e2016-01-12 00:47:18 +0000212 bool isSplitCSR() const { return IsSplitCSR; }
213 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
214
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000215 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
216 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
Craig Topper2a30d782014-06-18 05:05:13 +0000217 llvm_unreachable("Duplicate entries!");
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000218 }
219
220 unsigned getOriginalCPIdx(unsigned CloneIdx) const {
221 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
222 if (I != CPEClones.end())
223 return I->second;
224 else
225 return -1U;
226 }
Chris Bieneman03695ab2014-07-15 17:18:41 +0000227
228 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
229 MachineBasicBlock* MBB) {
230 auto It = CoalescedWeights.find(MBB);
231 if (It == CoalescedWeights.end()) {
232 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
233 }
234 return It;
235 }
James Molloy9abb2fa2016-09-26 07:26:24 +0000236
237 /// Indicate to the backend that \c GV has had its storage changed to inside
238 /// a constant pool. This means it no longer needs to be emitted as a
239 /// global variable.
240 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) {
241 PromotedGlobals.insert(GV);
242 }
243 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() {
244 return PromotedGlobals;
245 }
246 int getPromotedConstpoolIncrease() const {
247 return PromotedGlobalsIncrease;
248 }
249 void setPromotedConstpoolIncrease(int Sz) {
250 PromotedGlobalsIncrease = Sz;
251 }
Eli Friedmane97aa962019-07-02 21:35:15 +0000252
253 DenseMap<unsigned, unsigned> EHPrologueRemappedRegs;
Oliver Stannard6771a892019-07-22 08:44:36 +0000254
255 void setPreservesR0() { PreservesR0 = true; }
256 bool getPreservesR0() const { return PreservesR0; }
Evan Cheng10043e22007-01-19 07:51:42 +0000257};
Evan Cheng10043e22007-01-19 07:51:42 +0000258
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000259} // end namespace llvm
260
261#endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H