blob: c4825882182d2c64b6c5c7fb5e7062121597a15e [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;
Misha Brukmanb4402432005-04-21 23:30:14 +000026
Nate Begeman412602d2004-08-14 22:16:36 +000027public:
Eric Christopherd104c312014-06-12 20:54:11 +000028 PPCFrameLowering(const PPCSubtarget &STI);
Nate Begeman412602d2004-08-14 22:16:36 +000029
Hal Finkelbb420f12013-03-15 05:06:04 +000030 unsigned determineFrameLayout(MachineFunction &MF,
31 bool UpdateMF = true,
32 bool UseEstimate = false) const;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000033
34 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
35 /// the function.
Craig Topper0d3fa922014-04-29 07:57:37 +000036 void emitPrologue(MachineFunction &MF) const override;
37 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000038
Craig Topper0d3fa922014-04-29 07:57:37 +000039 bool hasFP(const MachineFunction &MF) const override;
Anton Korobeynikov3eb4fed2010-12-18 19:53:14 +000040 bool needsFP(const MachineFunction &MF) const;
Hal Finkelaa03c032013-03-21 19:03:19 +000041 void replaceFPWithRealFP(MachineFunction &MF) const;
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +000042
Anton Korobeynikov7283b8d2010-11-27 23:05:25 +000043 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000044 RegScavenger *RS = nullptr) const override;
Hal Finkel5a765fd2013-03-14 20:33:40 +000045 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000046 RegScavenger *RS = nullptr) const override;
Hal Finkelbb420f12013-03-15 05:06:04 +000047 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
Anton Korobeynikov7283b8d2010-11-27 23:05:25 +000048
Roman Divackyc9e23d92012-09-12 14:47:47 +000049 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator MI,
51 const std::vector<CalleeSavedInfo> &CSI,
Craig Topper0d3fa922014-04-29 07:57:37 +000052 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +000053
Eli Bendersky8da87162013-02-21 20:05:00 +000054 void eliminateCallFramePseudoInstr(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000055 MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator I) const override;
Eli Bendersky8da87162013-02-21 20:05:00 +000057
Roman Divackyc9e23d92012-09-12 14:47:47 +000058 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
Craig Topper0d3fa922014-04-29 07:57:37 +000059 MachineBasicBlock::iterator MI,
60 const std::vector<CalleeSavedInfo> &CSI,
61 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +000062
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000063 /// targetHandlesStackFrameRounding - Returns true if the target is
64 /// responsible for rounding up the stack frame (probably at emitPrologue
65 /// time).
Craig Topper0d3fa922014-04-29 07:57:37 +000066 bool targetHandlesStackFrameRounding() const override { return true; }
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000067
Jim Laskey527c12f2006-12-06 17:42:06 +000068 /// getReturnSaveOffset - Return the previous frame offset to save the
69 /// return address.
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000070 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller773f14c2009-07-03 06:47:08 +000071 if (isDarwinABI)
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000072 return isPPC64 ? 16 : 8;
Tilmann Scheller773f14c2009-07-03 06:47:08 +000073 // SVR4 ABI:
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000074 return isPPC64 ? 16 : 4;
Nate Begeman412602d2004-08-14 22:16:36 +000075 }
Jim Laskey527c12f2006-12-06 17:42:06 +000076
Ulrich Weigandad0cb912014-06-18 17:52:49 +000077 /// getTOCSaveOffset - Return the previous frame offset to save the
78 /// TOC register -- 64-bit SVR4 ABI only.
Ulrich Weigand8658f172014-07-20 23:43:15 +000079 static unsigned getTOCSaveOffset(bool isELFv2ABI) {
80 return isELFv2ABI ? 24 : 40;
Ulrich Weigandad0cb912014-06-18 17:52:49 +000081 }
82
Jim Laskey48850c12006-11-16 22:43:37 +000083 /// getFramePointerSaveOffset - Return the previous frame offset to save the
84 /// frame pointer.
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000085 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller773f14c2009-07-03 06:47:08 +000086 // For the Darwin ABI:
Dale Johannesen5ece8f02009-11-24 22:59:02 +000087 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
88 // for saving the frame pointer (if needed.) While the published ABI has
89 // not used this slot since at least MacOSX 10.2, there is older code
90 // around that does use it, and that needs to continue to work.
Tilmann Scheller773f14c2009-07-03 06:47:08 +000091 if (isDarwinABI)
Dale Johannesen5ece8f02009-11-24 22:59:02 +000092 return isPPC64 ? -8U : -4U;
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +000093
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000094 // SVR4 ABI: First slot in the general register save area.
Tilmann Scheller5b2df8d2009-12-18 13:00:34 +000095 return isPPC64 ? -8U : -4U;
Jim Laskey48850c12006-11-16 22:43:37 +000096 }
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +000097
Hal Finkela7c54e82013-07-17 00:45:52 +000098 /// getBasePointerSaveOffset - Return the previous frame offset to save the
99 /// base pointer.
Hal Finkel3ee2af72014-07-18 23:29:49 +0000100 static unsigned getBasePointerSaveOffset(bool isPPC64,
101 bool isDarwinABI,
102 bool isPIC) {
Hal Finkela7c54e82013-07-17 00:45:52 +0000103 if (isDarwinABI)
104 return isPPC64 ? -16U : -8U;
105
106 // SVR4 ABI: First slot in the general register save area.
Hal Finkel3ee2af72014-07-18 23:29:49 +0000107 return isPPC64 ? -16U : isPIC ? -12U : -8U;
Hal Finkela7c54e82013-07-17 00:45:52 +0000108 }
109
Jim Laskey48850c12006-11-16 22:43:37 +0000110 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
111 ///
Ulrich Weigand8658f172014-07-20 23:43:15 +0000112 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
113 bool isELFv2ABI) {
Tilmann Schellerd1aaa322009-08-15 11:54:46 +0000114 if (isDarwinABI || isPPC64)
Ulrich Weigand8658f172014-07-20 23:43:15 +0000115 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +0000116
Tilmann Scheller773f14c2009-07-03 06:47:08 +0000117 // SVR4 ABI:
Nicolas Geoffrayb3e99a12007-04-03 12:35:28 +0000118 return 8;
Jim Laskey48850c12006-11-16 22:43:37 +0000119 }
120
Tilmann Scheller336e2bd2009-09-27 17:58:47 +0000121 const SpillSlot *
Eric Christopherd104c312014-06-12 20:54:11 +0000122 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
Nate Begeman412602d2004-08-14 22:16:36 +0000123};
Nate Begeman412602d2004-08-14 22:16:36 +0000124} // End llvm namespace
125
126#endif