145bb48eaSTom Stellard //===----------------------- AMDGPUFrameLowering.cpp ----------------------===// 245bb48eaSTom Stellard // 345bb48eaSTom Stellard // The LLVM Compiler Infrastructure 445bb48eaSTom Stellard // 545bb48eaSTom Stellard // This file is distributed under the University of Illinois Open Source 645bb48eaSTom Stellard // License. See LICENSE.TXT for details. 745bb48eaSTom Stellard // 845bb48eaSTom Stellard //==-----------------------------------------------------------------------===// 945bb48eaSTom Stellard // 1045bb48eaSTom Stellard // Interface to describe a layout of a stack frame on a AMDIL target machine 1145bb48eaSTom Stellard // 1245bb48eaSTom Stellard //===----------------------------------------------------------------------===// 1345bb48eaSTom Stellard #include "AMDGPUFrameLowering.h" 1445bb48eaSTom Stellard #include "AMDGPURegisterInfo.h" 1545bb48eaSTom Stellard #include "R600MachineFunctionInfo.h" 1645bb48eaSTom Stellard #include "llvm/CodeGen/MachineFrameInfo.h" 1745bb48eaSTom Stellard #include "llvm/CodeGen/MachineRegisterInfo.h" 1845bb48eaSTom Stellard #include "llvm/IR/Instructions.h" 1945bb48eaSTom Stellard 2045bb48eaSTom Stellard using namespace llvm; 2145bb48eaSTom Stellard AMDGPUFrameLowering::AMDGPUFrameLowering(StackDirection D, unsigned StackAl, 2245bb48eaSTom Stellard int LAO, unsigned TransAl) 2345bb48eaSTom Stellard : TargetFrameLowering(D, StackAl, LAO, TransAl) { } 2445bb48eaSTom Stellard 2545bb48eaSTom Stellard AMDGPUFrameLowering::~AMDGPUFrameLowering() { } 2645bb48eaSTom Stellard 2745bb48eaSTom Stellard unsigned AMDGPUFrameLowering::getStackWidth(const MachineFunction &MF) const { 2845bb48eaSTom Stellard 2945bb48eaSTom Stellard // XXX: Hardcoding to 1 for now. 3045bb48eaSTom Stellard // 3145bb48eaSTom Stellard // I think the StackWidth should stored as metadata associated with the 3245bb48eaSTom Stellard // MachineFunction. This metadata can either be added by a frontend, or 3345bb48eaSTom Stellard // calculated by a R600 specific LLVM IR pass. 3445bb48eaSTom Stellard // 3545bb48eaSTom Stellard // The StackWidth determines how stack objects are laid out in memory. 3645bb48eaSTom Stellard // For a vector stack variable, like: int4 stack[2], the data will be stored 3745bb48eaSTom Stellard // in the following ways depending on the StackWidth. 3845bb48eaSTom Stellard // 3945bb48eaSTom Stellard // StackWidth = 1: 4045bb48eaSTom Stellard // 4145bb48eaSTom Stellard // T0.X = stack[0].x 4245bb48eaSTom Stellard // T1.X = stack[0].y 4345bb48eaSTom Stellard // T2.X = stack[0].z 4445bb48eaSTom Stellard // T3.X = stack[0].w 4545bb48eaSTom Stellard // T4.X = stack[1].x 4645bb48eaSTom Stellard // T5.X = stack[1].y 4745bb48eaSTom Stellard // T6.X = stack[1].z 4845bb48eaSTom Stellard // T7.X = stack[1].w 4945bb48eaSTom Stellard // 5045bb48eaSTom Stellard // StackWidth = 2: 5145bb48eaSTom Stellard // 5245bb48eaSTom Stellard // T0.X = stack[0].x 5345bb48eaSTom Stellard // T0.Y = stack[0].y 5445bb48eaSTom Stellard // T1.X = stack[0].z 5545bb48eaSTom Stellard // T1.Y = stack[0].w 5645bb48eaSTom Stellard // T2.X = stack[1].x 5745bb48eaSTom Stellard // T2.Y = stack[1].y 5845bb48eaSTom Stellard // T3.X = stack[1].z 5945bb48eaSTom Stellard // T3.Y = stack[1].w 6045bb48eaSTom Stellard // 6145bb48eaSTom Stellard // StackWidth = 4: 6245bb48eaSTom Stellard // T0.X = stack[0].x 6345bb48eaSTom Stellard // T0.Y = stack[0].y 6445bb48eaSTom Stellard // T0.Z = stack[0].z 6545bb48eaSTom Stellard // T0.W = stack[0].w 6645bb48eaSTom Stellard // T1.X = stack[1].x 6745bb48eaSTom Stellard // T1.Y = stack[1].y 6845bb48eaSTom Stellard // T1.Z = stack[1].z 6945bb48eaSTom Stellard // T1.W = stack[1].w 7045bb48eaSTom Stellard return 1; 7145bb48eaSTom Stellard } 7245bb48eaSTom Stellard 7345bb48eaSTom Stellard /// \returns The number of registers allocated for \p FI. 74*5567bafeSJames Y Knight int AMDGPUFrameLowering::getFrameIndexReference(const MachineFunction &MF, 75*5567bafeSJames Y Knight int FI, 76*5567bafeSJames Y Knight unsigned &FrameReg) const { 7745bb48eaSTom Stellard const MachineFrameInfo *MFI = MF.getFrameInfo(); 78*5567bafeSJames Y Knight const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo(); 79*5567bafeSJames Y Knight 80*5567bafeSJames Y Knight // Fill in FrameReg output argument. 81*5567bafeSJames Y Knight FrameReg = RI->getFrameRegister(MF); 82*5567bafeSJames Y Knight 8345bb48eaSTom Stellard // Start the offset at 2 so we don't overwrite work group information. 8445bb48eaSTom Stellard // XXX: We should only do this when the shader actually uses this 8545bb48eaSTom Stellard // information. 8645bb48eaSTom Stellard unsigned OffsetBytes = 2 * (getStackWidth(MF) * 4); 8745bb48eaSTom Stellard int UpperBound = FI == -1 ? MFI->getNumObjects() : FI; 8845bb48eaSTom Stellard 8945bb48eaSTom Stellard for (int i = MFI->getObjectIndexBegin(); i < UpperBound; ++i) { 9045bb48eaSTom Stellard OffsetBytes = RoundUpToAlignment(OffsetBytes, MFI->getObjectAlignment(i)); 9145bb48eaSTom Stellard OffsetBytes += MFI->getObjectSize(i); 9245bb48eaSTom Stellard // Each register holds 4 bytes, so we must always align the offset to at 9345bb48eaSTom Stellard // least 4 bytes, so that 2 frame objects won't share the same register. 9445bb48eaSTom Stellard OffsetBytes = RoundUpToAlignment(OffsetBytes, 4); 9545bb48eaSTom Stellard } 9645bb48eaSTom Stellard 9745bb48eaSTom Stellard if (FI != -1) 9845bb48eaSTom Stellard OffsetBytes = RoundUpToAlignment(OffsetBytes, MFI->getObjectAlignment(FI)); 9945bb48eaSTom Stellard 10045bb48eaSTom Stellard return OffsetBytes / (getStackWidth(MF) * 4); 10145bb48eaSTom Stellard } 10245bb48eaSTom Stellard 10345bb48eaSTom Stellard const TargetFrameLowering::SpillSlot * 10445bb48eaSTom Stellard AMDGPUFrameLowering::getCalleeSavedSpillSlots(unsigned &NumEntries) const { 10545bb48eaSTom Stellard NumEntries = 0; 10645bb48eaSTom Stellard return nullptr; 10745bb48eaSTom Stellard } 10845bb48eaSTom Stellard void AMDGPUFrameLowering::emitPrologue(MachineFunction &MF, 10945bb48eaSTom Stellard MachineBasicBlock &MBB) const {} 11045bb48eaSTom Stellard void 11145bb48eaSTom Stellard AMDGPUFrameLowering::emitEpilogue(MachineFunction &MF, 11245bb48eaSTom Stellard MachineBasicBlock &MBB) const { 11345bb48eaSTom Stellard } 11445bb48eaSTom Stellard 11545bb48eaSTom Stellard bool 11645bb48eaSTom Stellard AMDGPUFrameLowering::hasFP(const MachineFunction &MF) const { 11745bb48eaSTom Stellard return false; 11845bb48eaSTom Stellard } 119