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 /// ArgsRegSaveSize - Size of the register save area for vararg functions or 47 /// those making guaranteed tail calls that need more stack argument space 48 /// than is provided by this functions incoming parameters. 49 /// 50 unsigned ArgRegsSaveSize = 0; 51 52 /// ReturnRegsCount - Number of registers used up in the return. 53 unsigned ReturnRegsCount = 0; 54 55 /// HasStackFrame - True if this function has a stack frame. Set by 56 /// determineCalleeSaves(). 57 bool HasStackFrame = false; 58 59 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by 60 /// emitPrologue. 61 bool RestoreSPFromFP = false; 62 63 /// LRSpilled - True if the LR register has been for spilled for 64 /// any reason, so it's legal to emit an ARM::tBfar (i.e. "bl"). 65 bool LRSpilled = false; 66 67 /// FramePtrSpillOffset - If HasStackFrame, this records the frame pointer 68 /// spill stack offset. 69 unsigned FramePtrSpillOffset = 0; 70 71 /// GPRCS1Offset, GPRCS2Offset, DPRCSOffset - Starting offset of callee saved 72 /// register spills areas. For Mac OS X: 73 /// 74 /// GPR callee-saved (1) : r4, r5, r6, r7, lr 75 /// -------------------------------------------- 76 /// GPR callee-saved (2) : r8, r10, r11 77 /// -------------------------------------------- 78 /// DPR callee-saved : d8 - d15 79 /// 80 /// Also see AlignedDPRCSRegs below. Not all D-regs need to go in area 3. 81 /// Some may be spilled after the stack has been realigned. 82 unsigned GPRCS1Offset = 0; 83 unsigned GPRCS2Offset = 0; 84 unsigned DPRCSOffset = 0; 85 86 /// GPRCS1Size, GPRCS2Size, DPRCSSize - Sizes of callee saved register spills 87 /// areas. 88 unsigned FPCXTSaveSize = 0; 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 // Security Extensions 112 bool IsCmseNSEntry; 113 bool IsCmseNSCall; 114 115 /// CPEClones - Track constant pool entries clones created by Constant Island 116 /// pass. 117 DenseMap<unsigned, unsigned> CPEClones; 118 119 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments 120 /// being passed on the stack 121 unsigned ArgumentStackSize = 0; 122 123 /// ArgumentStackToRestore - amount of bytes on stack consumed that we must 124 /// restore on return. 125 unsigned ArgumentStackToRestore = 0; 126 127 /// CoalescedWeights - mapping of basic blocks to the rolling counter of 128 /// coalesced weights. 129 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights; 130 131 /// True if this function has a subset of CSRs that is handled explicitly via 132 /// copies. 133 bool IsSplitCSR = false; 134 135 /// Globals that have had their storage promoted into the constant pool. 136 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals; 137 138 /// The amount the literal pool has been increasedby due to promoted globals. 139 int PromotedGlobalsIncrease = 0; 140 141 /// True if r0 will be preserved by a call to this function (e.g. C++ 142 /// con/destructors). 143 bool PreservesR0 = false; 144 145 public: 146 ARMFunctionInfo() = default; 147 148 explicit ARMFunctionInfo(MachineFunction &MF); 149 isThumbFunction()150 bool isThumbFunction() const { return isThumb; } isThumb1OnlyFunction()151 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; } isThumb2Function()152 bool isThumb2Function() const { return isThumb && hasThumb2; } 153 isCmseNSEntryFunction()154 bool isCmseNSEntryFunction() const { return IsCmseNSEntry; } isCmseNSCallFunction()155 bool isCmseNSCallFunction() const { return IsCmseNSCall; } 156 getStoredByValParamsPadding()157 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; } setStoredByValParamsPadding(unsigned p)158 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; } 159 getArgRegsSaveSize()160 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; } setArgRegsSaveSize(unsigned s)161 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; } 162 getReturnRegsCount()163 unsigned getReturnRegsCount() const { return ReturnRegsCount; } setReturnRegsCount(unsigned s)164 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; } 165 hasStackFrame()166 bool hasStackFrame() const { return HasStackFrame; } setHasStackFrame(bool s)167 void setHasStackFrame(bool s) { HasStackFrame = s; } 168 shouldRestoreSPFromFP()169 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; } setShouldRestoreSPFromFP(bool s)170 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; } 171 isLRSpilled()172 bool isLRSpilled() const { return LRSpilled; } setLRIsSpilled(bool s)173 void setLRIsSpilled(bool s) { LRSpilled = s; } 174 getFramePtrSpillOffset()175 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; } setFramePtrSpillOffset(unsigned o)176 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; } 177 getNumAlignedDPRCS2Regs()178 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; } setNumAlignedDPRCS2Regs(unsigned n)179 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; } 180 getGPRCalleeSavedArea1Offset()181 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; } getGPRCalleeSavedArea2Offset()182 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; } getDPRCalleeSavedAreaOffset()183 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; } 184 setGPRCalleeSavedArea1Offset(unsigned o)185 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; } setGPRCalleeSavedArea2Offset(unsigned o)186 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; } setDPRCalleeSavedAreaOffset(unsigned o)187 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; } 188 getFPCXTSaveAreaSize()189 unsigned getFPCXTSaveAreaSize() const { return FPCXTSaveSize; } getGPRCalleeSavedArea1Size()190 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; } getGPRCalleeSavedArea2Size()191 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; } getDPRCalleeSavedGapSize()192 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; } getDPRCalleeSavedAreaSize()193 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; } 194 setFPCXTSaveAreaSize(unsigned s)195 void setFPCXTSaveAreaSize(unsigned s) { FPCXTSaveSize = s; } setGPRCalleeSavedArea1Size(unsigned s)196 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; } setGPRCalleeSavedArea2Size(unsigned s)197 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; } setDPRCalleeSavedGapSize(unsigned s)198 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; } setDPRCalleeSavedAreaSize(unsigned s)199 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; } 200 getArgumentStackSize()201 unsigned getArgumentStackSize() const { return ArgumentStackSize; } setArgumentStackSize(unsigned size)202 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; } 203 getArgumentStackToRestore()204 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; } setArgumentStackToRestore(unsigned v)205 void setArgumentStackToRestore(unsigned v) { ArgumentStackToRestore = v; } 206 initPICLabelUId(unsigned UId)207 void initPICLabelUId(unsigned UId) { 208 PICLabelUId = UId; 209 } 210 getNumPICLabels()211 unsigned getNumPICLabels() const { 212 return PICLabelUId; 213 } 214 createPICLabelUId()215 unsigned createPICLabelUId() { 216 return PICLabelUId++; 217 } 218 getVarArgsFrameIndex()219 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } setVarArgsFrameIndex(int Index)220 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } 221 hasITBlocks()222 bool hasITBlocks() const { return HasITBlocks; } setHasITBlocks(bool h)223 void setHasITBlocks(bool h) { HasITBlocks = h; } 224 isSplitCSR()225 bool isSplitCSR() const { return IsSplitCSR; } setIsSplitCSR(bool s)226 void setIsSplitCSR(bool s) { IsSplitCSR = s; } 227 recordCPEClone(unsigned CPIdx,unsigned CPCloneIdx)228 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) { 229 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second) 230 llvm_unreachable("Duplicate entries!"); 231 } 232 getOriginalCPIdx(unsigned CloneIdx)233 unsigned getOriginalCPIdx(unsigned CloneIdx) const { 234 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx); 235 if (I != CPEClones.end()) 236 return I->second; 237 else 238 return -1U; 239 } 240 getCoalescedWeight(MachineBasicBlock * MBB)241 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight( 242 MachineBasicBlock* MBB) { 243 auto It = CoalescedWeights.find(MBB); 244 if (It == CoalescedWeights.end()) { 245 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first; 246 } 247 return It; 248 } 249 250 /// Indicate to the backend that \c GV has had its storage changed to inside 251 /// a constant pool. This means it no longer needs to be emitted as a 252 /// global variable. markGlobalAsPromotedToConstantPool(const GlobalVariable * GV)253 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) { 254 PromotedGlobals.insert(GV); 255 } getGlobalsPromotedToConstantPool()256 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() { 257 return PromotedGlobals; 258 } getPromotedConstpoolIncrease()259 int getPromotedConstpoolIncrease() const { 260 return PromotedGlobalsIncrease; 261 } setPromotedConstpoolIncrease(int Sz)262 void setPromotedConstpoolIncrease(int Sz) { 263 PromotedGlobalsIncrease = Sz; 264 } 265 266 DenseMap<unsigned, unsigned> EHPrologueRemappedRegs; 267 DenseMap<unsigned, unsigned> EHPrologueOffsetInRegs; 268 setPreservesR0()269 void setPreservesR0() { PreservesR0 = true; } getPreservesR0()270 bool getPreservesR0() const { return PreservesR0; } 271 }; 272 273 } // end namespace llvm 274 275 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H 276