116c29b5f285f375be53dabaa73e3e91107485fe4Anton Korobeynikov//===-- Thumb1FrameLowering.h - Thumb1-specific frame info stuff --*- C++ -*-=// 233464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// 333464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// The LLVM Compiler Infrastructure 433464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// 533464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// This file is distributed under the University of Illinois Open Source 633464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// License. See LICENSE.TXT for details. 733464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// 833464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov//===----------------------------------------------------------------------===// 933464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// 1033464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// 1133464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov// 1233464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov//===----------------------------------------------------------------------===// 1333464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 1437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#ifndef LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H 1537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#define LLVM_LIB_TARGET_ARM_THUMB1FRAMELOWERING_H 1633464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 1716c29b5f285f375be53dabaa73e3e91107485fe4Anton Korobeynikov#include "ARMFrameLowering.h" 1833464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov#include "Thumb1InstrInfo.h" 194c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar#include "ThumbRegisterInfo.h" 2016c29b5f285f375be53dabaa73e3e91107485fe4Anton Korobeynikov#include "llvm/Target/TargetFrameLowering.h" 2133464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 2233464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikovnamespace llvm { 2333464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 2416c29b5f285f375be53dabaa73e3e91107485fe4Anton Korobeynikovclass Thumb1FrameLowering : public ARMFrameLowering { 2533464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikovpublic: 26c6a4f5e819217e1e12c458aed8e7b122e23a3a58Stephen Hines explicit Thumb1FrameLowering(const ARMSubtarget &sti); 2733464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 2833464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov /// emitProlog/emitEpilog - These methods insert prolog and epilog code into 2933464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov /// the function. 306948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 32d0c38176690e9602a93a20a43f1bd084564a8116Anton Korobeynikov 33cd775ceff0b25a0b026f643a7990c2924bd310a3Anton Korobeynikov bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 34cd775ceff0b25a0b026f643a7990c2924bd310a3Anton Korobeynikov MachineBasicBlock::iterator MI, 35cd775ceff0b25a0b026f643a7990c2924bd310a3Anton Korobeynikov const std::vector<CalleeSavedInfo> &CSI, 3636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const TargetRegisterInfo *TRI) const override; 37cd775ceff0b25a0b026f643a7990c2924bd310a3Anton Korobeynikov bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 3836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachineBasicBlock::iterator MI, 3936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const std::vector<CalleeSavedInfo> &CSI, 4036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const TargetRegisterInfo *TRI) const override; 41cd775ceff0b25a0b026f643a7990c2924bd310a3Anton Korobeynikov 4236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool hasReservedCallFrame(const MachineFunction &MF) const override; 43700ed80d3da5e98e05ceb90e9bfb66058581a6dbEli Bendersky 44de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar MachineBasicBlock::iterator 4536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines eliminateCallFramePseudoInstr(MachineFunction &MF, 4636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachineBasicBlock &MBB, 4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MachineBasicBlock::iterator MI) const override; 48f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 49f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// Check whether or not the given \p MBB can be used as a epilogue 50f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// for the target. 51f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// The epilogue will be inserted before the first terminator of that block. 52f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// This method is used by the shrink-wrapping pass to decide if 53f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// \p MBB will be correctly handled by the target. 54f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override; 55f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 56de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// Disable shrink wrap as tBfar/BL will be used to adjust for long jumps. 57de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar bool enableShrinkWrapping(const MachineFunction &MF) const override { 58de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar return false; 59de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar } 60de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar 61f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainarprivate: 62f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// Check if the frame lowering of \p MF needs a special fixup 63f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// code sequence for the epilogue. 64f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// Unlike T2 and ARM mode, the T1 pop instruction cannot restore 65f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// to LR, and we can't pop the value directly to the PC when 66f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// we need to update the SP after popping the value. So instead 67f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// we have to emit: 68f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// POP {r3} 69f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// ADD sp, #offset 70f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// BX r3 71f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// If this would clobber a return value, then generate this sequence instead: 72f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// MOV ip, r3 73f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// POP {r3} 74f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// ADD sp, #offset 75f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// MOV lr, r3 76f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// MOV r3, ip 77f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// BX lr 78f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar bool needPopSpecialFixUp(const MachineFunction &MF) const; 79f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 80f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// Emit the special fixup code sequence for the epilogue. 81f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// \see needPopSpecialFixUp for more details. 82f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// \p DoIt, tells this method whether or not to actually insert 83f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// the code sequence in \p MBB. I.e., when \p DoIt is false, 84f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// \p MBB is left untouched. 85f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// \returns For \p DoIt == true: True when the emission succeeded 86f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// false otherwise. For \p DoIt == false: True when the emission 87f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar /// would have been possible, false otherwise. 88f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar bool emitPopSpecialFixUp(MachineBasicBlock &MBB, bool DoIt) const; 8933464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov}; 9033464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 9133464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov} // End llvm namespace 9233464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov 9333464912237efaa0ed7060829e66b59055bdd48bAnton Korobeynikov#endif 94