1*9880d681SAndroid Build Coastguard Worker //=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- C++ -*-=// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file declares AArch64-specific per-machine-function information. 11*9880d681SAndroid Build Coastguard Worker // 12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H 15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallPtrSet.h" 18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h" 19*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunction.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCLinkerOptimizationHint.h" 21*9880d681SAndroid Build Coastguard Worker 22*9880d681SAndroid Build Coastguard Worker namespace llvm { 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and 25*9880d681SAndroid Build Coastguard Worker /// contains private AArch64-specific information for each MachineFunction. 26*9880d681SAndroid Build Coastguard Worker class AArch64FunctionInfo : public MachineFunctionInfo { 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker /// Number of bytes of arguments this function has on the stack. If the callee 29*9880d681SAndroid Build Coastguard Worker /// is expected to restore the argument stack this should be a multiple of 16, 30*9880d681SAndroid Build Coastguard Worker /// all usable during a tail call. 31*9880d681SAndroid Build Coastguard Worker /// 32*9880d681SAndroid Build Coastguard Worker /// The alternative would forbid tail call optimisation in some cases: if we 33*9880d681SAndroid Build Coastguard Worker /// want to transfer control from a function with 8-bytes of stack-argument 34*9880d681SAndroid Build Coastguard Worker /// space to a function with 16-bytes then misalignment of this value would 35*9880d681SAndroid Build Coastguard Worker /// make a stack adjustment necessary, which could not be undone by the 36*9880d681SAndroid Build Coastguard Worker /// callee. 37*9880d681SAndroid Build Coastguard Worker unsigned BytesInStackArgArea; 38*9880d681SAndroid Build Coastguard Worker 39*9880d681SAndroid Build Coastguard Worker /// The number of bytes to restore to deallocate space for incoming 40*9880d681SAndroid Build Coastguard Worker /// arguments. Canonically 0 in the C calling convention, but non-zero when 41*9880d681SAndroid Build Coastguard Worker /// callee is expected to pop the args. 42*9880d681SAndroid Build Coastguard Worker unsigned ArgumentStackToRestore; 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Worker /// HasStackFrame - True if this function has a stack frame. Set by 45*9880d681SAndroid Build Coastguard Worker /// determineCalleeSaves(). 46*9880d681SAndroid Build Coastguard Worker bool HasStackFrame; 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker /// \brief Amount of stack frame size, not including callee-saved registers. 49*9880d681SAndroid Build Coastguard Worker unsigned LocalStackSize; 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker /// \brief Amount of stack frame size used for saving callee-saved registers. 52*9880d681SAndroid Build Coastguard Worker unsigned CalleeSavedStackSize; 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker /// \brief Number of TLS accesses using the special (combinable) 55*9880d681SAndroid Build Coastguard Worker /// _TLS_MODULE_BASE_ symbol. 56*9880d681SAndroid Build Coastguard Worker unsigned NumLocalDynamicTLSAccesses; 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker /// \brief FrameIndex for start of varargs area for arguments passed on the 59*9880d681SAndroid Build Coastguard Worker /// stack. 60*9880d681SAndroid Build Coastguard Worker int VarArgsStackIndex; 61*9880d681SAndroid Build Coastguard Worker 62*9880d681SAndroid Build Coastguard Worker /// \brief FrameIndex for start of varargs area for arguments passed in 63*9880d681SAndroid Build Coastguard Worker /// general purpose registers. 64*9880d681SAndroid Build Coastguard Worker int VarArgsGPRIndex; 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Worker /// \brief Size of the varargs area for arguments passed in general purpose 67*9880d681SAndroid Build Coastguard Worker /// registers. 68*9880d681SAndroid Build Coastguard Worker unsigned VarArgsGPRSize; 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker /// \brief FrameIndex for start of varargs area for arguments passed in 71*9880d681SAndroid Build Coastguard Worker /// floating-point registers. 72*9880d681SAndroid Build Coastguard Worker int VarArgsFPRIndex; 73*9880d681SAndroid Build Coastguard Worker 74*9880d681SAndroid Build Coastguard Worker /// \brief Size of the varargs area for arguments passed in floating-point 75*9880d681SAndroid Build Coastguard Worker /// registers. 76*9880d681SAndroid Build Coastguard Worker unsigned VarArgsFPRSize; 77*9880d681SAndroid Build Coastguard Worker 78*9880d681SAndroid Build Coastguard Worker /// True if this function has a subset of CSRs that is handled explicitly via 79*9880d681SAndroid Build Coastguard Worker /// copies. 80*9880d681SAndroid Build Coastguard Worker bool IsSplitCSR; 81*9880d681SAndroid Build Coastguard Worker 82*9880d681SAndroid Build Coastguard Worker /// True when the stack gets realigned dynamically because the size of stack 83*9880d681SAndroid Build Coastguard Worker /// frame is unknown at compile time. e.g., in case of VLAs. 84*9880d681SAndroid Build Coastguard Worker bool StackRealigned; 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker /// True when the callee-save stack area has unused gaps that may be used for 87*9880d681SAndroid Build Coastguard Worker /// other stack allocations. 88*9880d681SAndroid Build Coastguard Worker bool CalleeSaveStackHasFreeSpace; 89*9880d681SAndroid Build Coastguard Worker 90*9880d681SAndroid Build Coastguard Worker public: AArch64FunctionInfo()91*9880d681SAndroid Build Coastguard Worker AArch64FunctionInfo() 92*9880d681SAndroid Build Coastguard Worker : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false), 93*9880d681SAndroid Build Coastguard Worker NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0), 94*9880d681SAndroid Build Coastguard Worker VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0), 95*9880d681SAndroid Build Coastguard Worker IsSplitCSR(false), StackRealigned(false), 96*9880d681SAndroid Build Coastguard Worker CalleeSaveStackHasFreeSpace(false) {} 97*9880d681SAndroid Build Coastguard Worker AArch64FunctionInfo(MachineFunction & MF)98*9880d681SAndroid Build Coastguard Worker explicit AArch64FunctionInfo(MachineFunction &MF) 99*9880d681SAndroid Build Coastguard Worker : BytesInStackArgArea(0), ArgumentStackToRestore(0), HasStackFrame(false), 100*9880d681SAndroid Build Coastguard Worker NumLocalDynamicTLSAccesses(0), VarArgsStackIndex(0), VarArgsGPRIndex(0), 101*9880d681SAndroid Build Coastguard Worker VarArgsGPRSize(0), VarArgsFPRIndex(0), VarArgsFPRSize(0), 102*9880d681SAndroid Build Coastguard Worker IsSplitCSR(false), StackRealigned(false), 103*9880d681SAndroid Build Coastguard Worker CalleeSaveStackHasFreeSpace(false) { 104*9880d681SAndroid Build Coastguard Worker (void)MF; 105*9880d681SAndroid Build Coastguard Worker } 106*9880d681SAndroid Build Coastguard Worker getBytesInStackArgArea()107*9880d681SAndroid Build Coastguard Worker unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; } setBytesInStackArgArea(unsigned bytes)108*9880d681SAndroid Build Coastguard Worker void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; } 109*9880d681SAndroid Build Coastguard Worker getArgumentStackToRestore()110*9880d681SAndroid Build Coastguard Worker unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; } setArgumentStackToRestore(unsigned bytes)111*9880d681SAndroid Build Coastguard Worker void setArgumentStackToRestore(unsigned bytes) { 112*9880d681SAndroid Build Coastguard Worker ArgumentStackToRestore = bytes; 113*9880d681SAndroid Build Coastguard Worker } 114*9880d681SAndroid Build Coastguard Worker hasStackFrame()115*9880d681SAndroid Build Coastguard Worker bool hasStackFrame() const { return HasStackFrame; } setHasStackFrame(bool s)116*9880d681SAndroid Build Coastguard Worker void setHasStackFrame(bool s) { HasStackFrame = s; } 117*9880d681SAndroid Build Coastguard Worker isStackRealigned()118*9880d681SAndroid Build Coastguard Worker bool isStackRealigned() const { return StackRealigned; } setStackRealigned(bool s)119*9880d681SAndroid Build Coastguard Worker void setStackRealigned(bool s) { StackRealigned = s; } 120*9880d681SAndroid Build Coastguard Worker hasCalleeSaveStackFreeSpace()121*9880d681SAndroid Build Coastguard Worker bool hasCalleeSaveStackFreeSpace() const { 122*9880d681SAndroid Build Coastguard Worker return CalleeSaveStackHasFreeSpace; 123*9880d681SAndroid Build Coastguard Worker } setCalleeSaveStackHasFreeSpace(bool s)124*9880d681SAndroid Build Coastguard Worker void setCalleeSaveStackHasFreeSpace(bool s) { 125*9880d681SAndroid Build Coastguard Worker CalleeSaveStackHasFreeSpace = s; 126*9880d681SAndroid Build Coastguard Worker } 127*9880d681SAndroid Build Coastguard Worker isSplitCSR()128*9880d681SAndroid Build Coastguard Worker bool isSplitCSR() const { return IsSplitCSR; } setIsSplitCSR(bool s)129*9880d681SAndroid Build Coastguard Worker void setIsSplitCSR(bool s) { IsSplitCSR = s; } 130*9880d681SAndroid Build Coastguard Worker setLocalStackSize(unsigned Size)131*9880d681SAndroid Build Coastguard Worker void setLocalStackSize(unsigned Size) { LocalStackSize = Size; } getLocalStackSize()132*9880d681SAndroid Build Coastguard Worker unsigned getLocalStackSize() const { return LocalStackSize; } 133*9880d681SAndroid Build Coastguard Worker setCalleeSavedStackSize(unsigned Size)134*9880d681SAndroid Build Coastguard Worker void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; } getCalleeSavedStackSize()135*9880d681SAndroid Build Coastguard Worker unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; } 136*9880d681SAndroid Build Coastguard Worker incNumLocalDynamicTLSAccesses()137*9880d681SAndroid Build Coastguard Worker void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; } getNumLocalDynamicTLSAccesses()138*9880d681SAndroid Build Coastguard Worker unsigned getNumLocalDynamicTLSAccesses() const { 139*9880d681SAndroid Build Coastguard Worker return NumLocalDynamicTLSAccesses; 140*9880d681SAndroid Build Coastguard Worker } 141*9880d681SAndroid Build Coastguard Worker getVarArgsStackIndex()142*9880d681SAndroid Build Coastguard Worker int getVarArgsStackIndex() const { return VarArgsStackIndex; } setVarArgsStackIndex(int Index)143*9880d681SAndroid Build Coastguard Worker void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; } 144*9880d681SAndroid Build Coastguard Worker getVarArgsGPRIndex()145*9880d681SAndroid Build Coastguard Worker int getVarArgsGPRIndex() const { return VarArgsGPRIndex; } setVarArgsGPRIndex(int Index)146*9880d681SAndroid Build Coastguard Worker void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; } 147*9880d681SAndroid Build Coastguard Worker getVarArgsGPRSize()148*9880d681SAndroid Build Coastguard Worker unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; } setVarArgsGPRSize(unsigned Size)149*9880d681SAndroid Build Coastguard Worker void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; } 150*9880d681SAndroid Build Coastguard Worker getVarArgsFPRIndex()151*9880d681SAndroid Build Coastguard Worker int getVarArgsFPRIndex() const { return VarArgsFPRIndex; } setVarArgsFPRIndex(int Index)152*9880d681SAndroid Build Coastguard Worker void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; } 153*9880d681SAndroid Build Coastguard Worker getVarArgsFPRSize()154*9880d681SAndroid Build Coastguard Worker unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; } setVarArgsFPRSize(unsigned Size)155*9880d681SAndroid Build Coastguard Worker void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; } 156*9880d681SAndroid Build Coastguard Worker 157*9880d681SAndroid Build Coastguard Worker typedef SmallPtrSet<const MachineInstr *, 16> SetOfInstructions; 158*9880d681SAndroid Build Coastguard Worker getLOHRelated()159*9880d681SAndroid Build Coastguard Worker const SetOfInstructions &getLOHRelated() const { return LOHRelated; } 160*9880d681SAndroid Build Coastguard Worker 161*9880d681SAndroid Build Coastguard Worker // Shortcuts for LOH related types. 162*9880d681SAndroid Build Coastguard Worker class MILOHDirective { 163*9880d681SAndroid Build Coastguard Worker MCLOHType Kind; 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard Worker /// Arguments of this directive. Order matters. 166*9880d681SAndroid Build Coastguard Worker SmallVector<const MachineInstr *, 3> Args; 167*9880d681SAndroid Build Coastguard Worker 168*9880d681SAndroid Build Coastguard Worker public: 169*9880d681SAndroid Build Coastguard Worker typedef ArrayRef<const MachineInstr *> LOHArgs; 170*9880d681SAndroid Build Coastguard Worker MILOHDirective(MCLOHType Kind,LOHArgs Args)171*9880d681SAndroid Build Coastguard Worker MILOHDirective(MCLOHType Kind, LOHArgs Args) 172*9880d681SAndroid Build Coastguard Worker : Kind(Kind), Args(Args.begin(), Args.end()) { 173*9880d681SAndroid Build Coastguard Worker assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); 174*9880d681SAndroid Build Coastguard Worker } 175*9880d681SAndroid Build Coastguard Worker getKind()176*9880d681SAndroid Build Coastguard Worker MCLOHType getKind() const { return Kind; } getArgs()177*9880d681SAndroid Build Coastguard Worker LOHArgs getArgs() const { return Args; } 178*9880d681SAndroid Build Coastguard Worker }; 179*9880d681SAndroid Build Coastguard Worker 180*9880d681SAndroid Build Coastguard Worker typedef MILOHDirective::LOHArgs MILOHArgs; 181*9880d681SAndroid Build Coastguard Worker typedef SmallVector<MILOHDirective, 32> MILOHContainer; 182*9880d681SAndroid Build Coastguard Worker getLOHContainer()183*9880d681SAndroid Build Coastguard Worker const MILOHContainer &getLOHContainer() const { return LOHContainerSet; } 184*9880d681SAndroid Build Coastguard Worker 185*9880d681SAndroid Build Coastguard Worker /// Add a LOH directive of this @p Kind and this @p Args. addLOHDirective(MCLOHType Kind,MILOHArgs Args)186*9880d681SAndroid Build Coastguard Worker void addLOHDirective(MCLOHType Kind, MILOHArgs Args) { 187*9880d681SAndroid Build Coastguard Worker LOHContainerSet.push_back(MILOHDirective(Kind, Args)); 188*9880d681SAndroid Build Coastguard Worker LOHRelated.insert(Args.begin(), Args.end()); 189*9880d681SAndroid Build Coastguard Worker } 190*9880d681SAndroid Build Coastguard Worker 191*9880d681SAndroid Build Coastguard Worker private: 192*9880d681SAndroid Build Coastguard Worker // Hold the lists of LOHs. 193*9880d681SAndroid Build Coastguard Worker MILOHContainer LOHContainerSet; 194*9880d681SAndroid Build Coastguard Worker SetOfInstructions LOHRelated; 195*9880d681SAndroid Build Coastguard Worker }; 196*9880d681SAndroid Build Coastguard Worker } // End llvm namespace 197*9880d681SAndroid Build Coastguard Worker 198*9880d681SAndroid Build Coastguard Worker #endif 199