blob: cad6e8e38256af3866debce723ab63fabbad818a [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
Evan Chengaa24f082007-01-20 02:09:25 +000064 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer
Evan Cheng10043e22007-01-19 07:51:42 +000065 /// spill stack offset.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000066 unsigned FramePtrSpillOffset = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000067
Jim Grosbach0b7fda22010-11-02 17:35:25 +000068 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved
69 /// register spills areas. For Mac OS X:
Evan Cheng10043e22007-01-19 07:51:42 +000070 ///
Jim Grosbach0b7fda22010-11-02 17:35:25 +000071 /// GPR callee-saved (1) : r4, r5, r6, r7, lr
72 /// --------------------------------------------
73 /// GPR callee-saved (2) : r8, r10, r11
Evan Cheng10043e22007-01-19 07:51:42 +000074 /// --------------------------------------------
75 /// DPR callee-saved : d8 - d15
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000076 ///
77 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3.
78 /// Some may be spilled after the stack has been realigned.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000079 unsigned GPRCS1Offset = 0;
80 unsigned GPRCS2Offset = 0;
81 unsigned DPRCSOffset = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000082
Jim Grosbach0b7fda22010-11-02 17:35:25 +000083 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills
84 /// areas.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000085 unsigned GPRCS1Size = 0;
86 unsigned GPRCS2Size = 0;
87 unsigned DPRCSAlignGapSize = 0;
88 unsigned DPRCSSize = 0;
Evan Cheng10043e22007-01-19 07:51:42 +000089
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000090 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in
91 /// the aligned portion of the stack frame. This is always a contiguous
92 /// sequence of D-registers starting from d8.
93 ///
94 /// We do not keep track of the frame indices used for these registers - they
95 /// behave like any other frame index in the aligned stack frame. These
96 /// registers also aren't included in DPRCSSize above.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000097 unsigned NumAlignedDPRCS2Regs = 0;
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +000098
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +000099 unsigned PICLabelUId = 0;
Evan Cheng454ff532008-11-08 00:51:41 +0000100
Dan Gohman31ae5862010-04-17 14:41:14 +0000101 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000102 int VarArgsFrameIndex = 0;
Dan Gohman31ae5862010-04-17 14:41:14 +0000103
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000104 /// HasITBlocks - True if IT blocks have been inserted.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000105 bool HasITBlocks = false;
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000106
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000107 /// CPEClones - Track constant pool entries clones created by Constant Island
108 /// pass.
109 DenseMap<unsigned, unsigned> CPEClones;
110
Oliver Stannardb14c6252014-04-02 16:10:33 +0000111 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments
112 /// being passed on the stack
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000113 unsigned ArgumentStackSize = 0;
Oliver Stannardb14c6252014-04-02 16:10:33 +0000114
Chris Bieneman03695ab2014-07-15 17:18:41 +0000115 /// CoalescedWeights - mapping of basic blocks to the rolling counter of
116 /// coalesced weights.
117 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights;
118
Manman Ren5e9e65e2016-01-12 00:47:18 +0000119 /// True if this function has a subset of CSRs that is handled explicitly via
120 /// copies.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000121 bool IsSplitCSR = false;
Manman Ren5e9e65e2016-01-12 00:47:18 +0000122
James Molloy9abb2fa2016-09-26 07:26:24 +0000123 /// Globals that have had their storage promoted into the constant pool.
124 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;
125
126 /// The amount the literal pool has been increasedby due to promoted globals.
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000127 int PromotedGlobalsIncrease = 0;
Fangrui Songf78650a2018-07-30 19:41:25 +0000128
Evan Cheng10043e22007-01-19 07:51:42 +0000129public:
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000130 ARMFunctionInfo() = default;
Evan Cheng10043e22007-01-19 07:51:42 +0000131
Eric Christopher3d19f132014-06-18 22:48:09 +0000132 explicit ARMFunctionInfo(MachineFunction &MF);
Evan Cheng10043e22007-01-19 07:51:42 +0000133
134 bool isThumbFunction() const { return isThumb; }
David Goodwin22c2fba2009-07-08 23:10:31 +0000135 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; }
David Goodwin27303cd2009-06-30 18:04:13 +0000136 bool isThumb2Function() const { return isThumb && hasThumb2; }
Evan Cheng10043e22007-01-19 07:51:42 +0000137
Stepan Dyatkovskiyd0e34a22013-05-20 08:01:34 +0000138 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; }
139 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; }
140
Tim Northover8cda34f2015-03-11 18:54:22 +0000141 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; }
Stepan Dyatkovskiyf5aa83d2013-04-30 07:19:58 +0000142 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; }
Evan Cheng10043e22007-01-19 07:51:42 +0000143
Jonathan Roelofsef84bda2014-08-05 21:32:21 +0000144 unsigned getReturnRegsCount() const { return ReturnRegsCount; }
145 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; }
146
Evan Chengaa24f082007-01-20 02:09:25 +0000147 bool hasStackFrame() const { return HasStackFrame; }
148 void setHasStackFrame(bool s) { HasStackFrame = s; }
Evan Cheng43e85182007-01-29 22:22:24 +0000149
Evan Cheng3f251fb2010-08-10 19:30:19 +0000150 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; }
151 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; }
152
Evan Cheng6f059e32007-03-01 08:26:31 +0000153 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; }
154 void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; }
Evan Cheng43e85182007-01-29 22:22:24 +0000155
Evan Cheng10043e22007-01-19 07:51:42 +0000156 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; }
157 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; }
Jim Grosbachf24f9d92009-08-11 15:33:49 +0000158
Jakob Stoklund Olesen09655852011-12-23 00:36:18 +0000159 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; }
160 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; }
161
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000162 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; }
163 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; }
Evan Cheng10043e22007-01-19 07:51:42 +0000164 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; }
165
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000166 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; }
167 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; }
Evan Cheng10043e22007-01-19 07:51:42 +0000168 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; }
169
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000170 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; }
171 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; }
Tim Northover228c9432014-11-05 00:27:13 +0000172 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; }
Evan Cheng10043e22007-01-19 07:51:42 +0000173 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; }
174
Jim Grosbach0b7fda22010-11-02 17:35:25 +0000175 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; }
176 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; }
Tim Northover228c9432014-11-05 00:27:13 +0000177 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; }
Evan Cheng10043e22007-01-19 07:51:42 +0000178 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; }
179
Oliver Stannardb14c6252014-04-02 16:10:33 +0000180 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
181 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
182
Evan Chengdfce83c2011-01-17 08:03:18 +0000183 void initPICLabelUId(unsigned UId) {
184 PICLabelUId = UId;
Evan Cheng454ff532008-11-08 00:51:41 +0000185 }
186
Evan Chengdfce83c2011-01-17 08:03:18 +0000187 unsigned getNumPICLabels() const {
188 return PICLabelUId;
Evan Cheng454ff532008-11-08 00:51:41 +0000189 }
190
Evan Chengdfce83c2011-01-17 08:03:18 +0000191 unsigned createPICLabelUId() {
192 return PICLabelUId++;
Evan Cheng454ff532008-11-08 00:51:41 +0000193 }
Dan Gohman31ae5862010-04-17 14:41:14 +0000194
195 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
196 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000197
198 bool hasITBlocks() const { return HasITBlocks; }
199 void setHasITBlocks(bool h) { HasITBlocks = h; }
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000200
Manman Ren5e9e65e2016-01-12 00:47:18 +0000201 bool isSplitCSR() const { return IsSplitCSR; }
202 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
203
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000204 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) {
205 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second)
Craig Topper2a30d782014-06-18 05:05:13 +0000206 llvm_unreachable("Duplicate entries!");
Anton Korobeynikov221f4fa2011-01-30 22:07:39 +0000207 }
208
209 unsigned getOriginalCPIdx(unsigned CloneIdx) const {
210 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx);
211 if (I != CPEClones.end())
212 return I->second;
213 else
214 return -1U;
215 }
Chris Bieneman03695ab2014-07-15 17:18:41 +0000216
217 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight(
218 MachineBasicBlock* MBB) {
219 auto It = CoalescedWeights.find(MBB);
220 if (It == CoalescedWeights.end()) {
221 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first;
222 }
223 return It;
224 }
James Molloy9abb2fa2016-09-26 07:26:24 +0000225
226 /// Indicate to the backend that \c GV has had its storage changed to inside
227 /// a constant pool. This means it no longer needs to be emitted as a
228 /// global variable.
229 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) {
230 PromotedGlobals.insert(GV);
231 }
232 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() {
233 return PromotedGlobals;
234 }
235 int getPromotedConstpoolIncrease() const {
236 return PromotedGlobalsIncrease;
237 }
238 void setPromotedConstpoolIncrease(int Sz) {
239 PromotedGlobalsIncrease = Sz;
240 }
Evan Cheng10043e22007-01-19 07:51:42 +0000241};
Evan Cheng10043e22007-01-19 07:51:42 +0000242
Eugene Zelenkoe6cf4372017-01-26 23:40:06 +0000243} // end namespace llvm
244
245#endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H