| Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 1 | //===- Thumb1FrameLowering.h - Thumb1-specific frame info stuff ---*- C++ -*-=// |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 8 | |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 9 | #ifndef LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H |
| 10 | #define LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 11 | |
| Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 12 | #include "ARMFrameLowering.h" |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 13 | |
| 14 | namespace llvm { |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 15 | |
| Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 16 | class ARMSubtarget; |
| 17 | class MachineFunction; |
| 18 | |
| Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 19 | class Thumb1FrameLowering : public ARMFrameLowering { |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 20 | public: |
| Eric Christopher | 45fb7b6 | 2014-06-26 19:29:59 +0000 | [diff] [blame] | 21 | explicit Thumb1FrameLowering(const ARMSubtarget &sti); |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 22 | |
| 23 | /// emitProlog/emitEpilog - These methods insert prolog and epilog code into |
| 24 | /// the function. |
| Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 25 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 26 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
| Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 27 | |
| Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 28 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 29 | MachineBasicBlock::iterator MI, |
| 30 | const std::vector<CalleeSavedInfo> &CSI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 31 | const TargetRegisterInfo *TRI) const override; |
| Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 32 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 33 | MachineBasicBlock::iterator MI, |
| Krzysztof Parzyszek | bea30c6 | 2017-08-10 16:17:32 +0000 | [diff] [blame] | 34 | std::vector<CalleeSavedInfo> &CSI, |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 35 | const TargetRegisterInfo *TRI) const override; |
| Anton Korobeynikov | d08fbd1 | 2010-11-27 23:05:03 +0000 | [diff] [blame] | 36 | |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 37 | bool hasReservedCallFrame(const MachineFunction &MF) const override; |
| Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 38 | |
| Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 39 | MachineBasicBlock::iterator |
| Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 40 | eliminateCallFramePseudoInstr(MachineFunction &MF, |
| 41 | MachineBasicBlock &MBB, |
| 42 | MachineBasicBlock::iterator MI) const override; |
| Quentin Colombet | 48b7720 | 2015-07-22 16:34:37 +0000 | [diff] [blame] | 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 | |
| Weiming Zhao | 48c033e | 2016-01-08 18:37:43 +0000 | [diff] [blame] | 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 | |
| Quentin Colombet | 48b7720 | 2015-07-22 16:34:37 +0000 | [diff] [blame] | 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; |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
| Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 86 | } // end namespace llvm |
| Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 87 | |
| Eugene Zelenko | 076468c | 2017-09-20 21:35:51 +0000 | [diff] [blame] | 88 | #endif // LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H |