1 //===-- SIMachineFunctionInfo.cpp - SI Machine Function Info -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
12 #include "SIMachineFunctionInfo.h"
13 #include "AMDGPUSubtarget.h"
14 #include "SIInstrInfo.h"
15 #include "llvm/CodeGen/MachineInstrBuilder.h"
16 #include "llvm/CodeGen/MachineFrameInfo.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/LLVMContext.h"
26 // Pin the vtable to this file.
27 void SIMachineFunctionInfo::anchor() {}
29 SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF)
30 : AMDGPUMachineFunction(MF),
31 TIDReg(AMDGPU::NoRegister),
34 LDSWaveSpillSize(0) { }
36 SIMachineFunctionInfo::SpilledReg SIMachineFunctionInfo::getSpilledReg(
40 const MachineFrameInfo *FrameInfo = MF->getFrameInfo();
41 const SIRegisterInfo *TRI = static_cast<const SIRegisterInfo*>(
42 MF->getTarget().getSubtarget<AMDGPUSubtarget>().getRegisterInfo());
43 MachineRegisterInfo &MRI = MF->getRegInfo();
44 int64_t Offset = FrameInfo->getObjectOffset(FrameIndex);
47 unsigned LaneVGPRIdx = Offset / (64 * 4);
48 unsigned Lane = (Offset / 4) % 64;
50 struct SpilledReg Spill;
52 if (!LaneVGPRs.count(LaneVGPRIdx)) {
53 unsigned LaneVGPR = TRI->findUnusedVGPR(MRI);
54 LaneVGPRs[LaneVGPRIdx] = LaneVGPR;
55 MRI.setPhysRegUsed(LaneVGPR);
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();
61 BI->addLiveIn(LaneVGPR);
65 Spill.VGPR = LaneVGPRs[LaneVGPRIdx];
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
75 return getShaderType() == ShaderType::COMPUTE ? 256 : ST.getWavefrontSize();