#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
#define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/CallingConvLower.h"
#include "llvm/CodeGen/MIRYamlMapping.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/IR/Function.h"
#include "llvm/MC/MCLinkerOptimizationHint.h"
#include <cassert>
namespace llvm {
namespace yaml {
struct AArch64FunctionInfo;
}
class MachineInstr;
class AArch64FunctionInfo final : public MachineFunctionInfo {
MachineFunction *MF;
unsigned BytesInStackArgArea = 0;
unsigned ArgumentStackToRestore = 0;
unsigned TailCallReservedStack = 0;
bool HasStackFrame = false;
uint64_t LocalStackSize = 0;
int MinSVECSFrameIndex = 0;
int MaxSVECSFrameIndex = 0;
unsigned CalleeSavedStackSize = 0;
unsigned SVECalleeSavedStackSize = 0;
bool HasCalleeSavedStackSize = false;
unsigned NumLocalDynamicTLSAccesses = 0;
int VarArgsStackIndex = 0;
int VarArgsGPRIndex = 0;
unsigned VarArgsGPRSize = 0;
int VarArgsFPRIndex = 0;
unsigned VarArgsFPRSize = 0;
bool IsSplitCSR = false;
bool StackRealigned = false;
bool CalleeSaveStackHasFreeSpace = false;
Register SRetReturnReg;
uint64_t StackSizeSVE = 0;
bool HasCalculatedStackSizeSVE = false;
Optional<bool> HasRedZone;
SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
Optional<int> TaggedBasePointerIndex;
unsigned TaggedBasePointerOffset;
Optional<std::string> OutliningStyle;
int CalleeSaveBaseToFrameRecordOffset = 0;
bool SignReturnAddress = false;
bool SignReturnAddressAll = false;
bool SignWithBKey = false;
bool BranchTargetEnforcement = false;
bool HasSwiftAsyncContext = false;
int SwiftAsyncContextFrameIdx = std::numeric_limits<int>::max();
bool IsMTETagged = false;
bool IsSVECC = false;
mutable Optional<bool> NeedsDwarfUnwindInfo;
mutable Optional<bool> NeedsAsyncDwarfUnwindInfo;
public:
explicit AArch64FunctionInfo(MachineFunction &MF);
MachineFunctionInfo *
clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
const override;
bool isSVECC() const { return IsSVECC; };
void setIsSVECC(bool s) { IsSVECC = s; };
void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI);
unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
void setArgumentStackToRestore(unsigned bytes) {
ArgumentStackToRestore = bytes;
}
unsigned getTailCallReservedStack() const { return TailCallReservedStack; }
void setTailCallReservedStack(unsigned bytes) {
TailCallReservedStack = bytes;
}
bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; }
void setStackSizeSVE(uint64_t S) {
HasCalculatedStackSizeSVE = true;
StackSizeSVE = S;
}
uint64_t getStackSizeSVE() const { return StackSizeSVE; }
bool hasStackFrame() const { return HasStackFrame; }
void setHasStackFrame(bool s) { HasStackFrame = s; }
bool isStackRealigned() const { return StackRealigned; }
void setStackRealigned(bool s) { StackRealigned = s; }
bool hasCalleeSaveStackFreeSpace() const {
return CalleeSaveStackHasFreeSpace;
}
void setCalleeSaveStackHasFreeSpace(bool s) {
CalleeSaveStackHasFreeSpace = s;
}
bool isSplitCSR() const { return IsSplitCSR; }
void setIsSplitCSR(bool s) { IsSplitCSR = s; }
void setLocalStackSize(uint64_t Size) { LocalStackSize = Size; }
uint64_t getLocalStackSize() const { return LocalStackSize; }
void setOutliningStyle(std::string Style) { OutliningStyle = Style; }
Optional<std::string> getOutliningStyle() const { return OutliningStyle; }
void setCalleeSavedStackSize(unsigned Size) {
CalleeSavedStackSize = Size;
HasCalleeSavedStackSize = true;
}
unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const {
bool ValidateCalleeSavedStackSize = false;
#ifndef NDEBUG
ValidateCalleeSavedStackSize = HasCalleeSavedStackSize;
#endif
if (!HasCalleeSavedStackSize || ValidateCalleeSavedStackSize) {
assert(MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated");
if (MFI.getCalleeSavedInfo().empty())
return 0;
int64_t MinOffset = std::numeric_limits<int64_t>::max();
int64_t MaxOffset = std::numeric_limits<int64_t>::min();
for (const auto &Info : MFI.getCalleeSavedInfo()) {
int FrameIdx = Info.getFrameIdx();
if (MFI.getStackID(FrameIdx) != TargetStackID::Default)
continue;
int64_t Offset = MFI.getObjectOffset(FrameIdx);
int64_t ObjSize = MFI.getObjectSize(FrameIdx);
MinOffset = std::min<int64_t>(Offset, MinOffset);
MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset);
}
if (SwiftAsyncContextFrameIdx != std::numeric_limits<int>::max()) {
int64_t Offset = MFI.getObjectOffset(getSwiftAsyncContextFrameIdx());
int64_t ObjSize = MFI.getObjectSize(getSwiftAsyncContextFrameIdx());
MinOffset = std::min<int64_t>(Offset, MinOffset);
MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset);
}
unsigned Size = alignTo(MaxOffset - MinOffset, 16);
assert((!HasCalleeSavedStackSize || getCalleeSavedStackSize() == Size) &&
"Invalid size calculated for callee saves");
return Size;
}
return getCalleeSavedStackSize();
}
unsigned getCalleeSavedStackSize() const {
assert(HasCalleeSavedStackSize &&
"CalleeSavedStackSize has not been calculated");
return CalleeSavedStackSize;
}
void setSVECalleeSavedStackSize(unsigned Size) {
SVECalleeSavedStackSize = Size;
}
unsigned getSVECalleeSavedStackSize() const {
return SVECalleeSavedStackSize;
}
void setMinMaxSVECSFrameIndex(int Min, int Max) {
MinSVECSFrameIndex = Min;
MaxSVECSFrameIndex = Max;
}
int getMinSVECSFrameIndex() const { return MinSVECSFrameIndex; }
int getMaxSVECSFrameIndex() const { return MaxSVECSFrameIndex; }
void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
unsigned getNumLocalDynamicTLSAccesses() const {
return NumLocalDynamicTLSAccesses;
}
Optional<bool> hasRedZone() const { return HasRedZone; }
void setHasRedZone(bool s) { HasRedZone = s; }
int getVarArgsStackIndex() const { return VarArgsStackIndex; }
void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
unsigned getSRetReturnReg() const { return SRetReturnReg; }
void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
unsigned getJumpTableEntrySize(int Idx) const {
return JumpTableEntryInfo[Idx].first;
}
MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
return JumpTableEntryInfo[Idx].second;
}
void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
if ((unsigned)Idx >= JumpTableEntryInfo.size())
JumpTableEntryInfo.resize(Idx+1);
JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
}
using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
class MILOHDirective {
MCLOHType Kind;
SmallVector<const MachineInstr *, 3> Args;
public:
using LOHArgs = ArrayRef<const MachineInstr *>;
MILOHDirective(MCLOHType Kind, LOHArgs Args)
: Kind(Kind), Args(Args.begin(), Args.end()) {
assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
}
MCLOHType getKind() const { return Kind; }
LOHArgs getArgs() const { return Args; }
};
using MILOHArgs = MILOHDirective::LOHArgs;
using MILOHContainer = SmallVector<MILOHDirective, 32>;
const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
LOHContainerSet.push_back(MILOHDirective(Kind, Args));
LOHRelated.insert(Args.begin(), Args.end());
}
SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
return ForwardedMustTailRegParms;
}
Optional<int> getTaggedBasePointerIndex() const {
return TaggedBasePointerIndex;
}
void setTaggedBasePointerIndex(int Index) { TaggedBasePointerIndex = Index; }
unsigned getTaggedBasePointerOffset() const {
return TaggedBasePointerOffset;
}
void setTaggedBasePointerOffset(unsigned Offset) {
TaggedBasePointerOffset = Offset;
}
int getCalleeSaveBaseToFrameRecordOffset() const {
return CalleeSaveBaseToFrameRecordOffset;
}
void setCalleeSaveBaseToFrameRecordOffset(int Offset) {
CalleeSaveBaseToFrameRecordOffset = Offset;
}
bool shouldSignReturnAddress() const;
bool shouldSignReturnAddress(bool SpillsLR) const;
bool shouldSignWithBKey() const { return SignWithBKey; }
bool isMTETagged() const { return IsMTETagged; }
bool branchTargetEnforcement() const { return BranchTargetEnforcement; }
void setHasSwiftAsyncContext(bool HasContext) {
HasSwiftAsyncContext = HasContext;
}
bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
void setSwiftAsyncContextFrameIdx(int FI) {
SwiftAsyncContextFrameIdx = FI;
}
int getSwiftAsyncContextFrameIdx() const { return SwiftAsyncContextFrameIdx; }
bool needsDwarfUnwindInfo() const;
bool needsAsyncDwarfUnwindInfo() const;
private:
MILOHContainer LOHContainerSet;
SetOfInstructions LOHRelated;
SmallVector<std::pair<unsigned, MCSymbol *>, 2> JumpTableEntryInfo;
};
namespace yaml {
struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
Optional<bool> HasRedZone;
AArch64FunctionInfo() = default;
AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI);
void mappingImpl(yaml::IO &YamlIO) override;
~AArch64FunctionInfo() = default;
};
template <> struct MappingTraits<AArch64FunctionInfo> {
static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) {
YamlIO.mapOptional("hasRedZone", MFI.HasRedZone);
}
};
}
}
#endif