LLVM  11.0.0git
PPCFrameLowering.h
Go to the documentation of this file.
1 //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- 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 #ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
13 #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
14 
15 #include "llvm/ADT/STLExtras.h"
18 
19 namespace llvm {
20 class PPCSubtarget;
21 
23  const PPCSubtarget &Subtarget;
24  const unsigned ReturnSaveOffset;
25  const unsigned TOCSaveOffset;
26  const unsigned FramePointerSaveOffset;
27  const unsigned LinkageSize;
28  const unsigned BasePointerSaveOffset;
29  const unsigned CRSaveOffset;
30 
31  /**
32  * Find register[s] that can be used in function prologue and epilogue
33  *
34  * Find register[s] that can be use as scratch register[s] in function
35  * prologue and epilogue to save various registers (Link Register, Base
36  * Pointer, etc.). Prefer R0/R12, if available. Otherwise choose whatever
37  * register[s] are available.
38  *
39  * This method will return true if it is able to find enough unique scratch
40  * registers (1 or 2 depending on the requirement). If it is unable to find
41  * enough available registers in the block, it will return false and set
42  * any passed output parameter that corresponds to a required unique register
43  * to PPC::NoRegister.
44  *
45  * \param[in] MBB The machine basic block to find an available register for
46  * \param[in] UseAtEnd Specify whether the scratch register will be used at
47  * the end of the basic block (i.e., will the scratch
48  * register kill a register defined in the basic block)
49  * \param[in] TwoUniqueRegsRequired Specify whether this basic block will
50  * require two unique scratch registers.
51  * \param[out] SR1 The scratch register to use
52  * \param[out] SR2 The second scratch register. If this pointer is not null
53  * the function will attempt to set it to an available
54  * register regardless of whether there is a hard requirement
55  * for two unique scratch registers.
56  * \return true if the required number of registers was found.
57  * false if the required number of scratch register weren't available.
58  * If either output parameter refers to a required scratch register
59  * that isn't available, it will be set to an invalid value.
60  */
61  bool findScratchRegister(MachineBasicBlock *MBB,
62  bool UseAtEnd,
63  bool TwoUniqueRegsRequired = false,
64  Register *SR1 = nullptr,
65  Register *SR2 = nullptr) const;
66  bool twoUniqueScratchRegsRequired(MachineBasicBlock *MBB) const;
67 
68  /**
69  * Create branch instruction for PPC::TCRETURN* (tail call return)
70  *
71  * \param[in] MBB that is terminated by PPC::TCRETURN*
72  */
73  void createTailCallBranchInstr(MachineBasicBlock &MBB) const;
74 
75  /**
76  * Check if the conditions are correct to allow for the stack update
77  * to be moved past the CSR save/restore code.
78  */
79  bool stackUpdateCanBeMoved(MachineFunction &MF) const;
80 
81 public:
82  PPCFrameLowering(const PPCSubtarget &STI);
83 
84  /**
85  * Determine the frame layout and update the machine function.
86  */
88  bool UseEstimate = false) const;
89 
90  /**
91  * Determine the frame layout but do not update the machine function.
92  * The MachineFunction object can be const in this case as it is not
93  * modified.
94  */
95  unsigned determineFrameLayout(const MachineFunction &MF,
96  bool UseEstimate = false,
97  unsigned *NewMaxCallFrameSize = nullptr) const;
98 
99  /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
100  /// the function.
101  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
102  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
103 
104  bool hasFP(const MachineFunction &MF) const override;
105  bool needsFP(const MachineFunction &MF) const;
106  void replaceFPWithRealFP(MachineFunction &MF) const;
107 
108  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
109  RegScavenger *RS = nullptr) const override;
111  RegScavenger *RS = nullptr) const override;
113 
117  const TargetRegisterInfo *TRI) const override;
118  /// This function will assign callee saved gprs to volatile vector registers
119  /// for prologue spills when applicable. It returns false if there are any
120  /// registers which were not spilled to volatile vector registers.
121  bool
123  const TargetRegisterInfo *TRI,
124  std::vector<CalleeSavedInfo> &CSI) const override;
125 
128  MachineBasicBlock::iterator I) const override;
129 
130  bool
134  const TargetRegisterInfo *TRI) const override;
135 
136  /// targetHandlesStackFrameRounding - Returns true if the target is
137  /// responsible for rounding up the stack frame (probably at emitPrologue
138  /// time).
139  bool targetHandlesStackFrameRounding() const override { return true; }
140 
141  /// getReturnSaveOffset - Return the previous frame offset to save the
142  /// return address.
143  unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
144 
145  /// getTOCSaveOffset - Return the previous frame offset to save the
146  /// TOC register -- 64-bit SVR4 ABI only.
147  unsigned getTOCSaveOffset() const;
148 
149  /// getFramePointerSaveOffset - Return the previous frame offset to save the
150  /// frame pointer.
151  unsigned getFramePointerSaveOffset() const;
152 
153  /// getBasePointerSaveOffset - Return the previous frame offset to save the
154  /// base pointer.
155  unsigned getBasePointerSaveOffset() const;
156 
157  /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
158  ///
159  unsigned getLinkageSize() const { return LinkageSize; }
160 
161  const SpillSlot *
162  getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
163 
164  bool enableShrinkWrapping(const MachineFunction &MF) const override;
165 
166  /// Methods used by shrink wrapping to determine if MBB can be used for the
167  /// function prologue/epilogue.
168  bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
169  bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
170 };
171 } // End llvm namespace
172 
173 #endif
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
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...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned determineFrameLayout(const MachineFunction &MF, bool UseEstimate=false, unsigned *NewMaxCallFrameSize=nullptr) const
Determine the frame layout but do not update the machine function.
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...
unsigned const TargetRegisterInfo * TRI
unsigned determineFrameLayoutAndUpdate(MachineFunction &MF, bool UseEstimate=false) const
Determine the frame layout and update the machine function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
bool targetHandlesStackFrameRounding() const override
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:298
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Methods used by shrink wrapping to determine if MBB can be used for the function prologue/epilogue.
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
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...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
This function will assign callee saved gprs to volatile vector registers for prologue spills when app...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned getFramePointerSaveOffset() const
getFramePointerSaveOffset - Return the previous frame offset to save the frame pointer.
Information about stack frame layout on the target.
unsigned getTOCSaveOffset() const
getTOCSaveOffset - Return the previous frame offset to save the TOC register – 64-bit SVR4 ABI only...
unsigned getBasePointerSaveOffset() const
getBasePointerSaveOffset - Return the previous frame offset to save the base pointer.
PPCFrameLowering(const PPCSubtarget &STI)
#define I(x, y, z)
Definition: MD5.cpp:59
bool needsFP(const MachineFunction &MF) const
unsigned getReturnSaveOffset() const
getReturnSaveOffset - Return the previous frame offset to save the return address.
unsigned getLinkageSize() const
getLinkageSize - Return the size of the PowerPC ABI linkage area.
IRTranslator LLVM IR MI
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
void replaceFPWithRealFP(MachineFunction &MF) const