blob: aa7499d49ad3eee61bfa55f38e7e953b49dd0f48 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Misha Brukmanb4402432005-04-21 23:30:14 +00006//
Nate Begeman412602d2004-08-14 22:16:36 +00007//===----------------------------------------------------------------------===//
8//
9//
Nate Begeman6cca84e2005-10-16 05:39:50 +000010//===----------------------------------------------------------------------===//
Nate Begeman412602d2004-08-14 22:16:36 +000011
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000012#ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
13#define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
Nate Begeman412602d2004-08-14 22:16:36 +000014
Chris Lattnerbfca1ab2005-10-14 23:51:18 +000015#include "PPC.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000016#include "llvm/ADT/STLExtras.h"
David Blaikie1be62f02017-11-03 22:32:11 +000017#include "llvm/CodeGen/TargetFrameLowering.h"
Nate Begeman412602d2004-08-14 22:16:36 +000018#include "llvm/Target/TargetMachine.h"
Nate Begeman412602d2004-08-14 22:16:36 +000019
20namespace llvm {
Eric Christopherd104c312014-06-12 20:54:11 +000021class PPCSubtarget;
Nate Begeman412602d2004-08-14 22:16:36 +000022
Anton Korobeynikov2f931282011-01-10 12:39:04 +000023class PPCFrameLowering: public TargetFrameLowering {
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000024 const PPCSubtarget &Subtarget;
Eric Christopherf71609b2015-02-13 00:39:27 +000025 const unsigned ReturnSaveOffset;
Eric Christopher736d39e2015-02-13 00:39:36 +000026 const unsigned TOCSaveOffset;
Eric Christopherdc3a8a42015-02-13 00:39:38 +000027 const unsigned FramePointerSaveOffset;
Eric Christophera4ae2132015-02-13 22:22:57 +000028 const unsigned LinkageSize;
Eric Christopherfcd3d872015-02-13 22:48:53 +000029 const unsigned BasePointerSaveOffset;
Misha Brukmanb4402432005-04-21 23:30:14 +000030
Kit Barton9c432ae2015-11-16 20:22:15 +000031 /**
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000032 * Find register[s] that can be used in function prologue and epilogue
Kit Barton9c432ae2015-11-16 20:22:15 +000033 *
Nemanja Ivanovicae22101c2016-02-20 18:16:25 +000034 * Find register[s] that can be use as scratch register[s] in function
Kit Barton9c432ae2015-11-16 20:22:15 +000035 * prologue and epilogue to save various registers (Link Register, Base
Nemanja Ivanovicae22101c2016-02-20 18:16:25 +000036 * Pointer, etc.). Prefer R0/R12, if available. Otherwise choose whatever
37 * register[s] are available.
Kit Barton9c432ae2015-11-16 20:22:15 +000038 *
Nemanja Ivanovicae22101c2016-02-20 18:16:25 +000039 * This method will return true if it is able to find enough unique scratch
40 * registers (1 or 2 depending on the requirement). If it is unable to find
41 * enough available registers in the block, it will return false and set
42 * any passed output parameter that corresponds to a required unique register
43 * to PPC::NoRegister.
Kit Barton9c432ae2015-11-16 20:22:15 +000044 *
45 * \param[in] MBB The machine basic block to find an available register for
46 * \param[in] UseAtEnd Specify whether the scratch register will be used at
47 * the end of the basic block (i.e., will the scratch
48 * register kill a register defined in the basic block)
Nemanja Ivanovicae22101c2016-02-20 18:16:25 +000049 * \param[in] TwoUniqueRegsRequired Specify whether this basic block will
50 * require two unique scratch registers.
51 * \param[out] SR1 The scratch register to use
52 * \param[out] SR2 The second scratch register. If this pointer is not null
53 * the function will attempt to set it to an available
54 * register regardless of whether there is a hard requirement
55 * for two unique scratch registers.
56 * \return true if the required number of registers was found.
57 * false if the required number of scratch register weren't available.
58 * If either output parameter refers to a required scratch register
59 * that isn't available, it will be set to an invalid value.
Kit Barton9c432ae2015-11-16 20:22:15 +000060 */
61 bool findScratchRegister(MachineBasicBlock *MBB,
62 bool UseAtEnd,
Nemanja Ivanovicae22101c2016-02-20 18:16:25 +000063 bool TwoUniqueRegsRequired = false,
64 unsigned *SR1 = nullptr,
65 unsigned *SR2 = nullptr) const;
66 bool twoUniqueScratchRegsRequired(MachineBasicBlock *MBB) const;
Kit Barton9c432ae2015-11-16 20:22:15 +000067
Chuang-Yu Chengf8b592f2016-04-01 06:44:32 +000068 /**
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000069 * Create branch instruction for PPC::TCRETURN* (tail call return)
Chuang-Yu Chengf8b592f2016-04-01 06:44:32 +000070 *
71 * \param[in] MBB that is terminated by PPC::TCRETURN*
72 */
73 void createTailCallBranchInstr(MachineBasicBlock &MBB) const;
74
Nate Begeman412602d2004-08-14 22:16:36 +000075public:
Eric Christopherd104c312014-06-12 20:54:11 +000076 PPCFrameLowering(const PPCSubtarget &STI);
Nate Begeman412602d2004-08-14 22:16:36 +000077
Hal Finkelbb420f12013-03-15 05:06:04 +000078 unsigned determineFrameLayout(MachineFunction &MF,
79 bool UpdateMF = true,
80 bool UseEstimate = false) const;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000081
82 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
83 /// the function.
Quentin Colombet61b305e2015-05-05 17:38:16 +000084 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Craig Topper0d3fa922014-04-29 07:57:37 +000085 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000086
Craig Topper0d3fa922014-04-29 07:57:37 +000087 bool hasFP(const MachineFunction &MF) const override;
Anton Korobeynikov3eb4fed2010-12-18 19:53:14 +000088 bool needsFP(const MachineFunction &MF) const;
Hal Finkelaa03c032013-03-21 19:03:19 +000089 void replaceFPWithRealFP(MachineFunction &MF) const;
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +000090
Matthias Braun02564862015-07-14 17:17:13 +000091 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
92 RegScavenger *RS = nullptr) const override;
Hal Finkel5a765fd2013-03-14 20:33:40 +000093 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000094 RegScavenger *RS = nullptr) const override;
Hal Finkelbb420f12013-03-15 05:06:04 +000095 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
Anton Korobeynikov7283b8d2010-11-27 23:05:25 +000096
Roman Divackyc9e23d92012-09-12 14:47:47 +000097 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
98 MachineBasicBlock::iterator MI,
99 const std::vector<CalleeSavedInfo> &CSI,
Craig Topper0d3fa922014-04-29 07:57:37 +0000100 const TargetRegisterInfo *TRI) const override;
Zaara Syeda5c179bf2018-11-09 16:36:24 +0000101 /// This function will assign callee saved gprs to volatile vector registers
102 /// for prologue spills when applicable. It returns false if there are any
103 /// registers which were not spilled to volatile vector registers.
104 bool
105 assignCalleeSavedSpillSlots(MachineFunction &MF,
106 const TargetRegisterInfo *TRI,
107 std::vector<CalleeSavedInfo> &CSI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +0000108
Hans Wennborge1a2e902016-03-31 18:33:38 +0000109 MachineBasicBlock::iterator
110 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
111 MachineBasicBlock::iterator I) const override;
Eli Bendersky8da87162013-02-21 20:05:00 +0000112
Roman Divackyc9e23d92012-09-12 14:47:47 +0000113 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
Craig Topper0d3fa922014-04-29 07:57:37 +0000114 MachineBasicBlock::iterator MI,
Krzysztof Parzyszekbea30c62017-08-10 16:17:32 +0000115 std::vector<CalleeSavedInfo> &CSI,
Craig Topper0d3fa922014-04-29 07:57:37 +0000116 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +0000117
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +0000118 /// targetHandlesStackFrameRounding - Returns true if the target is
119 /// responsible for rounding up the stack frame (probably at emitPrologue
120 /// time).
Craig Topper0d3fa922014-04-29 07:57:37 +0000121 bool targetHandlesStackFrameRounding() const override { return true; }
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +0000122
Jim Laskey527c12f2006-12-06 17:42:06 +0000123 /// getReturnSaveOffset - Return the previous frame offset to save the
124 /// return address.
Eric Christopherf71609b2015-02-13 00:39:27 +0000125 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
Jim Laskey527c12f2006-12-06 17:42:06 +0000126
Ulrich Weigandad0cb912014-06-18 17:52:49 +0000127 /// getTOCSaveOffset - Return the previous frame offset to save the
128 /// TOC register -- 64-bit SVR4 ABI only.
Eric Christopher736d39e2015-02-13 00:39:36 +0000129 unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
Ulrich Weigandad0cb912014-06-18 17:52:49 +0000130
Jim Laskey48850c12006-11-16 22:43:37 +0000131 /// getFramePointerSaveOffset - Return the previous frame offset to save the
132 /// frame pointer.
Eric Christopherdc3a8a42015-02-13 00:39:38 +0000133 unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; }
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +0000134
Hal Finkela7c54e82013-07-17 00:45:52 +0000135 /// getBasePointerSaveOffset - Return the previous frame offset to save the
136 /// base pointer.
Eric Christopherfcd3d872015-02-13 22:48:53 +0000137 unsigned getBasePointerSaveOffset() const { return BasePointerSaveOffset; }
Hal Finkela7c54e82013-07-17 00:45:52 +0000138
Jim Laskey48850c12006-11-16 22:43:37 +0000139 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
140 ///
Eric Christophera4ae2132015-02-13 22:22:57 +0000141 unsigned getLinkageSize() const { return LinkageSize; }
Jim Laskey48850c12006-11-16 22:43:37 +0000142
Tilmann Scheller336e2bd2009-09-27 17:58:47 +0000143 const SpillSlot *
Eric Christopherd104c312014-06-12 20:54:11 +0000144 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
Kit Bartond3b904d2015-09-10 01:55:44 +0000145
146 bool enableShrinkWrapping(const MachineFunction &MF) const override;
Kit Barton9c432ae2015-11-16 20:22:15 +0000147
148 /// Methods used by shrink wrapping to determine if MBB can be used for the
149 /// function prologue/epilogue.
150 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
151 bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
Nate Begeman412602d2004-08-14 22:16:36 +0000152};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000153} // End llvm namespace
Nate Begeman412602d2004-08-14 22:16:36 +0000154
155#endif