blob: c67541699e6636d781006728f4fb2017e218ff56 [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;
Misha Brukmanb4402432005-04-21 23:30:14 +000028
Nate Begeman412602d2004-08-14 22:16:36 +000029public:
Eric Christopherd104c312014-06-12 20:54:11 +000030 PPCFrameLowering(const PPCSubtarget &STI);
Nate Begeman412602d2004-08-14 22:16:36 +000031
Hal Finkelbb420f12013-03-15 05:06:04 +000032 unsigned determineFrameLayout(MachineFunction &MF,
33 bool UpdateMF = true,
34 bool UseEstimate = false) const;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000035
36 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
37 /// the function.
Craig Topper0d3fa922014-04-29 07:57:37 +000038 void emitPrologue(MachineFunction &MF) const override;
39 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000040
Craig Topper0d3fa922014-04-29 07:57:37 +000041 bool hasFP(const MachineFunction &MF) const override;
Anton Korobeynikov3eb4fed2010-12-18 19:53:14 +000042 bool needsFP(const MachineFunction &MF) const;
Hal Finkelaa03c032013-03-21 19:03:19 +000043 void replaceFPWithRealFP(MachineFunction &MF) const;
Anton Korobeynikov0eecf5d2010-11-18 21:19:35 +000044
Anton Korobeynikov7283b8d2010-11-27 23:05:25 +000045 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000046 RegScavenger *RS = nullptr) const override;
Hal Finkel5a765fd2013-03-14 20:33:40 +000047 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000048 RegScavenger *RS = nullptr) const override;
Hal Finkelbb420f12013-03-15 05:06:04 +000049 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
Anton Korobeynikov7283b8d2010-11-27 23:05:25 +000050
Roman Divackyc9e23d92012-09-12 14:47:47 +000051 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
52 MachineBasicBlock::iterator MI,
53 const std::vector<CalleeSavedInfo> &CSI,
Craig Topper0d3fa922014-04-29 07:57:37 +000054 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +000055
Eli Bendersky8da87162013-02-21 20:05:00 +000056 void eliminateCallFramePseudoInstr(MachineFunction &MF,
Craig Topper0d3fa922014-04-29 07:57:37 +000057 MachineBasicBlock &MBB,
58 MachineBasicBlock::iterator I) const override;
Eli Bendersky8da87162013-02-21 20:05:00 +000059
Roman Divackyc9e23d92012-09-12 14:47:47 +000060 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
Craig Topper0d3fa922014-04-29 07:57:37 +000061 MachineBasicBlock::iterator MI,
62 const std::vector<CalleeSavedInfo> &CSI,
63 const TargetRegisterInfo *TRI) const override;
Roman Divackyc9e23d92012-09-12 14:47:47 +000064
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000065 /// targetHandlesStackFrameRounding - Returns true if the target is
66 /// responsible for rounding up the stack frame (probably at emitPrologue
67 /// time).
Craig Topper0d3fa922014-04-29 07:57:37 +000068 bool targetHandlesStackFrameRounding() const override { return true; }
Anton Korobeynikovf7183ed2010-11-15 00:06:54 +000069
Jim Laskey527c12f2006-12-06 17:42:06 +000070 /// getReturnSaveOffset - Return the previous frame offset to save the
71 /// return address.
Eric Christopherf71609b2015-02-13 00:39:27 +000072 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
Jim Laskey527c12f2006-12-06 17:42:06 +000073
Ulrich Weigandad0cb912014-06-18 17:52:49 +000074 /// getTOCSaveOffset - Return the previous frame offset to save the
75 /// TOC register -- 64-bit SVR4 ABI only.
Eric Christopher736d39e2015-02-13 00:39:36 +000076 unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
Ulrich Weigandad0cb912014-06-18 17:52:49 +000077
Jim Laskey48850c12006-11-16 22:43:37 +000078 /// getFramePointerSaveOffset - Return the previous frame offset to save the
79 /// frame pointer.
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000080 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller773f14c2009-07-03 06:47:08 +000081 // For the Darwin ABI:
Dale Johannesen5ece8f02009-11-24 22:59:02 +000082 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
83 // for saving the frame pointer (if needed.) While the published ABI has
84 // not used this slot since at least MacOSX 10.2, there is older code
85 // around that does use it, and that needs to continue to work.
Tilmann Scheller773f14c2009-07-03 06:47:08 +000086 if (isDarwinABI)
Dale Johannesen5ece8f02009-11-24 22:59:02 +000087 return isPPC64 ? -8U : -4U;
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +000088
Tilmann Schellerd1aaa322009-08-15 11:54:46 +000089 // SVR4 ABI: First slot in the general register save area.
Tilmann Scheller5b2df8d2009-12-18 13:00:34 +000090 return isPPC64 ? -8U : -4U;
Jim Laskey48850c12006-11-16 22:43:37 +000091 }
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +000092
Hal Finkela7c54e82013-07-17 00:45:52 +000093 /// getBasePointerSaveOffset - Return the previous frame offset to save the
94 /// base pointer.
Hal Finkel3ee2af72014-07-18 23:29:49 +000095 static unsigned getBasePointerSaveOffset(bool isPPC64,
96 bool isDarwinABI,
97 bool isPIC) {
Hal Finkela7c54e82013-07-17 00:45:52 +000098 if (isDarwinABI)
99 return isPPC64 ? -16U : -8U;
100
101 // SVR4 ABI: First slot in the general register save area.
Hal Finkel3ee2af72014-07-18 23:29:49 +0000102 return isPPC64 ? -16U : isPIC ? -12U : -8U;
Hal Finkela7c54e82013-07-17 00:45:52 +0000103 }
104
Jim Laskey48850c12006-11-16 22:43:37 +0000105 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
106 ///
Ulrich Weigand8658f172014-07-20 23:43:15 +0000107 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI,
108 bool isELFv2ABI) {
Tilmann Schellerd1aaa322009-08-15 11:54:46 +0000109 if (isDarwinABI || isPPC64)
Ulrich Weigand8658f172014-07-20 23:43:15 +0000110 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4);
Anton Korobeynikova5ab8f12010-11-15 00:06:05 +0000111
Tilmann Scheller773f14c2009-07-03 06:47:08 +0000112 // SVR4 ABI:
Nicolas Geoffrayb3e99a12007-04-03 12:35:28 +0000113 return 8;
Jim Laskey48850c12006-11-16 22:43:37 +0000114 }
115
Tilmann Scheller336e2bd2009-09-27 17:58:47 +0000116 const SpillSlot *
Eric Christopherd104c312014-06-12 20:54:11 +0000117 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
Nate Begeman412602d2004-08-14 22:16:36 +0000118};
Nate Begeman412602d2004-08-14 22:16:36 +0000119} // End llvm namespace
120
121#endif