LLVM  14.0.0git
M68kFrameLowering.h
Go to the documentation of this file.
1 //===- M68kFrameLowering.h - Define frame lowering for M68k -*- 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 /// \file
10 /// This file contains the M68k declaration of TargetFrameLowering class.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_M68K_M68KFRAMELOWERING_H
15 #define LLVM_LIB_TARGET_M68K_M68KFRAMELOWERING_H
16 
17 #include "M68k.h"
18 
20 
21 namespace llvm {
22 class MachineInstrBuilder;
23 class MCCFIInstruction;
24 class M68kSubtarget;
25 class M68kRegisterInfo;
26 struct Align;
27 
29  // Cached subtarget predicates.
30  const M68kSubtarget &STI;
31  const TargetInstrInfo &TII;
32  const M68kRegisterInfo *TRI;
33 
34  /// Stack slot size in bytes.
35  unsigned SlotSize;
36 
37  unsigned StackPtr;
38 
39  /// If we're forcing a stack realignment we can't rely on just the frame
40  /// info, we need to know the ABI stack alignment as well in case we have a
41  /// call out. Otherwise just make sure we have some alignment - we'll go
42  /// with the minimum SlotSize.
43  uint64_t calculateMaxStackAlign(const MachineFunction &MF) const;
44 
45  /// Adjusts the stack pointer using LEA, SUB, or ADD.
46  MachineInstrBuilder BuildStackAdjustment(MachineBasicBlock &MBB,
48  const DebugLoc &DL, int64_t Offset,
49  bool InEpilogue) const;
50 
51  /// Aligns the stack pointer by ANDing it with -MaxAlign.
52  void BuildStackAlignAND(MachineBasicBlock &MBB,
54  unsigned Reg, uint64_t MaxAlign) const;
55 
56  /// Wraps up getting a CFI index and building a MachineInstr for it.
58  const DebugLoc &DL, const MCCFIInstruction &CFIInst) const;
59 
60  void emitPrologueCalleeSavedFrameMoves(MachineBasicBlock &MBB,
62  const DebugLoc &DL) const;
63 
64  unsigned getPSPSlotOffsetFromSP(const MachineFunction &MF) const;
65 
66 public:
67  explicit M68kFrameLowering(const M68kSubtarget &sti, Align Alignment);
68 
69  static const M68kFrameLowering *create(const M68kSubtarget &ST);
70 
71  /// This method is called during prolog/epilog code insertion to eliminate
72  /// call frame setup and destroy pseudo instructions (but only if the Target
73  /// is using them). It is responsible for eliminating these instructions,
74  /// replacing them with concrete instructions. This method need only be
75  /// implemented if using call frame setup/destroy pseudo instructions.
76  /// Returns an iterator pointing to the instruction after the replaced one.
79  MachineBasicBlock::iterator MI) const override;
80 
81  /// Insert prolog code into the function.
82  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
83 
84  /// Insert epilog code into the function.
85  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
86 
87  /// This method determines which of the registers reported by
88  /// TargetRegisterInfo::getCalleeSavedRegs() should actually get saved.
89  /// The default implementation checks populates the \p SavedRegs bitset with
90  /// all registers which are modified in the function, targets may override
91  /// this function to save additional registers.
92  /// This method also sets up the register scavenger ensuring there is a free
93  /// register or a frameindex available.
94  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
95  RegScavenger *RS = nullptr) const override;
96 
97  /// Allows target to override spill slot assignment logic. If implemented,
98  /// assignCalleeSavedSpillSlots() should assign frame slots to all CSI
99  /// entries and return true. If this method returns false, spill slots will
100  /// be assigned using generic implementation. assignCalleeSavedSpillSlots()
101  /// may add, delete or rearrange elements of CSI.
102  bool
104  const TargetRegisterInfo *TRI,
105  std::vector<CalleeSavedInfo> &CSI) const override;
106 
107  /// Issues instruction(s) to spill all callee saved registers and returns
108  /// true if it isn't possible / profitable to do so by issuing a series of
109  /// store instructions via storeRegToStackSlot(). Returns false otherwise.
113  const TargetRegisterInfo *TRI) const override;
114 
115  /// Issues instruction(s) to restore all callee saved registers and returns
116  /// true if it isn't possible / profitable to do so by issuing a series of
117  /// load instructions via loadRegToStackSlot(). Returns false otherwise.
118  bool
122  const TargetRegisterInfo *TRI) const override;
123 
124  /// Return true if the specified function should have a dedicated frame
125  /// pointer register. This is true if the function has variable sized
126  /// allocas, if it needs dynamic stack realignment, if frame pointer
127  /// elimination is disabled, or if the frame address is taken.
128  bool hasFP(const MachineFunction &MF) const override;
129 
130  /// Under normal circumstances, when a frame pointer is not required, we
131  /// reserve argument space for call sites in the function immediately on
132  /// entry to the current function. This eliminates the need for add/sub sp
133  /// brackets around call sites. Returns true if the call frame is included as
134  /// part of the stack frame.
135  bool hasReservedCallFrame(const MachineFunction &MF) const override;
136 
137  /// If there is a reserved call frame, the call frame pseudos can be
138  /// simplified. Having a FP, as in the default implementation, is not
139  /// sufficient here since we can't always use it. Use a more nuanced
140  /// condition.
141  bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;
142 
143  // Do we need to perform FI resolution for this function. Normally, this is
144  // required only when the function has any stack objects. However, FI
145  // resolution actually has another job, not apparent from the title - it
146  // resolves callframe setup/destroy that were not simplified earlier.
147  //
148  // So, this is required for M68k functions that have push sequences even
149  // when there are no stack objects.
150  bool needsFrameIndexResolution(const MachineFunction &MF) const override;
151 
152  /// This method should return the base register and offset used to reference
153  /// a frame index location. The offset is returned directly, and the base
154  /// register is returned via FrameReg.
156  Register &FrameReg) const override;
157 
158  /// Check the instruction before/after the passed instruction. If
159  /// it is an ADD/SUB/LEA instruction it is deleted argument and the
160  /// stack adjustment is returned as a positive value for ADD/LEA and
161  /// a negative for SUB.
163  bool doMergeWithPrevious) const;
164 
165  /// Emit a series of instructions to increment / decrement the stack
166  /// pointer by a constant value.
168  int64_t NumBytes, bool InEpilogue) const;
169 };
170 } // namespace llvm
171 
172 #endif
llvm::M68kFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Insert epilog code into the function.
Definition: M68kFrameLowering.cpp:675
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::M68kFrameLowering::M68kFrameLowering
M68kFrameLowering(const M68kSubtarget &sti, Align Alignment)
Definition: M68kFrameLowering.cpp:36
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::M68kFrameLowering::create
static const M68kFrameLowering * create(const M68kSubtarget &ST)
TargetFrameLowering.h
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
llvm::M68kFrameLowering::determineCalleeSaves
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
Definition: M68kFrameLowering.cpp:776
llvm::M68kFrameLowering::emitSPUpdate
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value.
Definition: M68kFrameLowering.cpp:337
llvm::M68kRegisterInfo
Definition: M68kRegisterInfo.h:30
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::M68kFrameLowering::needsFrameIndexResolution
bool needsFrameIndexResolution(const MachineFunction &MF) const override
Definition: M68kFrameLowering.cpp:65
M68k.h
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
llvm::M68kFrameLowering::restoreCalleeSavedRegisters
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
Issues instruction(s) to restore all callee saved registers and returns true if it isn't possible / p...
Definition: M68kFrameLowering.cpp:870
llvm::BitVector
Definition: BitVector.h:74
llvm::M68kFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
Definition: M68kFrameLowering.cpp:43
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
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::M68kSubtarget
Definition: M68kSubtarget.h:45
llvm::M68kFrameLowering::spillCalleeSavedRegisters
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
Issues instruction(s) to spill all callee saved registers and returns true if it isn't possible / pro...
Definition: M68kFrameLowering.cpp:835
llvm::MachineInstrBuilder
Definition: MachineInstrBuilder.h:69
uint64_t
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::RegScavenger
Definition: RegisterScavenging.h:34
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::M68kFrameLowering::getFrameIndexReference
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
This method should return the base register and offset used to reference a frame index location.
Definition: M68kFrameLowering.cpp:76
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition: AArch64SLSHardening.cpp:75
llvm::M68kFrameLowering::assignCalleeSavedSpillSlots
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
Allows target to override spill slot assignment logic.
Definition: M68kFrameLowering.cpp:806
llvm::StackOffset
StackOffset is a class to represent an offset with 2 dimensions, named fixed and scalable,...
Definition: TypeSize.h:134
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::M68kFrameLowering
Definition: M68kFrameLowering.h:28
llvm::M68kFrameLowering::eliminateCallFramePseudoInstr
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
Definition: M68kFrameLowering.cpp:227
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::M68kFrameLowering::canSimplifyCallFramePseudos
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
If there is a reserved call frame, the call frame pseudos can be simplified.
Definition: M68kFrameLowering.cpp:58
llvm::M68kFrameLowering::hasReservedCallFrame
bool hasReservedCallFrame(const MachineFunction &MF) const override
Under normal circumstances, when a frame pointer is not required, we reserve argument space for call ...
Definition: M68kFrameLowering.cpp:53
llvm::M68kFrameLowering::mergeSPUpdates
int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, bool doMergeWithPrevious) const
Check the instruction before/after the passed instruction.
Definition: M68kFrameLowering.cpp:384
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::M68kFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Insert prolog code into the function.
Definition: M68kFrameLowering.cpp:474
llvm::MachineInstrBundleIterator< MachineInstr >