LLVM API Documentation

PPCFrameInfo.h

Go to the documentation of this file.
00001 //===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //
00011 //===----------------------------------------------------------------------===//
00012 
00013 #ifndef POWERPC_FRAMEINFO_H
00014 #define POWERPC_FRAMEINFO_H
00015 
00016 #include "PPC.h"
00017 #include "llvm/Target/TargetFrameInfo.h"
00018 #include "llvm/Target/TargetMachine.h"
00019 
00020 namespace llvm {
00021 
00022 class PPCFrameInfo: public TargetFrameInfo {
00023   const TargetMachine &TM;
00024 
00025 public:
00026   PPCFrameInfo(const TargetMachine &tm, bool LP64)
00027     : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
00028   }
00029 
00030   /// getReturnSaveOffset - Return the previous frame offset to save the
00031   /// return address.
00032   static unsigned getReturnSaveOffset(bool LP64, bool isMacho) {
00033     if (isMacho)
00034       return LP64 ? 16 : 8;
00035     // For ELF 32 ABI:
00036     return 4;
00037   }
00038 
00039   /// getFramePointerSaveOffset - Return the previous frame offset to save the
00040   /// frame pointer.
00041   static unsigned getFramePointerSaveOffset(bool LP64, bool isMacho) {
00042     // For MachO ABI:
00043     // Use the TOC save slot in the PowerPC linkage area for saving the frame
00044     // pointer (if needed.)  LLVM does not generate code that uses the TOC (R2
00045     // is treated as a caller saved register.)
00046     if (isMacho)
00047       return LP64 ? 40 : 20;
00048     
00049     // For ELF 32 ABI:
00050     // Save it right before the link register
00051     return -4U;
00052   }
00053   
00054   /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
00055   ///
00056   static unsigned getLinkageSize(bool LP64, bool isMacho) {
00057     if (isMacho)
00058       return 6 * (LP64 ? 8 : 4);
00059     
00060     // For ELF 32 ABI:
00061     return 8;
00062   }
00063 
00064   /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
00065   /// argument area.
00066   static unsigned getMinCallArgumentsSize(bool LP64, bool isMacho) {
00067     // For Macho ABI:
00068     // The prolog code of the callee may store up to 8 GPR argument registers to
00069     // the stack, allowing va_start to index over them in memory if its varargs.
00070     // Because we cannot tell if this is needed on the caller side, we have to
00071     // conservatively assume that it is needed.  As such, make sure we have at
00072     // least enough stack space for the caller to store the 8 GPRs.
00073     if (isMacho)
00074       return 8 * (LP64 ? 8 : 4);
00075     
00076     // For ELF 32 ABI:
00077     // There is no default stack allocated for the 8 first GPR arguments.
00078     return 0;
00079   }
00080 
00081   /// getMinCallFrameSize - Return the minimum size a call frame can be using
00082   /// the PowerPC ABI.
00083   static unsigned getMinCallFrameSize(bool LP64, bool isMacho) {
00084     // The call frame needs to be at least big enough for linkage and 8 args.
00085     return getLinkageSize(LP64, isMacho) +
00086            getMinCallArgumentsSize(LP64, isMacho);
00087   }
00088   
00089 };
00090 
00091 } // End llvm namespace
00092 
00093 #endif