blob: 61af48712b6cf64c9b49838cdd943c8c7b4bb554 [file] [log] [blame]
Eugene Zelenko076468c2017-09-20 21:35:51 +00001//===- Thumb1FrameLowering.h - Thumb1-specific frame info stuff ---*- C++ -*-=//
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Korobeynikovf7183ed2010-11-15 00:06:54 +00006//
7//===----------------------------------------------------------------------===//
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +00008
Benjamin Kramera7c40ef2014-08-13 16:26:38 +00009#ifndef LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H
10#define LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000011
Anton Korobeynikov2f931282011-01-10 12:39:04 +000012#include "ARMFrameLowering.h"
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000013
14namespace llvm {
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000015
Eugene Zelenko076468c2017-09-20 21:35:51 +000016class ARMSubtarget;
17class MachineFunction;
18
Anton Korobeynikov2f931282011-01-10 12:39:04 +000019class Thumb1FrameLowering : public ARMFrameLowering {
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000020public:
Eric Christopher45fb7b62014-06-26 19:29:59 +000021 explicit Thumb1FrameLowering(const ARMSubtarget &sti);
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000022
23 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
24 /// the function.
Quentin Colombet61b305e2015-05-05 17:38:16 +000025 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Craig Topper6bc27bf2014-03-10 02:09:33 +000026 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +000027
Anton Korobeynikovd08fbd12010-11-27 23:05:03 +000028 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
29 MachineBasicBlock::iterator MI,
30 const std::vector<CalleeSavedInfo> &CSI,
Craig Topper6bc27bf2014-03-10 02:09:33 +000031 const TargetRegisterInfo *TRI) const override;
Anton Korobeynikovd08fbd12010-11-27 23:05:03 +000032 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
Craig Topper6bc27bf2014-03-10 02:09:33 +000033 MachineBasicBlock::iterator MI,
Krzysztof Parzyszekbea30c62017-08-10 16:17:32 +000034 std::vector<CalleeSavedInfo> &CSI,
Craig Topper6bc27bf2014-03-10 02:09:33 +000035 const TargetRegisterInfo *TRI) const override;
Anton Korobeynikovd08fbd12010-11-27 23:05:03 +000036
Craig Topper6bc27bf2014-03-10 02:09:33 +000037 bool hasReservedCallFrame(const MachineFunction &MF) const override;
Eli Bendersky8da87162013-02-21 20:05:00 +000038
Hans Wennborge1a2e902016-03-31 18:33:38 +000039 MachineBasicBlock::iterator
Craig Topper6bc27bf2014-03-10 02:09:33 +000040 eliminateCallFramePseudoInstr(MachineFunction &MF,
41 MachineBasicBlock &MBB,
42 MachineBasicBlock::iterator MI) const override;
Quentin Colombet48b77202015-07-22 16:34:37 +000043
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 Zhao48c033e2016-01-08 18:37:43 +000051 /// 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 Colombet48b77202015-07-22 16:34:37 +000056private:
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 Korobeynikovf7183ed2010-11-15 00:06:54 +000084};
85
Eugene Zelenko076468c2017-09-20 21:35:51 +000086} // end namespace llvm
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000087
Eugene Zelenko076468c2017-09-20 21:35:51 +000088#endif // LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H