Jia Liu | b22310f | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===// |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
Nate Begeman | 6cca84e | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 11 | //===----------------------------------------------------------------------===// |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 12 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 13 | #ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H |
| 14 | #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 15 | |
Chris Lattner | bfca1ab | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 16 | #include "PPC.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetFrameLowering.h" |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachine.h" |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 22 | class PPCSubtarget; |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 23 | |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 24 | class PPCFrameLowering: public TargetFrameLowering { |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 25 | const PPCSubtarget &Subtarget; |
Eric Christopher | f71609b | 2015-02-13 00:39:27 +0000 | [diff] [blame] | 26 | const unsigned ReturnSaveOffset; |
Eric Christopher | 736d39e | 2015-02-13 00:39:36 +0000 | [diff] [blame] | 27 | const unsigned TOCSaveOffset; |
Eric Christopher | dc3a8a4 | 2015-02-13 00:39:38 +0000 | [diff] [blame] | 28 | const unsigned FramePointerSaveOffset; |
Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 29 | const unsigned LinkageSize; |
Eric Christopher | fcd3d87 | 2015-02-13 22:48:53 +0000 | [diff] [blame] | 30 | const unsigned BasePointerSaveOffset; |
Misha Brukman | b440243 | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 31 | |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 32 | /** |
Nemanja Ivanovic | ae22101c | 2016-02-20 18:16:25 +0000 | [diff] [blame] | 33 | * \brief Find register[s] that can be used in function prologue and epilogue |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 34 | * |
Nemanja Ivanovic | ae22101c | 2016-02-20 18:16:25 +0000 | [diff] [blame] | 35 | * Find register[s] that can be use as scratch register[s] in function |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 36 | * prologue and epilogue to save various registers (Link Register, Base |
Nemanja Ivanovic | ae22101c | 2016-02-20 18:16:25 +0000 | [diff] [blame] | 37 | * Pointer, etc.). Prefer R0/R12, if available. Otherwise choose whatever |
| 38 | * register[s] are available. |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 39 | * |
Nemanja Ivanovic | ae22101c | 2016-02-20 18:16:25 +0000 | [diff] [blame] | 40 | * This method will return true if it is able to find enough unique scratch |
| 41 | * registers (1 or 2 depending on the requirement). If it is unable to find |
| 42 | * enough available registers in the block, it will return false and set |
| 43 | * any passed output parameter that corresponds to a required unique register |
| 44 | * to PPC::NoRegister. |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 45 | * |
| 46 | * \param[in] MBB The machine basic block to find an available register for |
| 47 | * \param[in] UseAtEnd Specify whether the scratch register will be used at |
| 48 | * the end of the basic block (i.e., will the scratch |
| 49 | * register kill a register defined in the basic block) |
Nemanja Ivanovic | ae22101c | 2016-02-20 18:16:25 +0000 | [diff] [blame] | 50 | * \param[in] TwoUniqueRegsRequired Specify whether this basic block will |
| 51 | * require two unique scratch registers. |
| 52 | * \param[out] SR1 The scratch register to use |
| 53 | * \param[out] SR2 The second scratch register. If this pointer is not null |
| 54 | * the function will attempt to set it to an available |
| 55 | * register regardless of whether there is a hard requirement |
| 56 | * for two unique scratch registers. |
| 57 | * \return true if the required number of registers was found. |
| 58 | * false if the required number of scratch register weren't available. |
| 59 | * If either output parameter refers to a required scratch register |
| 60 | * that isn't available, it will be set to an invalid value. |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 61 | */ |
| 62 | bool findScratchRegister(MachineBasicBlock *MBB, |
| 63 | bool UseAtEnd, |
Nemanja Ivanovic | ae22101c | 2016-02-20 18:16:25 +0000 | [diff] [blame] | 64 | bool TwoUniqueRegsRequired = false, |
| 65 | unsigned *SR1 = nullptr, |
| 66 | unsigned *SR2 = nullptr) const; |
| 67 | bool twoUniqueScratchRegsRequired(MachineBasicBlock *MBB) const; |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 68 | |
Chuang-Yu Cheng | f8b592f | 2016-04-01 06:44:32 +0000 | [diff] [blame] | 69 | /** |
| 70 | * \brief Create branch instruction for PPC::TCRETURN* (tail call return) |
| 71 | * |
| 72 | * \param[in] MBB that is terminated by PPC::TCRETURN* |
| 73 | */ |
| 74 | void createTailCallBranchInstr(MachineBasicBlock &MBB) const; |
| 75 | |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 76 | public: |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 77 | PPCFrameLowering(const PPCSubtarget &STI); |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 78 | |
Hal Finkel | bb420f1 | 2013-03-15 05:06:04 +0000 | [diff] [blame] | 79 | unsigned determineFrameLayout(MachineFunction &MF, |
| 80 | bool UpdateMF = true, |
| 81 | bool UseEstimate = false) const; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 82 | |
| 83 | /// emitProlog/emitEpilog - These methods insert prolog and epilog code into |
| 84 | /// the function. |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 85 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 86 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 87 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 88 | bool hasFP(const MachineFunction &MF) const override; |
Anton Korobeynikov | 3eb4fed | 2010-12-18 19:53:14 +0000 | [diff] [blame] | 89 | bool needsFP(const MachineFunction &MF) const; |
Hal Finkel | aa03c03 | 2013-03-21 19:03:19 +0000 | [diff] [blame] | 90 | void replaceFPWithRealFP(MachineFunction &MF) const; |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 91 | |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 92 | void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, |
| 93 | RegScavenger *RS = nullptr) const override; |
Hal Finkel | 5a765fd | 2013-03-14 20:33:40 +0000 | [diff] [blame] | 94 | void processFunctionBeforeFrameFinalized(MachineFunction &MF, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 95 | RegScavenger *RS = nullptr) const override; |
Hal Finkel | bb420f1 | 2013-03-15 05:06:04 +0000 | [diff] [blame] | 96 | void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const; |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 97 | |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 98 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 99 | MachineBasicBlock::iterator MI, |
| 100 | const std::vector<CalleeSavedInfo> &CSI, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 101 | const TargetRegisterInfo *TRI) const override; |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 102 | |
Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 103 | MachineBasicBlock::iterator |
| 104 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, |
| 105 | MachineBasicBlock::iterator I) const override; |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 106 | |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 107 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 108 | MachineBasicBlock::iterator MI, |
| 109 | const std::vector<CalleeSavedInfo> &CSI, |
| 110 | const TargetRegisterInfo *TRI) const override; |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 111 | |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 112 | /// targetHandlesStackFrameRounding - Returns true if the target is |
| 113 | /// responsible for rounding up the stack frame (probably at emitPrologue |
| 114 | /// time). |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 115 | bool targetHandlesStackFrameRounding() const override { return true; } |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 116 | |
Jim Laskey | 527c12f | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 117 | /// getReturnSaveOffset - Return the previous frame offset to save the |
| 118 | /// return address. |
Eric Christopher | f71609b | 2015-02-13 00:39:27 +0000 | [diff] [blame] | 119 | unsigned getReturnSaveOffset() const { return ReturnSaveOffset; } |
Jim Laskey | 527c12f | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 120 | |
Ulrich Weigand | ad0cb91 | 2014-06-18 17:52:49 +0000 | [diff] [blame] | 121 | /// getTOCSaveOffset - Return the previous frame offset to save the |
| 122 | /// TOC register -- 64-bit SVR4 ABI only. |
Eric Christopher | 736d39e | 2015-02-13 00:39:36 +0000 | [diff] [blame] | 123 | unsigned getTOCSaveOffset() const { return TOCSaveOffset; } |
Ulrich Weigand | ad0cb91 | 2014-06-18 17:52:49 +0000 | [diff] [blame] | 124 | |
Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 125 | /// getFramePointerSaveOffset - Return the previous frame offset to save the |
| 126 | /// frame pointer. |
Eric Christopher | dc3a8a4 | 2015-02-13 00:39:38 +0000 | [diff] [blame] | 127 | unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; } |
Anton Korobeynikov | a5ab8f1 | 2010-11-15 00:06:05 +0000 | [diff] [blame] | 128 | |
Hal Finkel | a7c54e8 | 2013-07-17 00:45:52 +0000 | [diff] [blame] | 129 | /// getBasePointerSaveOffset - Return the previous frame offset to save the |
| 130 | /// base pointer. |
Eric Christopher | fcd3d87 | 2015-02-13 22:48:53 +0000 | [diff] [blame] | 131 | unsigned getBasePointerSaveOffset() const { return BasePointerSaveOffset; } |
Hal Finkel | a7c54e8 | 2013-07-17 00:45:52 +0000 | [diff] [blame] | 132 | |
Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 133 | /// getLinkageSize - Return the size of the PowerPC ABI linkage area. |
| 134 | /// |
Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 135 | unsigned getLinkageSize() const { return LinkageSize; } |
Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 136 | |
Tilmann Scheller | 336e2bd | 2009-09-27 17:58:47 +0000 | [diff] [blame] | 137 | const SpillSlot * |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 138 | getCalleeSavedSpillSlots(unsigned &NumEntries) const override; |
Kit Barton | d3b904d | 2015-09-10 01:55:44 +0000 | [diff] [blame] | 139 | |
| 140 | bool enableShrinkWrapping(const MachineFunction &MF) const override; |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 141 | |
| 142 | /// Methods used by shrink wrapping to determine if MBB can be used for the |
| 143 | /// function prologue/epilogue. |
| 144 | bool canUseAsPrologue(const MachineBasicBlock &MBB) const override; |
| 145 | bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override; |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 146 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 147 | } // End llvm namespace |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 148 | |
| 149 | #endif |