blob: 22b945ea20816a9370d3122137dd726ec99a4467 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Nate Begemanca068e82004-08-14 22:16:36 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Nate Begemanca068e82004-08-14 22:16:36 +00008//===----------------------------------------------------------------------===//
9//
10//
Nate Begeman21e463b2005-10-16 05:39:50 +000011//===----------------------------------------------------------------------===//
Nate Begemanca068e82004-08-14 22:16:36 +000012
13#ifndef POWERPC_FRAMEINFO_H
14#define POWERPC_FRAMEINFO_H
15
Chris Lattner26689592005-10-14 23:51:18 +000016#include "PPC.h"
Nate Begemanca068e82004-08-14 22:16:36 +000017#include "llvm/Target/TargetFrameInfo.h"
18#include "llvm/Target/TargetMachine.h"
Nate Begemanca068e82004-08-14 22:16:36 +000019
20namespace llvm {
21
Nate Begeman21e463b2005-10-16 05:39:50 +000022class PPCFrameInfo: public TargetFrameInfo {
Nate Begemanca068e82004-08-14 22:16:36 +000023 const TargetMachine &TM;
Misha Brukmanb5f662f2005-04-21 23:30:14 +000024
Nate Begemanca068e82004-08-14 22:16:36 +000025public:
Nate Begeman21e463b2005-10-16 05:39:50 +000026 PPCFrameInfo(const TargetMachine &tm, bool LP64)
Misha Brukman63161812004-08-17 05:09:39 +000027 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
Nate Begemanca068e82004-08-14 22:16:36 +000028 }
29
Jim Laskey51fe9d92006-12-06 17:42:06 +000030 /// getReturnSaveOffset - Return the previous frame offset to save the
31 /// return address.
32 static unsigned getReturnSaveOffset(bool LP64) {
33 return LP64 ? 16 : 8;
Nate Begemanca068e82004-08-14 22:16:36 +000034 }
Jim Laskey51fe9d92006-12-06 17:42:06 +000035
Jim Laskey2f616bf2006-11-16 22:43:37 +000036 /// getFramePointerSaveOffset - Return the previous frame offset to save the
37 /// frame pointer.
38 static unsigned getFramePointerSaveOffset(bool LP64) {
39 // Use the TOC save slot in the PowerPC linkage area for saving the frame
40 // pointer (if needed.) LLVM does not generate code that uses the TOC (R2
41 // is treated as a caller saved register.)
42 return LP64 ? 40 : 20;
43 }
44
45 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
46 ///
47 static unsigned getLinkageSize(bool LP64) {
48 return 6 * (LP64 ? 8 : 4);
49 }
50
51 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
52 /// argument area.
53 static unsigned getMinCallArgumentsSize(bool LP64) {
54 // The prolog code of the callee may store up to 8 GPR argument registers to
55 // the stack, allowing va_start to index over them in memory if its varargs.
56 // Because we cannot tell if this is needed on the caller side, we have to
57 // conservatively assume that it is needed. As such, make sure we have at
58 // least enough stack space for the caller to store the 8 GPRs.
59 return 8 * (LP64 ? 8 : 4);
60 }
61
62 /// getMinCallFrameSize - Return the minimum size a call frame can be using
63 /// the PowerPC ABI.
64 static unsigned getMinCallFrameSize(bool LP64) {
65 // The call frame needs to be at least big enough for linkage and 8 args.
66 return getLinkageSize(LP64) + getMinCallArgumentsSize(LP64);
67 }
68
Nate Begemanca068e82004-08-14 22:16:36 +000069};
70
71} // End llvm namespace
72
73#endif