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