LLVM  14.0.0git
AArch64FrameLowering.h
Go to the documentation of this file.
1 //==-- AArch64FrameLowering.h - TargetFrameLowering for AArch64 --*- 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 //
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
14 #define LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
15 
16 #include "llvm/Support/TypeSize.h"
18 
19 namespace llvm {
20 
21 class MCCFIInstruction;
22 
24 public:
27  true /*StackRealignable*/) {}
28 
29  void
31  MachineBasicBlock::iterator MBBI) const override;
32 
35  MachineBasicBlock::iterator I) const override;
36 
37  /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
38  /// the function.
39  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
40  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
41 
42  bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
43 
45  Register &FrameReg) const override;
47  Register &FrameReg, bool PreferFP,
48  bool ForSimm) const;
50  int64_t ObjectOffset, bool isFixed,
51  bool isSVE, Register &FrameReg,
52  bool PreferFP, bool ForSimm) const;
56  const TargetRegisterInfo *TRI) const override;
57 
58  bool
62  const TargetRegisterInfo *TRI) const override;
63 
64  /// Can this function use the red zone for local allocations.
65  bool canUseRedZone(const MachineFunction &MF) const;
66 
67  bool hasFP(const MachineFunction &MF) const override;
68  bool hasReservedCallFrame(const MachineFunction &MF) const override;
69 
70  bool hasSwiftExtendedFrame(const MachineFunction &MF) const;
71 
73  const TargetRegisterInfo *TRI,
74  std::vector<CalleeSavedInfo> &CSI,
75  unsigned &MinCSFrameIndex,
76  unsigned &MaxCSFrameIndex) const override;
77 
78  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
79  RegScavenger *RS) const override;
80 
81  /// Returns true if the target will correctly handle shrink wrapping.
82  bool enableShrinkWrapping(const MachineFunction &MF) const override {
83  return true;
84  }
85 
86  bool enableStackSlotScavenging(const MachineFunction &MF) const override;
88 
90  RegScavenger *RS) const override;
91 
92  void
94  RegScavenger *RS) const override;
95 
96  unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
97 
98  unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
99 
102  Register &FrameReg,
103  bool IgnoreSPUpdates) const override;
105  int FI) const override;
106  int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
107 
109  switch (ID) {
110  default:
111  return false;
115  return true;
116  }
117  }
118 
119  bool isStackIdSafeForLocalArea(unsigned StackId) const override {
120  // We don't support putting SVE objects into the pre-allocated local
121  // frame block at the moment.
122  return StackId != TargetStackID::ScalableVector;
123  }
124 
125  void
127  SmallVectorImpl<int> &ObjectsToAllocate) const override;
128 
129 private:
130  /// Returns true if a homogeneous prolog or epilog code can be emitted
131  /// for the size optimization. If so, HOM_Prolog/HOM_Epilog pseudo
132  /// instructions are emitted in place. When Exit block is given, this check is
133  /// for epilog.
134  bool homogeneousPrologEpilog(MachineFunction &MF,
135  MachineBasicBlock *Exit = nullptr) const;
136 
137  /// Returns true if CSRs should be paired.
138  bool producePairRegisters(MachineFunction &MF) const;
139 
140  bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
141  uint64_t StackBumpBytes) const;
142 
143  int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
144  int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
145  int &MinCSFrameIndex,
146  int &MaxCSFrameIndex) const;
148  createDefCFAExpressionFromSP(const TargetRegisterInfo &TRI,
149  const StackOffset &OffsetFromSP) const;
150  MCCFIInstruction createCfaOffset(const TargetRegisterInfo &MRI, unsigned DwarfReg,
151  const StackOffset &OffsetFromDefCFA) const;
152  bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
153  unsigned StackBumpBytes) const;
154 };
155 
156 } // End llvm namespace
157 
158 #endif
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
TargetFrameLowering.h
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
TypeSize.h
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::AArch64FrameLowering::enableStackSlotScavenging
bool enableStackSlotScavenging(const MachineFunction &MF) const override
Returns true if the stack slot holes in the fixed and callee-save stack area should be used when allo...
Definition: AArch64FrameLowering.cpp:2976
llvm::AArch64FrameLowering::assignCalleeSavedSpillSlots
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
Definition: AArch64FrameLowering.cpp:2933
llvm::AArch64FrameLowering::hasSwiftExtendedFrame
bool hasSwiftExtendedFrame(const MachineFunction &MF) const
llvm::AArch64FrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: AArch64FrameLowering.cpp:359
llvm::AArch64FrameLowering::emitCalleeSavedFrameMoves
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const override
With basic block sections, emit callee saved frame moves for basic blocks that are in a different sec...
Definition: AArch64FrameLowering.cpp:535
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::AArch64FrameLowering
Definition: AArch64FrameLowering.h:23
llvm::AArch64FrameLowering::processFunctionBeforeFrameFinalized
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Definition: AArch64FrameLowering.cpp:3088
llvm::AArch64FrameLowering::resolveFrameOffsetReference
StackOffset resolveFrameOffsetReference(const MachineFunction &MF, int64_t ObjectOffset, bool isFixed, bool isSVE, Register &FrameReg, bool PreferFP, bool ForSimm) const
Definition: AArch64FrameLowering.cpp:2049
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
llvm::AArch64FrameLowering::eliminateCallFramePseudoInstr
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
Definition: AArch64FrameLowering.cpp:399
llvm::AArch64FrameLowering::getFrameIndexReference
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - Provide a base+offset reference to an FI slot for debug info.
Definition: AArch64FrameLowering.cpp:1992
llvm::BitVector
Definition: BitVector.h:74
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MCCFIInstruction
Definition: MCDwarf.h:457
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::AArch64FrameLowering::resolveFrameIndexReference
StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg, bool PreferFP, bool ForSimm) const
Definition: AArch64FrameLowering.cpp:2038
uint64_t
llvm::AArch64FrameLowering::spillCalleeSavedRegisters
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
Definition: AArch64FrameLowering.cpp:2477
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::RegScavenger
Definition: RegisterScavenging.h:34
llvm::TargetStackID::ScalableVector
@ ScalableVector
Definition: TargetFrameLowering.h:30
llvm::AArch64FrameLowering::enableShrinkWrapping
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
Definition: AArch64FrameLowering.h:82
llvm::AArch64FrameLowering::getStackIDForScalableVectors
TargetStackID::Value getStackIDForScalableVectors() const override
Returns the StackID that scalable vectors should be associated with.
Definition: AArch64FrameLowering.cpp:309
llvm::AArch64FrameLowering::getNonLocalFrameIndexReference
StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF, int FI) const override
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index locat...
Definition: AArch64FrameLowering.cpp:2002
llvm::AArch64FrameLowering::canUseRedZone
bool canUseRedZone(const MachineFunction &MF) const
Can this function use the red zone for local allocations.
Definition: AArch64FrameLowering.cpp:337
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AArch64FrameLowering::isSupportedStackID
bool isSupportedStackID(TargetStackID::Value ID) const override
Definition: AArch64FrameLowering.h:108
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::AArch64FrameLowering::AArch64FrameLowering
AArch64FrameLowering()
Definition: AArch64FrameLowering.h:25
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition: AArch64SLSHardening.cpp:75
llvm::TargetStackID::NoAlloc
@ NoAlloc
Definition: TargetFrameLowering.h:32
llvm::StackOffset
StackOffset is a class to represent an offset with 2 dimensions, named fixed and scalable,...
Definition: TypeSize.h:134
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::AArch64FrameLowering::hasReservedCallFrame
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Definition: AArch64FrameLowering.cpp:395
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::AArch64FrameLowering::getWinEHParentFrameOffset
unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override
The parent frame offset (aka dispFrame) is only used on X86_64 to retrieve the parent's frame pointer...
Definition: AArch64FrameLowering.cpp:3547
llvm::AArch64FrameLowering::processFunctionBeforeFrameIndicesReplaced
void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
Definition: AArch64FrameLowering.cpp:3520
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::TargetStackID::Default
@ Default
Definition: TargetFrameLowering.h:28
llvm::AArch64FrameLowering::getSEHFrameIndexOffset
int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const
Definition: AArch64FrameLowering.cpp:2028
llvm::AArch64FrameLowering::getFrameIndexReferencePreferSP
StackOffset getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const override
For Win64 AArch64 EH, the offset to the Unwind object is from the SP before the update.
Definition: AArch64FrameLowering.cpp:3531
llvm::AArch64FrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition: AArch64FrameLowering.cpp:1102
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
llvm::AArch64FrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition: AArch64FrameLowering.cpp:1688
llvm::AArch64FrameLowering::canUseAsPrologue
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
Definition: AArch64FrameLowering.cpp:617
llvm::AArch64FrameLowering::getWinEHFuncletFrameSize
unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const
Funclets only need to account for space for the callee saved registers, as the locals are accounted f...
Definition: AArch64FrameLowering.cpp:3554
llvm::SmallVectorImpl< int >
llvm::TargetFrameLowering::StackGrowsDown
@ StackGrowsDown
Definition: TargetFrameLowering.h:47
llvm::AArch64FrameLowering::determineCalleeSaves
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition: AArch64FrameLowering.cpp:2760
llvm::AArch64FrameLowering::restoreCalleeSavedRegisters
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
Definition: AArch64FrameLowering.cpp:2633
llvm::AArch64FrameLowering::isStackIdSafeForLocalArea
bool isStackIdSafeForLocalArea(unsigned StackId) const override
This method returns whether or not it is safe for an object with the given stack id to be bundled int...
Definition: AArch64FrameLowering.h:119
llvm::AArch64FrameLowering::orderFrameObjects
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack frame.
Definition: AArch64FrameLowering.cpp:3628
llvm::MachineInstrBundleIterator< MachineInstr >
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1927
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37