xref: /aosp_15_r20/external/llvm/lib/Target/ARM/Thumb1FrameLowering.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- Thumb1FrameLowering.h - Thumb1-specific frame info stuff --*- 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 //
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker 
14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H
15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker #include "ARMFrameLowering.h"
18*9880d681SAndroid Build Coastguard Worker #include "Thumb1InstrInfo.h"
19*9880d681SAndroid Build Coastguard Worker #include "ThumbRegisterInfo.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetFrameLowering.h"
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker namespace llvm {
23*9880d681SAndroid Build Coastguard Worker 
24*9880d681SAndroid Build Coastguard Worker class Thumb1FrameLowering : public ARMFrameLowering {
25*9880d681SAndroid Build Coastguard Worker public:
26*9880d681SAndroid Build Coastguard Worker   explicit Thumb1FrameLowering(const ARMSubtarget &sti);
27*9880d681SAndroid Build Coastguard Worker 
28*9880d681SAndroid Build Coastguard Worker   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
29*9880d681SAndroid Build Coastguard Worker   /// the function.
30*9880d681SAndroid Build Coastguard Worker   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
31*9880d681SAndroid Build Coastguard Worker   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
32*9880d681SAndroid Build Coastguard Worker 
33*9880d681SAndroid Build Coastguard Worker   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
34*9880d681SAndroid Build Coastguard Worker                                  MachineBasicBlock::iterator MI,
35*9880d681SAndroid Build Coastguard Worker                                  const std::vector<CalleeSavedInfo> &CSI,
36*9880d681SAndroid Build Coastguard Worker                                  const TargetRegisterInfo *TRI) const override;
37*9880d681SAndroid Build Coastguard Worker   bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
38*9880d681SAndroid Build Coastguard Worker                                   MachineBasicBlock::iterator MI,
39*9880d681SAndroid Build Coastguard Worker                                   const std::vector<CalleeSavedInfo> &CSI,
40*9880d681SAndroid Build Coastguard Worker                                   const TargetRegisterInfo *TRI) const override;
41*9880d681SAndroid Build Coastguard Worker 
42*9880d681SAndroid Build Coastguard Worker   bool hasReservedCallFrame(const MachineFunction &MF) const override;
43*9880d681SAndroid Build Coastguard Worker 
44*9880d681SAndroid Build Coastguard Worker   MachineBasicBlock::iterator
45*9880d681SAndroid Build Coastguard Worker   eliminateCallFramePseudoInstr(MachineFunction &MF,
46*9880d681SAndroid Build Coastguard Worker                                 MachineBasicBlock &MBB,
47*9880d681SAndroid Build Coastguard Worker                                 MachineBasicBlock::iterator MI) const override;
48*9880d681SAndroid Build Coastguard Worker 
49*9880d681SAndroid Build Coastguard Worker   /// Check whether or not the given \p MBB can be used as a epilogue
50*9880d681SAndroid Build Coastguard Worker   /// for the target.
51*9880d681SAndroid Build Coastguard Worker   /// The epilogue will be inserted before the first terminator of that block.
52*9880d681SAndroid Build Coastguard Worker   /// This method is used by the shrink-wrapping pass to decide if
53*9880d681SAndroid Build Coastguard Worker   /// \p MBB will be correctly handled by the target.
54*9880d681SAndroid Build Coastguard Worker   bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
55*9880d681SAndroid Build Coastguard Worker 
56*9880d681SAndroid Build Coastguard Worker   /// Disable shrink wrap as tBfar/BL will be used to adjust for long jumps.
enableShrinkWrapping(const MachineFunction & MF)57*9880d681SAndroid Build Coastguard Worker   bool enableShrinkWrapping(const MachineFunction &MF) const override {
58*9880d681SAndroid Build Coastguard Worker     return false;
59*9880d681SAndroid Build Coastguard Worker   }
60*9880d681SAndroid Build Coastguard Worker 
61*9880d681SAndroid Build Coastguard Worker private:
62*9880d681SAndroid Build Coastguard Worker   /// Check if the frame lowering of \p MF needs a special fixup
63*9880d681SAndroid Build Coastguard Worker   /// code sequence for the epilogue.
64*9880d681SAndroid Build Coastguard Worker   /// Unlike T2 and ARM mode, the T1 pop instruction cannot restore
65*9880d681SAndroid Build Coastguard Worker   /// to LR, and we can't pop the value directly to the PC when
66*9880d681SAndroid Build Coastguard Worker   /// we need to update the SP after popping the value. So instead
67*9880d681SAndroid Build Coastguard Worker   /// we have to emit:
68*9880d681SAndroid Build Coastguard Worker   ///   POP {r3}
69*9880d681SAndroid Build Coastguard Worker   ///   ADD sp, #offset
70*9880d681SAndroid Build Coastguard Worker   ///   BX r3
71*9880d681SAndroid Build Coastguard Worker   /// If this would clobber a return value, then generate this sequence instead:
72*9880d681SAndroid Build Coastguard Worker   ///   MOV ip, r3
73*9880d681SAndroid Build Coastguard Worker   ///   POP {r3}
74*9880d681SAndroid Build Coastguard Worker   ///   ADD sp, #offset
75*9880d681SAndroid Build Coastguard Worker   ///   MOV lr, r3
76*9880d681SAndroid Build Coastguard Worker   ///   MOV r3, ip
77*9880d681SAndroid Build Coastguard Worker   ///   BX lr
78*9880d681SAndroid Build Coastguard Worker   bool needPopSpecialFixUp(const MachineFunction &MF) const;
79*9880d681SAndroid Build Coastguard Worker 
80*9880d681SAndroid Build Coastguard Worker   /// Emit the special fixup code sequence for the epilogue.
81*9880d681SAndroid Build Coastguard Worker   /// \see needPopSpecialFixUp for more details.
82*9880d681SAndroid Build Coastguard Worker   /// \p DoIt, tells this method whether or not to actually insert
83*9880d681SAndroid Build Coastguard Worker   /// the code sequence in \p MBB. I.e., when \p DoIt is false,
84*9880d681SAndroid Build Coastguard Worker   /// \p MBB is left untouched.
85*9880d681SAndroid Build Coastguard Worker   /// \returns For \p DoIt == true: True when the emission succeeded
86*9880d681SAndroid Build Coastguard Worker   /// false otherwise. For \p DoIt == false: True when the emission
87*9880d681SAndroid Build Coastguard Worker   /// would have been possible, false otherwise.
88*9880d681SAndroid Build Coastguard Worker   bool emitPopSpecialFixUp(MachineBasicBlock &MBB, bool DoIt) const;
89*9880d681SAndroid Build Coastguard Worker };
90*9880d681SAndroid Build Coastguard Worker 
91*9880d681SAndroid Build Coastguard Worker } // End llvm namespace
92*9880d681SAndroid Build Coastguard Worker 
93*9880d681SAndroid Build Coastguard Worker #endif
94