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), |
Tom Stellard | c149dc0 | 2013-11-27 21:23:35 +0000 | [diff] [blame] | 32 | PSInputAddr(0), |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 33 | NumUserSGPRs(0), |
| 34 | LDSWaveSpillSize(0) { } |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 35 | |
| 36 | SIMachineFunctionInfo::SpilledReg SIMachineFunctionInfo::getSpilledReg( |
| 37 | MachineFunction *MF, |
| 38 | unsigned FrameIndex, |
| 39 | unsigned SubIdx) { |
| 40 | const MachineFrameInfo *FrameInfo = MF->getFrameInfo(); |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 41 | const SIRegisterInfo *TRI = static_cast<const SIRegisterInfo*>( |
| 42 | MF->getTarget().getSubtarget<AMDGPUSubtarget>().getRegisterInfo()); |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 43 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 44 | int64_t Offset = FrameInfo->getObjectOffset(FrameIndex); |
| 45 | Offset += SubIdx * 4; |
| 46 | |
| 47 | unsigned LaneVGPRIdx = Offset / (64 * 4); |
| 48 | unsigned Lane = (Offset / 4) % 64; |
| 49 | |
| 50 | struct SpilledReg Spill; |
| 51 | |
| 52 | if (!LaneVGPRs.count(LaneVGPRIdx)) { |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 53 | unsigned LaneVGPR = TRI->findUnusedVGPR(MRI); |
Tom Stellard | c5cf2f0 | 2014-08-21 20:40:54 +0000 | [diff] [blame] | 54 | LaneVGPRs[LaneVGPRIdx] = LaneVGPR; |
| 55 | MRI.setPhysRegUsed(LaneVGPR); |
| 56 | |
| 57 | // Add this register as live-in to all blocks to avoid machine verifer |
| 58 | // complaining about use of an undefined physical register. |
| 59 | for (MachineFunction::iterator BI = MF->begin(), BE = MF->end(); |
| 60 | BI != BE; ++BI) { |
| 61 | BI->addLiveIn(LaneVGPR); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | Spill.VGPR = LaneVGPRs[LaneVGPRIdx]; |
| 66 | Spill.Lane = Lane; |
| 67 | return Spill; |
Tom Stellard | c149dc0 | 2013-11-27 21:23:35 +0000 | [diff] [blame] | 68 | } |
Tom Stellard | 9646890 | 2014-09-24 01:33:17 +0000 | [diff] [blame] | 69 | |
| 70 | unsigned SIMachineFunctionInfo::getMaximumWorkGroupSize( |
| 71 | const MachineFunction &MF) const { |
| 72 | const AMDGPUSubtarget &ST = MF.getTarget().getSubtarget<AMDGPUSubtarget>(); |
| 73 | // FIXME: We should get this information from kernel attributes if it |
| 74 | // is available. |
| 75 | return getShaderType() == ShaderType::COMPUTE ? 256 : ST.getWavefrontSize(); |
| 76 | } |