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