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 | /** |
| 33 | * \brief Find a register that can be used in function prologue and epilogue |
| 34 | * |
| 35 | * Find a register that can be use as the scratch register in function |
| 36 | * prologue and epilogue to save various registers (Link Register, Base |
| 37 | * Pointer, etc.). Prefer R0, if it is available. If it is not available, |
| 38 | * then choose a different register. |
| 39 | * |
| 40 | * This method will return true if an available register was found (including |
| 41 | * R0). If no available registers are found, the method returns false and sets |
| 42 | * ScratchRegister to R0, as per the recommendation in the ABI. |
| 43 | * |
| 44 | * \param[in] MBB The machine basic block to find an available register for |
| 45 | * \param[in] UseAtEnd Specify whether the scratch register will be used at |
| 46 | * the end of the basic block (i.e., will the scratch |
| 47 | * register kill a register defined in the basic block) |
| 48 | * \param[out] ScratchRegister The scratch register to use |
| 49 | * \return true if a scratch register was found. false of a scratch register |
| 50 | * was not found and R0 is being used as the default. |
| 51 | */ |
| 52 | bool findScratchRegister(MachineBasicBlock *MBB, |
| 53 | bool UseAtEnd, |
| 54 | unsigned *ScratchRegister) const; |
| 55 | |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 56 | public: |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 57 | PPCFrameLowering(const PPCSubtarget &STI); |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 58 | |
Hal Finkel | bb420f1 | 2013-03-15 05:06:04 +0000 | [diff] [blame] | 59 | unsigned determineFrameLayout(MachineFunction &MF, |
| 60 | bool UpdateMF = true, |
| 61 | bool UseEstimate = false) const; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 62 | |
| 63 | /// emitProlog/emitEpilog - These methods insert prolog and epilog code into |
| 64 | /// the function. |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 65 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 66 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 67 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 68 | bool hasFP(const MachineFunction &MF) const override; |
Anton Korobeynikov | 3eb4fed | 2010-12-18 19:53:14 +0000 | [diff] [blame] | 69 | bool needsFP(const MachineFunction &MF) const; |
Hal Finkel | aa03c03 | 2013-03-21 19:03:19 +0000 | [diff] [blame] | 70 | void replaceFPWithRealFP(MachineFunction &MF) const; |
Anton Korobeynikov | 0eecf5d | 2010-11-18 21:19:35 +0000 | [diff] [blame] | 71 | |
Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 72 | void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, |
| 73 | RegScavenger *RS = nullptr) const override; |
Hal Finkel | 5a765fd | 2013-03-14 20:33:40 +0000 | [diff] [blame] | 74 | void processFunctionBeforeFrameFinalized(MachineFunction &MF, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 75 | RegScavenger *RS = nullptr) const override; |
Hal Finkel | bb420f1 | 2013-03-15 05:06:04 +0000 | [diff] [blame] | 76 | void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const; |
Anton Korobeynikov | 7283b8d | 2010-11-27 23:05:25 +0000 | [diff] [blame] | 77 | |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 78 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 79 | MachineBasicBlock::iterator MI, |
| 80 | const std::vector<CalleeSavedInfo> &CSI, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 81 | const TargetRegisterInfo *TRI) const override; |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 82 | |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 83 | void eliminateCallFramePseudoInstr(MachineFunction &MF, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 84 | MachineBasicBlock &MBB, |
| 85 | MachineBasicBlock::iterator I) const override; |
Eli Bendersky | 8da8716 | 2013-02-21 20:05:00 +0000 | [diff] [blame] | 86 | |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 87 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 88 | MachineBasicBlock::iterator MI, |
| 89 | const std::vector<CalleeSavedInfo> &CSI, |
| 90 | const TargetRegisterInfo *TRI) const override; |
Roman Divacky | c9e23d9 | 2012-09-12 14:47:47 +0000 | [diff] [blame] | 91 | |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 92 | /// targetHandlesStackFrameRounding - Returns true if the target is |
| 93 | /// responsible for rounding up the stack frame (probably at emitPrologue |
| 94 | /// time). |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 95 | bool targetHandlesStackFrameRounding() const override { return true; } |
Anton Korobeynikov | f7183ed | 2010-11-15 00:06:54 +0000 | [diff] [blame] | 96 | |
Jim Laskey | 527c12f | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 97 | /// getReturnSaveOffset - Return the previous frame offset to save the |
| 98 | /// return address. |
Eric Christopher | f71609b | 2015-02-13 00:39:27 +0000 | [diff] [blame] | 99 | unsigned getReturnSaveOffset() const { return ReturnSaveOffset; } |
Jim Laskey | 527c12f | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 100 | |
Ulrich Weigand | ad0cb91 | 2014-06-18 17:52:49 +0000 | [diff] [blame] | 101 | /// getTOCSaveOffset - Return the previous frame offset to save the |
| 102 | /// TOC register -- 64-bit SVR4 ABI only. |
Eric Christopher | 736d39e | 2015-02-13 00:39:36 +0000 | [diff] [blame] | 103 | unsigned getTOCSaveOffset() const { return TOCSaveOffset; } |
Ulrich Weigand | ad0cb91 | 2014-06-18 17:52:49 +0000 | [diff] [blame] | 104 | |
Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 105 | /// getFramePointerSaveOffset - Return the previous frame offset to save the |
| 106 | /// frame pointer. |
Eric Christopher | dc3a8a4 | 2015-02-13 00:39:38 +0000 | [diff] [blame] | 107 | unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; } |
Anton Korobeynikov | a5ab8f1 | 2010-11-15 00:06:05 +0000 | [diff] [blame] | 108 | |
Hal Finkel | a7c54e8 | 2013-07-17 00:45:52 +0000 | [diff] [blame] | 109 | /// getBasePointerSaveOffset - Return the previous frame offset to save the |
| 110 | /// base pointer. |
Eric Christopher | fcd3d87 | 2015-02-13 22:48:53 +0000 | [diff] [blame] | 111 | unsigned getBasePointerSaveOffset() const { return BasePointerSaveOffset; } |
Hal Finkel | a7c54e8 | 2013-07-17 00:45:52 +0000 | [diff] [blame] | 112 | |
Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 113 | /// getLinkageSize - Return the size of the PowerPC ABI linkage area. |
| 114 | /// |
Eric Christopher | a4ae213 | 2015-02-13 22:22:57 +0000 | [diff] [blame] | 115 | unsigned getLinkageSize() const { return LinkageSize; } |
Jim Laskey | 48850c1 | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 116 | |
Tilmann Scheller | 336e2bd | 2009-09-27 17:58:47 +0000 | [diff] [blame] | 117 | const SpillSlot * |
Eric Christopher | d104c31 | 2014-06-12 20:54:11 +0000 | [diff] [blame] | 118 | getCalleeSavedSpillSlots(unsigned &NumEntries) const override; |
Kit Barton | d3b904d | 2015-09-10 01:55:44 +0000 | [diff] [blame] | 119 | |
| 120 | bool enableShrinkWrapping(const MachineFunction &MF) const override; |
Kit Barton | 9c432ae | 2015-11-16 20:22:15 +0000 | [diff] [blame] | 121 | |
| 122 | /// Methods used by shrink wrapping to determine if MBB can be used for the |
| 123 | /// function prologue/epilogue. |
| 124 | bool canUseAsPrologue(const MachineBasicBlock &MBB) const override; |
| 125 | bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override; |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 126 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 127 | } // End llvm namespace |
Nate Begeman | 412602d | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 128 | |
| 129 | #endif |