blob: bbe1329a535213f70432fb7990224bc3f2be48d7 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
Misha Brukmanb4402432005-04-21 23:30:14 +00002//
Nate Begeman412602d2004-08-14 22:16:36 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb4402432005-04-21 23:30:14 +00007//
Nate Begeman412602d2004-08-14 22:16:36 +00008//===----------------------------------------------------------------------===//
9//
10//
Nate Begeman6cca84e2005-10-16 05:39:50 +000011//===----------------------------------------------------------------------===//
Nate Begeman412602d2004-08-14 22:16:36 +000012
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000013#ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
14#define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
Nate Begeman412602d2004-08-14 22:16:36 +000015
Chris Lattnerbfca1ab2005-10-14 23:51:18 +000016#include "PPC.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000017#include "llvm/ADT/STLExtras.h"
Anton Korobeynikov2f931282011-01-10 12:39:04 +000018#include "llvm/Target/TargetFrameLowering.h"
Nate Begeman412602d2004-08-14 22:16:36 +000019#include "llvm/Target/TargetMachine.h"
Nate Begeman412602d2004-08-14 22:16:36 +000020
21namespace llvm {
Eric Christopherd104c312014-06-12 20:54:11 +000022class PPCSubtarget;
Nate Begeman412602d2004-08-14 22:16:36 +000023
Anton Korobeynikov2f931282011-01-10 12:39:04 +000024class PPCFrameLowering: public TargetFrameLowering {
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000025 const PPCSubtarget &Subtarget;
Eric Christopherf71609b2015-02-13 00:39:27 +000026 const unsigned ReturnSaveOffset;
Eric Christopher736d39e2015-02-13 00:39:36 +000027 const unsigned TOCSaveOffset;
Eric Christopherdc3a8a42015-02-13 00:39:38 +000028 const unsigned FramePointerSaveOffset;
Eric Christophera4ae2132015-02-13 22:22:57 +000029 const unsigned LinkageSize;
Eric Christopherfcd3d872015-02-13 22:48:53 +000030 const unsigned BasePointerSaveOffset;
Misha Brukmanb4402432005-04-21 23:30:14 +000031
Kit Barton9c432ae2015-11-16 20:22:15 +000032 /**
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 Begeman412602d2004-08-14 22:16:36 +000056public:
Eric Christopherd104c312014-06-12 20:54:11 +000057 PPCFrameLowering(const PPCSubtarget &STI);
Nate Begeman412602d2004-08-14 22:16:36 +000058
Hal Finkelbb420f12013-03-15 05:06:04 +000059 unsigned determineFrameLayout(MachineFunction &MF,
60 bool UpdateMF = true,
61 bool UseEstimate = false) const;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000062
63 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
64 /// the function.
Quentin Colombet61b305e2015-05-05 17:38:16 +000065 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Craig Topper0d3fa922014-04-29 07:57:37 +000066 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000067
Craig Topper0d3fa922014-04-29 07:57:37 +000068 bool hasFP(const MachineFunction &MF) const override;
Anton Korobeynikov3eb4fed2010-12-18 19:53:14 +000069 bool needsFP(const MachineFunction &MF) const;
Hal Finkelaa03c032013-03-21 19:03:19 +000070 void replaceFPWithRealFP(MachineFunction &MF) const;
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +000071
Matthias Braun02564862015-07-14 17:17:13 +000072 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
73 RegScavenger *RS = nullptr) const override;
Hal Finkel5a765fd2013-03-14 20:33:40 +000074 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000075 RegScavenger *RS = nullptr) const override;
Hal Finkelbb420f12013-03-15 05:06:04 +000076 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
Anton Korobeynikov7283b8d2010-11-27 23:05:25 +000077
Roman Divackyc9e23d92012-09-12 14:47:47 +000078 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
79 MachineBasicBlock::iterator MI,
80 const std::vector<CalleeSavedInfo> &CSI,
Craig Topper0d3fa922014-04-29 07:57:37 +000081 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +000082
Eli Bendersky8da87162013-02-21 20:05:00 +000083 void eliminateCallFramePseudoInstr(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000084 MachineBasicBlock &MBB,
85 MachineBasicBlock::iterator I) const override;
Eli Bendersky8da87162013-02-21 20:05:00 +000086
Roman Divackyc9e23d92012-09-12 14:47:47 +000087 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
Craig Topper0d3fa922014-04-29 07:57:37 +000088 MachineBasicBlock::iterator MI,
89 const std::vector<CalleeSavedInfo> &CSI,
90 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +000091
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000092 /// targetHandlesStackFrameRounding - Returns true if the target is
93 /// responsible for rounding up the stack frame (probably at emitPrologue
94 /// time).
Craig Topper0d3fa922014-04-29 07:57:37 +000095 bool targetHandlesStackFrameRounding() const override { return true; }
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000096
Jim Laskey527c12f2006-12-06 17:42:06 +000097 /// getReturnSaveOffset - Return the previous frame offset to save the
98 /// return address.
Eric Christopherf71609b2015-02-13 00:39:27 +000099 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
Jim Laskey527c12f2006-12-06 17:42:06 +0000100
Ulrich Weigandad0cb912014-06-18 17:52:49 +0000101 /// getTOCSaveOffset - Return the previous frame offset to save the
102 /// TOC register -- 64-bit SVR4 ABI only.
Eric Christopher736d39e2015-02-13 00:39:36 +0000103 unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
Ulrich Weigandad0cb912014-06-18 17:52:49 +0000104
Jim Laskey48850c12006-11-16 22:43:37 +0000105 /// getFramePointerSaveOffset - Return the previous frame offset to save the
106 /// frame pointer.
Eric Christopherdc3a8a42015-02-13 00:39:38 +0000107 unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; }
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +0000108
Hal Finkela7c54e82013-07-17 00:45:52 +0000109 /// getBasePointerSaveOffset - Return the previous frame offset to save the
110 /// base pointer.
Eric Christopherfcd3d872015-02-13 22:48:53 +0000111 unsigned getBasePointerSaveOffset() const { return BasePointerSaveOffset; }
Hal Finkela7c54e82013-07-17 00:45:52 +0000112
Jim Laskey48850c12006-11-16 22:43:37 +0000113 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
114 ///
Eric Christophera4ae2132015-02-13 22:22:57 +0000115 unsigned getLinkageSize() const { return LinkageSize; }
Jim Laskey48850c12006-11-16 22:43:37 +0000116
Tilmann Scheller336e2bd2009-09-27 17:58:47 +0000117 const SpillSlot *
Eric Christopherd104c312014-06-12 20:54:11 +0000118 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
Kit Bartond3b904d2015-09-10 01:55:44 +0000119
120 bool enableShrinkWrapping(const MachineFunction &MF) const override;
Kit Barton9c432ae2015-11-16 20:22:15 +0000121
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 Begeman412602d2004-08-14 22:16:36 +0000126};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000127} // End llvm namespace
Nate Begeman412602d2004-08-14 22:16:36 +0000128
129#endif