1 //===-- ARMMachineFunctionInfo.h - ARM machine function info ----*- C++ -*-===// 2 // 3 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file declares ARM-specific per-machine-function information. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H 14 #define LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H 15 16 #include "llvm/ADT/DenseMap.h" 17 #include "llvm/ADT/SmallPtrSet.h" 18 #include "llvm/CodeGen/MachineFunction.h" 19 #include "llvm/Support/ErrorHandling.h" 20 #include <utility> 21 22 namespace llvm { 23 24 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and 25 /// contains private ARM-specific information for each MachineFunction. 26 class ARMFunctionInfo : public MachineFunctionInfo { 27 virtual void anchor(); 28 29 /// isThumb - True if this function is compiled under Thumb mode. 30 /// Used to initialized Align, so must precede it. 31 bool isThumb = false; 32 33 /// 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'. 36 bool hasThumb2 = false; 37 38 /// StByValParamsPadding - For parameter that is split between 39 /// GPRs and memory; while recovering GPRs part, when 40 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0, 41 /// we need to insert gap before parameter start address. It allows to 42 /// "attach" GPR-part to the part that was passed via stack. 43 unsigned StByValParamsPadding = 0; 44 45 /// VarArgsRegSaveSize - Size of the register save area for vararg functions. 46 /// 47 unsigned ArgRegsSaveSize = 0; 48 49 /// ReturnRegsCount - Number of registers used up in the return. 50 unsigned ReturnRegsCount = 0; 51 52 /// HasStackFrame - True if this function has a stack frame. Set by 53 /// determineCalleeSaves(). 54 bool HasStackFrame = false; 55 56 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by 57 /// emitPrologue. 58 bool RestoreSPFromFP = false; 59 60 /// LRSpilledForFarJump - True if the LR register has been for spilled to 61 /// enable far jump. 62 bool LRSpilledForFarJump = false; 63 64 /// 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 68 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer 69 /// spill stack offset. 70 unsigned FramePtrSpillOffset = 0; 71 72 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved 73 /// register spills areas. For Mac OS X: 74 /// 75 /// GPR callee-saved (1) : r4, r5, r6, r7, lr 76 /// -------------------------------------------- 77 /// GPR callee-saved (2) : r8, r10, r11 78 /// -------------------------------------------- 79 /// DPR callee-saved : d8 - d15 80 /// 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. 83 unsigned GPRCS1Offset = 0; 84 unsigned GPRCS2Offset = 0; 85 unsigned DPRCSOffset = 0; 86 87 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills 88 /// areas. 89 unsigned GPRCS1Size = 0; 90 unsigned GPRCS2Size = 0; 91 unsigned DPRCSAlignGapSize = 0; 92 unsigned DPRCSSize = 0; 93 94 /// 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. 101 unsigned NumAlignedDPRCS2Regs = 0; 102 103 unsigned PICLabelUId = 0; 104 105 /// VarArgsFrameIndex - FrameIndex for start of varargs area. 106 int VarArgsFrameIndex = 0; 107 108 /// HasITBlocks - True if IT blocks have been inserted. 109 bool HasITBlocks = false; 110 111 /// CPEClones - Track constant pool entries clones created by Constant Island 112 /// pass. 113 DenseMap<unsigned, unsigned> CPEClones; 114 115 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments 116 /// being passed on the stack 117 unsigned ArgumentStackSize = 0; 118 119 /// CoalescedWeights - mapping of basic blocks to the rolling counter of 120 /// coalesced weights. 121 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights; 122 123 /// True if this function has a subset of CSRs that is handled explicitly via 124 /// copies. 125 bool IsSplitCSR = false; 126 127 /// 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. 131 int PromotedGlobalsIncrease = 0; 132 133 public: 134 ARMFunctionInfo() = default; 135 136 explicit ARMFunctionInfo(MachineFunction &MF); 137 138 bool isThumbFunction() const { return isThumb; } 139 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; } 140 bool isThumb2Function() const { return isThumb && hasThumb2; } 141 142 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; } 143 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; } 144 145 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; } 146 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; } 147 148 unsigned getReturnRegsCount() const { return ReturnRegsCount; } 149 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; } 150 151 bool hasStackFrame() const { return HasStackFrame; } 152 void setHasStackFrame(bool s) { HasStackFrame = s; } 153 154 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; } 155 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; } 156 157 bool isLRSpilled() const { return LRSpilled; } 158 void setLRIsSpilled(bool s) { LRSpilled = s; } 159 160 bool isLRSpilledForFarJump() const { return LRSpilledForFarJump; } 161 void setLRIsSpilledForFarJump(bool s) { LRSpilledForFarJump = s; } 162 163 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; } 164 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; } 165 166 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; } 167 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; } 168 169 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; } 170 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; } 171 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; } 172 173 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; } 174 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; } 175 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; } 176 177 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; } 178 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; } 179 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; } 180 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; } 181 182 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; } 183 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; } 184 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; } 185 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; } 186 187 unsigned getArgumentStackSize() const { return ArgumentStackSize; } 188 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; } 189 190 void initPICLabelUId(unsigned UId) { 191 PICLabelUId = UId; 192 } 193 194 unsigned getNumPICLabels() const { 195 return PICLabelUId; 196 } 197 198 unsigned createPICLabelUId() { 199 return PICLabelUId++; 200 } 201 202 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } 203 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } 204 205 bool hasITBlocks() const { return HasITBlocks; } 206 void setHasITBlocks(bool h) { HasITBlocks = h; } 207 208 bool isSplitCSR() const { return IsSplitCSR; } 209 void setIsSplitCSR(bool s) { IsSplitCSR = s; } 210 211 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) { 212 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second) 213 llvm_unreachable("Duplicate entries!"); 214 } 215 216 unsigned getOriginalCPIdx(unsigned CloneIdx) const { 217 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx); 218 if (I != CPEClones.end()) 219 return I->second; 220 else 221 return -1U; 222 } 223 224 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight( 225 MachineBasicBlock* MBB) { 226 auto It = CoalescedWeights.find(MBB); 227 if (It == CoalescedWeights.end()) { 228 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first; 229 } 230 return It; 231 } 232 233 /// Indicate to the backend that \c GV has had its storage changed to inside 234 /// a constant pool. This means it no longer needs to be emitted as a 235 /// global variable. 236 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) { 237 PromotedGlobals.insert(GV); 238 } 239 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() { 240 return PromotedGlobals; 241 } 242 int getPromotedConstpoolIncrease() const { 243 return PromotedGlobalsIncrease; 244 } 245 void setPromotedConstpoolIncrease(int Sz) { 246 PromotedGlobalsIncrease = Sz; 247 } 248 249 DenseMap<unsigned, unsigned> EHPrologueRemappedRegs; 250 }; 251 252 } // end namespace llvm 253 254 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H 255