1*45bb48eaSTom Stellard //===----------------------- AMDGPUFrameLowering.cpp ----------------------===// 2*45bb48eaSTom Stellard // 3*45bb48eaSTom Stellard // The LLVM Compiler Infrastructure 4*45bb48eaSTom Stellard // 5*45bb48eaSTom Stellard // This file is distributed under the University of Illinois Open Source 6*45bb48eaSTom Stellard // License. See LICENSE.TXT for details. 7*45bb48eaSTom Stellard // 8*45bb48eaSTom Stellard //==-----------------------------------------------------------------------===// 9*45bb48eaSTom Stellard // 10*45bb48eaSTom Stellard // Interface to describe a layout of a stack frame on a AMDIL target machine 11*45bb48eaSTom Stellard // 12*45bb48eaSTom Stellard //===----------------------------------------------------------------------===// 13*45bb48eaSTom Stellard #include "AMDGPUFrameLowering.h" 14*45bb48eaSTom Stellard #include "AMDGPURegisterInfo.h" 15*45bb48eaSTom Stellard #include "R600MachineFunctionInfo.h" 16*45bb48eaSTom Stellard #include "llvm/CodeGen/MachineFrameInfo.h" 17*45bb48eaSTom Stellard #include "llvm/CodeGen/MachineRegisterInfo.h" 18*45bb48eaSTom Stellard #include "llvm/IR/Instructions.h" 19*45bb48eaSTom Stellard 20*45bb48eaSTom Stellard using namespace llvm; 21*45bb48eaSTom Stellard AMDGPUFrameLowering::AMDGPUFrameLowering(StackDirection D, unsigned StackAl, 22*45bb48eaSTom Stellard int LAO, unsigned TransAl) 23*45bb48eaSTom Stellard : TargetFrameLowering(D, StackAl, LAO, TransAl) { } 24*45bb48eaSTom Stellard 25*45bb48eaSTom Stellard AMDGPUFrameLowering::~AMDGPUFrameLowering() { } 26*45bb48eaSTom Stellard 27*45bb48eaSTom Stellard unsigned AMDGPUFrameLowering::getStackWidth(const MachineFunction &MF) const { 28*45bb48eaSTom Stellard 29*45bb48eaSTom Stellard // XXX: Hardcoding to 1 for now. 30*45bb48eaSTom Stellard // 31*45bb48eaSTom Stellard // I think the StackWidth should stored as metadata associated with the 32*45bb48eaSTom Stellard // MachineFunction. This metadata can either be added by a frontend, or 33*45bb48eaSTom Stellard // calculated by a R600 specific LLVM IR pass. 34*45bb48eaSTom Stellard // 35*45bb48eaSTom Stellard // The StackWidth determines how stack objects are laid out in memory. 36*45bb48eaSTom Stellard // For a vector stack variable, like: int4 stack[2], the data will be stored 37*45bb48eaSTom Stellard // in the following ways depending on the StackWidth. 38*45bb48eaSTom Stellard // 39*45bb48eaSTom Stellard // StackWidth = 1: 40*45bb48eaSTom Stellard // 41*45bb48eaSTom Stellard // T0.X = stack[0].x 42*45bb48eaSTom Stellard // T1.X = stack[0].y 43*45bb48eaSTom Stellard // T2.X = stack[0].z 44*45bb48eaSTom Stellard // T3.X = stack[0].w 45*45bb48eaSTom Stellard // T4.X = stack[1].x 46*45bb48eaSTom Stellard // T5.X = stack[1].y 47*45bb48eaSTom Stellard // T6.X = stack[1].z 48*45bb48eaSTom Stellard // T7.X = stack[1].w 49*45bb48eaSTom Stellard // 50*45bb48eaSTom Stellard // StackWidth = 2: 51*45bb48eaSTom Stellard // 52*45bb48eaSTom Stellard // T0.X = stack[0].x 53*45bb48eaSTom Stellard // T0.Y = stack[0].y 54*45bb48eaSTom Stellard // T1.X = stack[0].z 55*45bb48eaSTom Stellard // T1.Y = stack[0].w 56*45bb48eaSTom Stellard // T2.X = stack[1].x 57*45bb48eaSTom Stellard // T2.Y = stack[1].y 58*45bb48eaSTom Stellard // T3.X = stack[1].z 59*45bb48eaSTom Stellard // T3.Y = stack[1].w 60*45bb48eaSTom Stellard // 61*45bb48eaSTom Stellard // StackWidth = 4: 62*45bb48eaSTom Stellard // T0.X = stack[0].x 63*45bb48eaSTom Stellard // T0.Y = stack[0].y 64*45bb48eaSTom Stellard // T0.Z = stack[0].z 65*45bb48eaSTom Stellard // T0.W = stack[0].w 66*45bb48eaSTom Stellard // T1.X = stack[1].x 67*45bb48eaSTom Stellard // T1.Y = stack[1].y 68*45bb48eaSTom Stellard // T1.Z = stack[1].z 69*45bb48eaSTom Stellard // T1.W = stack[1].w 70*45bb48eaSTom Stellard return 1; 71*45bb48eaSTom Stellard } 72*45bb48eaSTom Stellard 73*45bb48eaSTom Stellard /// \returns The number of registers allocated for \p FI. 74*45bb48eaSTom Stellard int AMDGPUFrameLowering::getFrameIndexOffset(const MachineFunction &MF, 75*45bb48eaSTom Stellard int FI) const { 76*45bb48eaSTom Stellard const MachineFrameInfo *MFI = MF.getFrameInfo(); 77*45bb48eaSTom Stellard // Start the offset at 2 so we don't overwrite work group information. 78*45bb48eaSTom Stellard // XXX: We should only do this when the shader actually uses this 79*45bb48eaSTom Stellard // information. 80*45bb48eaSTom Stellard unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4); 81*45bb48eaSTom Stellard int UpperBound = FI == -1 ? MFI->getNumObjects() : FI; 82*45bb48eaSTom Stellard 83*45bb48eaSTom Stellard for (int i = MFI->getObjectIndexBegin(); i < UpperBound; ++i) { 84*45bb48eaSTom Stellard OffsetBytes = RoundUpToAlignment(OffsetBytes, MFI->getObjectAlignment(i)); 85*45bb48eaSTom Stellard OffsetBytes += MFI->getObjectSize(i); 86*45bb48eaSTom Stellard // Each register holds 4 bytes, so we must always align the offset to at 87*45bb48eaSTom Stellard // least 4 bytes, so that 2 frame objects won't share the same register. 88*45bb48eaSTom Stellard OffsetBytes = RoundUpToAlignment(OffsetBytes, 4); 89*45bb48eaSTom Stellard } 90*45bb48eaSTom Stellard 91*45bb48eaSTom Stellard if (FI != -1) 92*45bb48eaSTom Stellard OffsetBytes = RoundUpToAlignment(OffsetBytes, MFI->getObjectAlignment(FI)); 93*45bb48eaSTom Stellard 94*45bb48eaSTom Stellard return OffsetBytes / (getStackWidth(MF) * 4); 95*45bb48eaSTom Stellard } 96*45bb48eaSTom Stellard 97*45bb48eaSTom Stellard const TargetFrameLowering::SpillSlot * 98*45bb48eaSTom Stellard AMDGPUFrameLowering::getCalleeSavedSpillSlots(unsigned &NumEntries) const { 99*45bb48eaSTom Stellard NumEntries = 0; 100*45bb48eaSTom Stellard return nullptr; 101*45bb48eaSTom Stellard } 102*45bb48eaSTom Stellard void AMDGPUFrameLowering::emitPrologue(MachineFunction &MF, 103*45bb48eaSTom Stellard MachineBasicBlock &MBB) const {} 104*45bb48eaSTom Stellard void 105*45bb48eaSTom Stellard AMDGPUFrameLowering::emitEpilogue(MachineFunction &MF, 106*45bb48eaSTom Stellard MachineBasicBlock &MBB) const { 107*45bb48eaSTom Stellard } 108*45bb48eaSTom Stellard 109*45bb48eaSTom Stellard bool 110*45bb48eaSTom Stellard AMDGPUFrameLowering::hasFP(const MachineFunction &MF) const { 111*45bb48eaSTom Stellard return false; 112*45bb48eaSTom Stellard } 113