10b57cec5SDimitry Andric //===- Thumb1FrameLowering.h - Thumb1-specific frame info stuff ---*- C++ -*-=// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H 100b57cec5SDimitry Andric #define LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "ARMFrameLowering.h" 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric namespace llvm { 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric class ARMSubtarget; 170b57cec5SDimitry Andric class MachineFunction; 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric class Thumb1FrameLowering : public ARMFrameLowering { 200b57cec5SDimitry Andric public: 210b57cec5SDimitry Andric explicit Thumb1FrameLowering(const ARMSubtarget &sti); 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric /// emitProlog/emitEpilog - These methods insert prolog and epilog code into 240b57cec5SDimitry Andric /// the function. 250b57cec5SDimitry Andric void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 260b57cec5SDimitry Andric void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 290b57cec5SDimitry Andric MachineBasicBlock::iterator MI, 30*5ffd83dbSDimitry Andric ArrayRef<CalleeSavedInfo> CSI, 310b57cec5SDimitry Andric const TargetRegisterInfo *TRI) const override; 32*5ffd83dbSDimitry Andric bool 33*5ffd83dbSDimitry Andric restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 340b57cec5SDimitry Andric MachineBasicBlock::iterator MI, 35*5ffd83dbSDimitry Andric MutableArrayRef<CalleeSavedInfo> CSI, 360b57cec5SDimitry Andric const TargetRegisterInfo *TRI) const override; 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric bool hasReservedCallFrame(const MachineFunction &MF) const override; 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric MachineBasicBlock::iterator 410b57cec5SDimitry Andric eliminateCallFramePseudoInstr(MachineFunction &MF, 420b57cec5SDimitry Andric MachineBasicBlock &MBB, 430b57cec5SDimitry Andric MachineBasicBlock::iterator MI) const override; 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric /// Check whether or not the given \p MBB can be used as a epilogue 460b57cec5SDimitry Andric /// for the target. 470b57cec5SDimitry Andric /// The epilogue will be inserted before the first terminator of that block. 480b57cec5SDimitry Andric /// This method is used by the shrink-wrapping pass to decide if 490b57cec5SDimitry Andric /// \p MBB will be correctly handled by the target. 500b57cec5SDimitry Andric bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric /// Disable shrink wrap as tBfar/BL will be used to adjust for long jumps. enableShrinkWrapping(const MachineFunction & MF)530b57cec5SDimitry Andric bool enableShrinkWrapping(const MachineFunction &MF) const override { 540b57cec5SDimitry Andric return false; 550b57cec5SDimitry Andric } 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric private: 580b57cec5SDimitry Andric /// Check if the frame lowering of \p MF needs a special fixup 590b57cec5SDimitry Andric /// code sequence for the epilogue. 600b57cec5SDimitry Andric /// Unlike T2 and ARM mode, the T1 pop instruction cannot restore 610b57cec5SDimitry Andric /// to LR, and we can't pop the value directly to the PC when 620b57cec5SDimitry Andric /// we need to update the SP after popping the value. So instead 630b57cec5SDimitry Andric /// we have to emit: 640b57cec5SDimitry Andric /// POP {r3} 650b57cec5SDimitry Andric /// ADD sp, #offset 660b57cec5SDimitry Andric /// BX r3 670b57cec5SDimitry Andric /// If this would clobber a return value, then generate this sequence instead: 680b57cec5SDimitry Andric /// MOV ip, r3 690b57cec5SDimitry Andric /// POP {r3} 700b57cec5SDimitry Andric /// ADD sp, #offset 710b57cec5SDimitry Andric /// MOV lr, r3 720b57cec5SDimitry Andric /// MOV r3, ip 730b57cec5SDimitry Andric /// BX lr 740b57cec5SDimitry Andric bool needPopSpecialFixUp(const MachineFunction &MF) const; 750b57cec5SDimitry Andric 760b57cec5SDimitry Andric /// Emit the special fixup code sequence for the epilogue. 770b57cec5SDimitry Andric /// \see needPopSpecialFixUp for more details. 780b57cec5SDimitry Andric /// \p DoIt, tells this method whether or not to actually insert 790b57cec5SDimitry Andric /// the code sequence in \p MBB. I.e., when \p DoIt is false, 800b57cec5SDimitry Andric /// \p MBB is left untouched. 810b57cec5SDimitry Andric /// \returns For \p DoIt == true: True when the emission succeeded 820b57cec5SDimitry Andric /// false otherwise. For \p DoIt == false: True when the emission 830b57cec5SDimitry Andric /// would have been possible, false otherwise. 840b57cec5SDimitry Andric bool emitPopSpecialFixUp(MachineBasicBlock &MBB, bool DoIt) const; 850b57cec5SDimitry Andric }; 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric } // end namespace llvm 880b57cec5SDimitry Andric 890b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H 90