LLVM API Documentation

AMDGPUFrameLowering.cpp
Go to the documentation of this file.
00001 //===----------------------- AMDGPUFrameLowering.cpp ----------------------===//
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 // Interface to describe a layout of a stack frame on a AMDIL target machine
00011 //
00012 //===----------------------------------------------------------------------===//
00013 #include "AMDGPUFrameLowering.h"
00014 #include "AMDGPURegisterInfo.h"
00015 #include "R600MachineFunctionInfo.h"
00016 #include "llvm/CodeGen/MachineFrameInfo.h"
00017 #include "llvm/CodeGen/MachineRegisterInfo.h"
00018 #include "llvm/IR/Instructions.h"
00019 
00020 using namespace llvm;
00021 AMDGPUFrameLowering::AMDGPUFrameLowering(StackDirection D, unsigned StackAl,
00022     int LAO, unsigned TransAl)
00023   : TargetFrameLowering(D, StackAl, LAO, TransAl) { }
00024 
00025 AMDGPUFrameLowering::~AMDGPUFrameLowering() { }
00026 
00027 unsigned AMDGPUFrameLowering::getStackWidth(const MachineFunction &MF) const {
00028 
00029   // XXX: Hardcoding to 1 for now.
00030   //
00031   // I think the StackWidth should stored as metadata associated with the
00032   // MachineFunction.  This metadata can either be added by a frontend, or
00033   // calculated by a R600 specific LLVM IR pass.
00034   //
00035   // The StackWidth determines how stack objects are laid out in memory.
00036   // For a vector stack variable, like: int4 stack[2], the data will be stored
00037   // in the following ways depending on the StackWidth.
00038   //
00039   // StackWidth = 1:
00040   //
00041   // T0.X = stack[0].x
00042   // T1.X = stack[0].y
00043   // T2.X = stack[0].z
00044   // T3.X = stack[0].w
00045   // T4.X = stack[1].x
00046   // T5.X = stack[1].y
00047   // T6.X = stack[1].z
00048   // T7.X = stack[1].w
00049   //
00050   // StackWidth = 2:
00051   //
00052   // T0.X = stack[0].x
00053   // T0.Y = stack[0].y
00054   // T1.X = stack[0].z
00055   // T1.Y = stack[0].w
00056   // T2.X = stack[1].x
00057   // T2.Y = stack[1].y
00058   // T3.X = stack[1].z
00059   // T3.Y = stack[1].w
00060   // 
00061   // StackWidth = 4:
00062   // T0.X = stack[0].x
00063   // T0.Y = stack[0].y
00064   // T0.Z = stack[0].z
00065   // T0.W = stack[0].w
00066   // T1.X = stack[1].x
00067   // T1.Y = stack[1].y
00068   // T1.Z = stack[1].z
00069   // T1.W = stack[1].w
00070   return 1;
00071 }
00072 
00073 /// \returns The number of registers allocated for \p FI.
00074 int AMDGPUFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
00075                                          int FI) const {
00076   const MachineFrameInfo *MFI = MF.getFrameInfo();
00077   // Start the offset at 2 so we don't overwrite work group information.
00078   // XXX: We should only do this when the shader actually uses this
00079   // information.
00080   unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4);
00081   int UpperBound = FI == -1 ? MFI->getNumObjects() : FI;
00082 
00083   for (int i = MFI->getObjectIndexBegin(); i < UpperBound; ++i) {
00084     OffsetBytes = RoundUpToAlignment(OffsetBytes, MFI->getObjectAlignment(i));
00085     OffsetBytes += MFI->getObjectSize(i);
00086     // Each register holds 4 bytes, so we must always align the offset to at
00087     // least 4 bytes, so that 2 frame objects won't share the same register.
00088     OffsetBytes = RoundUpToAlignment(OffsetBytes, 4);
00089   }
00090 
00091   if (FI != -1)
00092     OffsetBytes = RoundUpToAlignment(OffsetBytes, MFI->getObjectAlignment(FI));
00093 
00094   return OffsetBytes / (getStackWidth(MF) * 4);
00095 }
00096 
00097 const TargetFrameLowering::SpillSlot *
00098 AMDGPUFrameLowering::getCalleeSavedSpillSlots(unsigned &NumEntries) const {
00099   NumEntries = 0;
00100   return nullptr;
00101 }
00102 void
00103 AMDGPUFrameLowering::emitPrologue(MachineFunction &MF) const {
00104 }
00105 void
00106 AMDGPUFrameLowering::emitEpilogue(MachineFunction &MF,
00107                                   MachineBasicBlock &MBB) const {
00108 }
00109 
00110 bool
00111 AMDGPUFrameLowering::hasFP(const MachineFunction &MF) const {
00112   return false;
00113 }