blob: 1330034f5ad1c97406c0b299aa34939415c5a9eb [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;
24 std::pair<unsigned, int> LR[1];
Misha Brukmanb5f662f2005-04-21 23:30:14 +000025
Nate Begemanca068e82004-08-14 22:16:36 +000026public:
Nate Begeman21e463b2005-10-16 05:39:50 +000027 PPCFrameInfo(const TargetMachine &tm, bool LP64)
Misha Brukman63161812004-08-17 05:09:39 +000028 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
Chris Lattnerff790892006-11-18 01:34:43 +000029 if (LP64) {
30 LR[0].first = PPC::LR8;
31 LR[0].second = 16;
32 } else {
33 LR[0].first = PPC::LR;
34 LR[0].second = 8;
35 }
Nate Begemanca068e82004-08-14 22:16:36 +000036 }
37
Alkis Evlogimenos8c9b4de2004-08-15 09:18:55 +000038 const std::pair<unsigned, int> *
Nate Begemanca068e82004-08-14 22:16:36 +000039 getCalleeSaveSpillSlots(unsigned &NumEntries) const {
40 NumEntries = 1;
Chris Lattnerb6482062004-08-16 05:09:58 +000041 return &LR[0];
Nate Begemanca068e82004-08-14 22:16:36 +000042 }
Jim Laskey2f616bf2006-11-16 22:43:37 +000043
44 /// getFramePointerSaveOffset - Return the previous frame offset to save the
45 /// frame pointer.
46 static unsigned getFramePointerSaveOffset(bool LP64) {
47 // Use the TOC save slot in the PowerPC linkage area for saving the frame
48 // pointer (if needed.) LLVM does not generate code that uses the TOC (R2
49 // is treated as a caller saved register.)
50 return LP64 ? 40 : 20;
51 }
52
53 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
54 ///
55 static unsigned getLinkageSize(bool LP64) {
56 return 6 * (LP64 ? 8 : 4);
57 }
58
59 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
60 /// argument area.
61 static unsigned getMinCallArgumentsSize(bool LP64) {
62 // The prolog code of the callee may store up to 8 GPR argument registers to
63 // the stack, allowing va_start to index over them in memory if its varargs.
64 // Because we cannot tell if this is needed on the caller side, we have to
65 // conservatively assume that it is needed. As such, make sure we have at
66 // least enough stack space for the caller to store the 8 GPRs.
67 return 8 * (LP64 ? 8 : 4);
68 }
69
70 /// getMinCallFrameSize - Return the minimum size a call frame can be using
71 /// the PowerPC ABI.
72 static unsigned getMinCallFrameSize(bool LP64) {
73 // The call frame needs to be at least big enough for linkage and 8 args.
74 return getLinkageSize(LP64) + getMinCallArgumentsSize(LP64);
75 }
76
Nate Begemanca068e82004-08-14 22:16:36 +000077};
78
79} // End llvm namespace
80
81#endif