Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 1 | //===-- SIMachineFunctionInfo.cpp - SI Machine Function Info -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | /// \file |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | |
| 12 | #include "SIMachineFunctionInfo.h" |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 13 | #include "AMDGPUSubtarget.h" |
Tom Stellard | eba6107 | 2014-05-02 15:41:42 +0000 | [diff] [blame] | 14 | #include "SIInstrInfo.h" |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Tom Stellard | c149dc0 | 2013-11-27 21:23:35 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Tom Stellard | eba6107 | 2014-05-02 15:41:42 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Function.h" |
| 19 | #include "llvm/IR/LLVMContext.h" |
Tom Stellard | c149dc0 | 2013-11-27 21:23:35 +0000 | [diff] [blame] | 20 | |
| 21 | #define MAX_LANES 64 |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 25 | |
| 26 | // Pin the vtable to this file. |
| 27 | void SIMachineFunctionInfo::anchor() {} |
| 28 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 29 | SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF) |
Vincent Lejeune | ace6f73 | 2013-04-01 21:47:53 +0000 | [diff] [blame] | 30 | : AMDGPUMachineFunction(MF), |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 31 | TIDReg(AMDGPU::NoRegister), |
Matt Arsenault | 49affb8 | 2015-11-25 20:55:12 +0000 | [diff] [blame] | 32 | ScratchRSrcReg(AMDGPU::NoRegister), |
| 33 | LDSWaveSpillSize(0), |
Tom Stellard | c149dc0 | 2013-11-27 21:23:35 +0000 | [diff] [blame] | 34 | PSInputAddr(0), |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 35 | NumUserSGPRs(0), |
Matt Arsenault | 49affb8 | 2015-11-25 20:55:12 +0000 | [diff] [blame] | 36 | HasSpilledSGPRs(false), |
| 37 | HasSpilledVGPRs(false), |
| 38 | DispatchPtr(false), |
| 39 | QueuePtr(false), |
| 40 | DispatchID(false), |
| 41 | KernargSegmentPtr(true), |
| 42 | FlatScratchInit(false), |
| 43 | GridWorkgroupCountX(false), |
| 44 | GridWorkgroupCountY(false), |
| 45 | GridWorkgroupCountZ(false), |
| 46 | WorkGroupIDX(true), |
| 47 | WorkGroupIDY(false), |
| 48 | WorkGroupIDZ(false), |
| 49 | WorkGroupInfo(false), |
| 50 | WorkItemIDX(true), |
| 51 | WorkItemIDY(false), |
| 52 | WorkItemIDZ(false) { |
| 53 | const Function *F = MF.getFunction(); |
| 54 | |
| 55 | if (F->hasFnAttribute("amdgpu-dispatch-ptr")) |
| 56 | DispatchPtr = true; |
| 57 | |
| 58 | if (F->hasFnAttribute("amdgpu-work-group-id-y")) |
| 59 | WorkGroupIDY = true; |
| 60 | |
| 61 | if (F->hasFnAttribute("amdgpu-work-group-id-z")) |
| 62 | WorkGroupIDZ = true; |
| 63 | |
| 64 | if (F->hasFnAttribute("amdgpu-work-item-id-y")) |
| 65 | WorkItemIDY = true; |
| 66 | |
| 67 | if (F->hasFnAttribute("amdgpu-work-item-id-z")) |
| 68 | WorkItemIDZ = true; |
| 69 | } |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 70 | |
Matt Arsenault | 0e3d389 | 2015-11-30 21:15:53 +0000 | [diff] [blame^] | 71 | void SIMachineFunctionInfo::setScratchRSrcReg(const SIRegisterInfo *TRI) { |
| 72 | // We need to round up to next multiple of 4. |
| 73 | unsigned NextSReg128 = RoundUpToAlignment(NumUserSGPRs + 5, 4); |
| 74 | unsigned RegSub0 = AMDGPU::SReg_32RegClass.getRegister(NextSReg128); |
| 75 | ScratchRSrcReg = TRI->getMatchingSuperReg(RegSub0, AMDGPU::sub0, |
| 76 | &AMDGPU::SReg_128RegClass); |
| 77 | } |
| 78 | |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 79 | SIMachineFunctionInfo::SpilledReg SIMachineFunctionInfo::getSpilledReg( |
| 80 | MachineFunction *MF, |
| 81 | unsigned FrameIndex, |
| 82 | unsigned SubIdx) { |
| 83 | const MachineFrameInfo *FrameInfo = MF->getFrameInfo(); |
Eric Christopher | 0795a2e | 2015-02-19 01:10:55 +0000 | [diff] [blame] | 84 | const SIRegisterInfo *TRI = static_cast<const SIRegisterInfo *>( |
| 85 | MF->getSubtarget<AMDGPUSubtarget>().getRegisterInfo()); |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 86 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 87 | int64_t Offset = FrameInfo->getObjectOffset(FrameIndex); |
| 88 | Offset += SubIdx * 4; |
| 89 | |
| 90 | unsigned LaneVGPRIdx = Offset / (64 * 4); |
| 91 | unsigned Lane = (Offset / 4) % 64; |
| 92 | |
| 93 | struct SpilledReg Spill; |
| 94 | |
| 95 | if (!LaneVGPRs.count(LaneVGPRIdx)) { |
Tom Stellard | 42fb60e | 2015-01-14 15:42:31 +0000 | [diff] [blame] | 96 | unsigned LaneVGPR = TRI->findUnusedRegister(MRI, &AMDGPU::VGPR_32RegClass); |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 97 | LaneVGPRs[LaneVGPRIdx] = LaneVGPR; |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 98 | |
| 99 | // Add this register as live-in to all blocks to avoid machine verifer |
| 100 | // complaining about use of an undefined physical register. |
| 101 | for (MachineFunction::iterator BI = MF->begin(), BE = MF->end(); |
| 102 | BI != BE; ++BI) { |
| 103 | BI->addLiveIn(LaneVGPR); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | Spill.VGPR = LaneVGPRs[LaneVGPRIdx]; |
| 108 | Spill.Lane = Lane; |
| 109 | return Spill; |
Tom Stellard | c149dc0 | 2013-11-27 21:23:35 +0000 | [diff] [blame] | 110 | } |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 111 | |
| 112 | unsigned SIMachineFunctionInfo::getMaximumWorkGroupSize( |
| 113 | const MachineFunction &MF) const { |
Eric Christopher | 0795a2e | 2015-02-19 01:10:55 +0000 | [diff] [blame] | 114 | const AMDGPUSubtarget &ST = MF.getSubtarget<AMDGPUSubtarget>(); |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 115 | // FIXME: We should get this information from kernel attributes if it |
| 116 | // is available. |
| 117 | return getShaderType() == ShaderType::COMPUTE ? 256 : ST.getWavefrontSize(); |
| 118 | } |