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 class ARMSubtarget; 26 27 /// ARMFunctionInfo - This class is derived from MachineFunctionInfo and 28 /// contains private ARM-specific information for each MachineFunction. 29 class ARMFunctionInfo : public MachineFunctionInfo { 30 virtual void anchor(); 31 32 /// isThumb - True if this function is compiled under Thumb mode. 33 /// Used to initialized Align, so must precede it. 34 bool isThumb = false; 35 36 /// hasThumb2 - True if the target architecture supports Thumb2. Do not use 37 /// to determine if function is compiled under Thumb mode, for that use 38 /// 'isThumb'. 39 bool hasThumb2 = false; 40 41 /// StByValParamsPadding - For parameter that is split between 42 /// GPRs and memory; while recovering GPRs part, when 43 /// StackAlignment > 4, and GPRs-part-size mod StackAlignment != 0, 44 /// we need to insert gap before parameter start address. It allows to 45 /// "attach" GPR-part to the part that was passed via stack. 46 unsigned StByValParamsPadding = 0; 47 48 /// ArgsRegSaveSize - Size of the register save area for vararg functions or 49 /// those making guaranteed tail calls that need more stack argument space 50 /// than is provided by this functions incoming parameters. 51 /// 52 unsigned ArgRegsSaveSize = 0; 53 54 /// ReturnRegsCount - Number of registers used up in the return. 55 unsigned ReturnRegsCount = 0; 56 57 /// HasStackFrame - True if this function has a stack frame. Set by 58 /// determineCalleeSaves(). 59 bool HasStackFrame = false; 60 61 /// RestoreSPFromFP - True if epilogue should restore SP from FP. Set by 62 /// emitPrologue. 63 bool RestoreSPFromFP = 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 FPCXTSaveSize = 0; 91 unsigned FRSaveSize = 0; 92 unsigned GPRCS1Size = 0; 93 unsigned GPRCS2Size = 0; 94 unsigned DPRCSAlignGapSize = 0; 95 unsigned DPRCSSize = 0; 96 97 /// NumAlignedDPRCS2Regs - The number of callee-saved DPRs that are saved in 98 /// the aligned portion of the stack frame. This is always a contiguous 99 /// sequence of D-registers starting from d8. 100 /// 101 /// We do not keep track of the frame indices used for these registers - they 102 /// behave like any other frame index in the aligned stack frame. These 103 /// registers also aren't included in DPRCSSize above. 104 unsigned NumAlignedDPRCS2Regs = 0; 105 106 unsigned PICLabelUId = 0; 107 108 /// VarArgsFrameIndex - FrameIndex for start of varargs area. 109 int VarArgsFrameIndex = 0; 110 111 /// HasITBlocks - True if IT blocks have been inserted. 112 bool HasITBlocks = false; 113 114 // Security Extensions 115 bool IsCmseNSEntry; 116 bool IsCmseNSCall; 117 118 /// CPEClones - Track constant pool entries clones created by Constant Island 119 /// pass. 120 DenseMap<unsigned, unsigned> CPEClones; 121 122 /// ArgumentStackSize - amount of bytes on stack consumed by the arguments 123 /// being passed on the stack 124 unsigned ArgumentStackSize = 0; 125 126 /// ArgumentStackToRestore - amount of bytes on stack consumed that we must 127 /// restore on return. 128 unsigned ArgumentStackToRestore = 0; 129 130 /// CoalescedWeights - mapping of basic blocks to the rolling counter of 131 /// coalesced weights. 132 DenseMap<const MachineBasicBlock*, unsigned> CoalescedWeights; 133 134 /// True if this function has a subset of CSRs that is handled explicitly via 135 /// copies. 136 bool IsSplitCSR = false; 137 138 /// Globals that have had their storage promoted into the constant pool. 139 SmallPtrSet<const GlobalVariable*,2> PromotedGlobals; 140 141 /// The amount the literal pool has been increasedby due to promoted globals. 142 int PromotedGlobalsIncrease = 0; 143 144 /// True if r0 will be preserved by a call to this function (e.g. C++ 145 /// con/destructors). 146 bool PreservesR0 = false; 147 148 /// True if the function should sign its return address. 149 bool SignReturnAddress = false; 150 151 /// True if the fucntion should sign its return address, even if LR is not 152 /// saved. 153 bool SignReturnAddressAll = false; 154 155 /// True if BTI instructions should be placed at potential indirect jump 156 /// destinations. 157 bool BranchTargetEnforcement = false; 158 159 public: 160 ARMFunctionInfo() = default; 161 162 explicit ARMFunctionInfo(const Function &F, const ARMSubtarget *STI); 163 164 MachineFunctionInfo * 165 clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, 166 const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) 167 const override; 168 isThumbFunction()169 bool isThumbFunction() const { return isThumb; } isThumb1OnlyFunction()170 bool isThumb1OnlyFunction() const { return isThumb && !hasThumb2; } isThumb2Function()171 bool isThumb2Function() const { return isThumb && hasThumb2; } 172 isCmseNSEntryFunction()173 bool isCmseNSEntryFunction() const { return IsCmseNSEntry; } isCmseNSCallFunction()174 bool isCmseNSCallFunction() const { return IsCmseNSCall; } 175 getStoredByValParamsPadding()176 unsigned getStoredByValParamsPadding() const { return StByValParamsPadding; } setStoredByValParamsPadding(unsigned p)177 void setStoredByValParamsPadding(unsigned p) { StByValParamsPadding = p; } 178 getArgRegsSaveSize()179 unsigned getArgRegsSaveSize() const { return ArgRegsSaveSize; } setArgRegsSaveSize(unsigned s)180 void setArgRegsSaveSize(unsigned s) { ArgRegsSaveSize = s; } 181 getReturnRegsCount()182 unsigned getReturnRegsCount() const { return ReturnRegsCount; } setReturnRegsCount(unsigned s)183 void setReturnRegsCount(unsigned s) { ReturnRegsCount = s; } 184 hasStackFrame()185 bool hasStackFrame() const { return HasStackFrame; } setHasStackFrame(bool s)186 void setHasStackFrame(bool s) { HasStackFrame = s; } 187 shouldRestoreSPFromFP()188 bool shouldRestoreSPFromFP() const { return RestoreSPFromFP; } setShouldRestoreSPFromFP(bool s)189 void setShouldRestoreSPFromFP(bool s) { RestoreSPFromFP = s; } 190 isLRSpilled()191 bool isLRSpilled() const { return LRSpilled; } setLRIsSpilled(bool s)192 void setLRIsSpilled(bool s) { LRSpilled = s; } 193 getFramePtrSpillOffset()194 unsigned getFramePtrSpillOffset() const { return FramePtrSpillOffset; } setFramePtrSpillOffset(unsigned o)195 void setFramePtrSpillOffset(unsigned o) { FramePtrSpillOffset = o; } 196 getNumAlignedDPRCS2Regs()197 unsigned getNumAlignedDPRCS2Regs() const { return NumAlignedDPRCS2Regs; } setNumAlignedDPRCS2Regs(unsigned n)198 void setNumAlignedDPRCS2Regs(unsigned n) { NumAlignedDPRCS2Regs = n; } 199 getGPRCalleeSavedArea1Offset()200 unsigned getGPRCalleeSavedArea1Offset() const { return GPRCS1Offset; } getGPRCalleeSavedArea2Offset()201 unsigned getGPRCalleeSavedArea2Offset() const { return GPRCS2Offset; } getDPRCalleeSavedAreaOffset()202 unsigned getDPRCalleeSavedAreaOffset() const { return DPRCSOffset; } 203 setGPRCalleeSavedArea1Offset(unsigned o)204 void setGPRCalleeSavedArea1Offset(unsigned o) { GPRCS1Offset = o; } setGPRCalleeSavedArea2Offset(unsigned o)205 void setGPRCalleeSavedArea2Offset(unsigned o) { GPRCS2Offset = o; } setDPRCalleeSavedAreaOffset(unsigned o)206 void setDPRCalleeSavedAreaOffset(unsigned o) { DPRCSOffset = o; } 207 getFPCXTSaveAreaSize()208 unsigned getFPCXTSaveAreaSize() const { return FPCXTSaveSize; } getFrameRecordSavedAreaSize()209 unsigned getFrameRecordSavedAreaSize() const { return FRSaveSize; } getGPRCalleeSavedArea1Size()210 unsigned getGPRCalleeSavedArea1Size() const { return GPRCS1Size; } getGPRCalleeSavedArea2Size()211 unsigned getGPRCalleeSavedArea2Size() const { return GPRCS2Size; } getDPRCalleeSavedGapSize()212 unsigned getDPRCalleeSavedGapSize() const { return DPRCSAlignGapSize; } getDPRCalleeSavedAreaSize()213 unsigned getDPRCalleeSavedAreaSize() const { return DPRCSSize; } 214 setFPCXTSaveAreaSize(unsigned s)215 void setFPCXTSaveAreaSize(unsigned s) { FPCXTSaveSize = s; } setFrameRecordSavedAreaSize(unsigned s)216 void setFrameRecordSavedAreaSize(unsigned s) { FRSaveSize = s; } setGPRCalleeSavedArea1Size(unsigned s)217 void setGPRCalleeSavedArea1Size(unsigned s) { GPRCS1Size = s; } setGPRCalleeSavedArea2Size(unsigned s)218 void setGPRCalleeSavedArea2Size(unsigned s) { GPRCS2Size = s; } setDPRCalleeSavedGapSize(unsigned s)219 void setDPRCalleeSavedGapSize(unsigned s) { DPRCSAlignGapSize = s; } setDPRCalleeSavedAreaSize(unsigned s)220 void setDPRCalleeSavedAreaSize(unsigned s) { DPRCSSize = s; } 221 getArgumentStackSize()222 unsigned getArgumentStackSize() const { return ArgumentStackSize; } setArgumentStackSize(unsigned size)223 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; } 224 getArgumentStackToRestore()225 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; } setArgumentStackToRestore(unsigned v)226 void setArgumentStackToRestore(unsigned v) { ArgumentStackToRestore = v; } 227 initPICLabelUId(unsigned UId)228 void initPICLabelUId(unsigned UId) { 229 PICLabelUId = UId; 230 } 231 getNumPICLabels()232 unsigned getNumPICLabels() const { 233 return PICLabelUId; 234 } 235 createPICLabelUId()236 unsigned createPICLabelUId() { 237 return PICLabelUId++; 238 } 239 getVarArgsFrameIndex()240 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } setVarArgsFrameIndex(int Index)241 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } 242 hasITBlocks()243 bool hasITBlocks() const { return HasITBlocks; } setHasITBlocks(bool h)244 void setHasITBlocks(bool h) { HasITBlocks = h; } 245 isSplitCSR()246 bool isSplitCSR() const { return IsSplitCSR; } setIsSplitCSR(bool s)247 void setIsSplitCSR(bool s) { IsSplitCSR = s; } 248 recordCPEClone(unsigned CPIdx,unsigned CPCloneIdx)249 void recordCPEClone(unsigned CPIdx, unsigned CPCloneIdx) { 250 if (!CPEClones.insert(std::make_pair(CPCloneIdx, CPIdx)).second) 251 llvm_unreachable("Duplicate entries!"); 252 } 253 getOriginalCPIdx(unsigned CloneIdx)254 unsigned getOriginalCPIdx(unsigned CloneIdx) const { 255 DenseMap<unsigned, unsigned>::const_iterator I = CPEClones.find(CloneIdx); 256 if (I != CPEClones.end()) 257 return I->second; 258 else 259 return -1U; 260 } 261 getCoalescedWeight(MachineBasicBlock * MBB)262 DenseMap<const MachineBasicBlock*, unsigned>::iterator getCoalescedWeight( 263 MachineBasicBlock* MBB) { 264 auto It = CoalescedWeights.find(MBB); 265 if (It == CoalescedWeights.end()) { 266 It = CoalescedWeights.insert(std::make_pair(MBB, 0)).first; 267 } 268 return It; 269 } 270 271 /// Indicate to the backend that \c GV has had its storage changed to inside 272 /// a constant pool. This means it no longer needs to be emitted as a 273 /// global variable. markGlobalAsPromotedToConstantPool(const GlobalVariable * GV)274 void markGlobalAsPromotedToConstantPool(const GlobalVariable *GV) { 275 PromotedGlobals.insert(GV); 276 } getGlobalsPromotedToConstantPool()277 SmallPtrSet<const GlobalVariable*, 2>& getGlobalsPromotedToConstantPool() { 278 return PromotedGlobals; 279 } getPromotedConstpoolIncrease()280 int getPromotedConstpoolIncrease() const { 281 return PromotedGlobalsIncrease; 282 } setPromotedConstpoolIncrease(int Sz)283 void setPromotedConstpoolIncrease(int Sz) { 284 PromotedGlobalsIncrease = Sz; 285 } 286 287 DenseMap<unsigned, unsigned> EHPrologueRemappedRegs; 288 DenseMap<unsigned, unsigned> EHPrologueOffsetInRegs; 289 setPreservesR0()290 void setPreservesR0() { PreservesR0 = true; } getPreservesR0()291 bool getPreservesR0() const { return PreservesR0; } 292 shouldSignReturnAddress()293 bool shouldSignReturnAddress() const { 294 return shouldSignReturnAddress(LRSpilled); 295 } 296 shouldSignReturnAddress(bool SpillsLR)297 bool shouldSignReturnAddress(bool SpillsLR) const { 298 if (!SignReturnAddress) 299 return false; 300 if (SignReturnAddressAll) 301 return true; 302 return SpillsLR; 303 } 304 branchTargetEnforcement()305 bool branchTargetEnforcement() const { return BranchTargetEnforcement; } 306 }; 307 308 } // end namespace llvm 309 310 #endif // LLVM_LIB_TARGET_ARM_ARMMACHINEFUNCTIONINFO_H 311