SIMachineFunctionInfo.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include "SIMachineFunctionInfo.h"
  11. #include "AMDGPUSubtarget.h"
  12. #include "SIInstrInfo.h"
  13. #include "llvm/CodeGen/MachineInstrBuilder.h"
  14. #include "llvm/CodeGen/MachineFrameInfo.h"
  15. #include "llvm/CodeGen/MachineRegisterInfo.h"
  16. #include "llvm/IR/Function.h"
  17. #include "llvm/IR/LLVMContext.h"
  18. #define MAX_LANES 64
  19. using namespace llvm;
  20. // Pin the vtable to this file.
  21. void SIMachineFunctionInfo::anchor() {}
  22. SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF)
  23. : AMDGPUMachineFunction(MF),
  24. TIDReg(AMDGPU::NoRegister),
  25. HasSpilledVGPRs(false),
  26. PSInputAddr(0),
  27. NumUserSGPRs(0),
  28. LDSWaveSpillSize(0) { }
  29. SIMachineFunctionInfo::SpilledReg SIMachineFunctionInfo::getSpilledReg(
  30. MachineFunction *MF,
  31. unsigned FrameIndex,
  32. unsigned SubIdx) {
  33. const MachineFrameInfo *FrameInfo = MF->getFrameInfo();
  34. const SIRegisterInfo *TRI = static_cast<const SIRegisterInfo *>(
  35. MF->getSubtarget<AMDGPUSubtarget>().getRegisterInfo());
  36. MachineRegisterInfo &MRI = MF->getRegInfo();
  37. int64_t Offset = FrameInfo->getObjectOffset(FrameIndex);
  38. Offset += SubIdx * 4;
  39. unsigned LaneVGPRIdx = Offset / (64 * 4);
  40. unsigned Lane = (Offset / 4) % 64;
  41. struct SpilledReg Spill;
  42. if (!LaneVGPRs.count(LaneVGPRIdx)) {
  43. unsigned LaneVGPR = TRI->findUnusedRegister(MRI, &AMDGPU::VGPR_32RegClass);
  44. LaneVGPRs[LaneVGPRIdx] = LaneVGPR;
  45. // Add this register as live-in to all blocks to avoid machine verifer
  46. // complaining about use of an undefined physical register.
  47. for (MachineFunction::iterator BI = MF->begin(), BE = MF->end();
  48. BI != BE; ++BI) {
  49. BI->addLiveIn(LaneVGPR);
  50. }
  51. }
  52. Spill.VGPR = LaneVGPRs[LaneVGPRIdx];
  53. Spill.Lane = Lane;
  54. return Spill;
  55. }
  56. unsigned SIMachineFunctionInfo::getMaximumWorkGroupSize(
  57. const MachineFunction &MF) const {
  58. const AMDGPUSubtarget &ST = MF.getSubtarget<AMDGPUSubtarget>();
  59. // FIXME: We should get this information from kernel attributes if it
  60. // is available.
  61. return getShaderType() == ShaderType::COMPUTE ? 256 : ST.getWavefrontSize();
  62. }