blob: 6269dce553f61ea0e39df7acb171bb9f534f0154 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- 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 Stellard96468902014-09-24 01:33:17 +000013#include "AMDGPUSubtarget.h"
Tom Stellardeba61072014-05-02 15:41:42 +000014#include "SIInstrInfo.h"
Tom Stellard96468902014-09-24 01:33:17 +000015#include "llvm/CodeGen/MachineInstrBuilder.h"
Tom Stellardc5cf2f02014-08-21 20:40:54 +000016#include "llvm/CodeGen/MachineFrameInfo.h"
Tom Stellardc149dc02013-11-27 21:23:35 +000017#include "llvm/CodeGen/MachineRegisterInfo.h"
Tom Stellardeba61072014-05-02 15:41:42 +000018#include "llvm/IR/Function.h"
19#include "llvm/IR/LLVMContext.h"
Tom Stellardc149dc02013-11-27 21:23:35 +000020
21#define MAX_LANES 64
Tom Stellard75aadc22012-12-11 21:25:42 +000022
23using namespace llvm;
24
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +000025
26// Pin the vtable to this file.
27void SIMachineFunctionInfo::anchor() {}
28
Tom Stellard75aadc22012-12-11 21:25:42 +000029SIMachineFunctionInfo::SIMachineFunctionInfo(const MachineFunction &MF)
Vincent Lejeuneace6f732013-04-01 21:47:53 +000030 : AMDGPUMachineFunction(MF),
Tom Stellard96468902014-09-24 01:33:17 +000031 TIDReg(AMDGPU::NoRegister),
Matt Arsenault49affb82015-11-25 20:55:12 +000032 ScratchRSrcReg(AMDGPU::NoRegister),
33 LDSWaveSpillSize(0),
Tom Stellardc149dc02013-11-27 21:23:35 +000034 PSInputAddr(0),
Tom Stellard96468902014-09-24 01:33:17 +000035 NumUserSGPRs(0),
Matt Arsenault49affb82015-11-25 20:55:12 +000036 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 Stellardc5cf2f02014-08-21 20:40:54 +000070
71SIMachineFunctionInfo::SpilledReg SIMachineFunctionInfo::getSpilledReg(
72 MachineFunction *MF,
73 unsigned FrameIndex,
74 unsigned SubIdx) {
75 const MachineFrameInfo *FrameInfo = MF->getFrameInfo();
Eric Christopher0795a2e2015-02-19 01:10:55 +000076 const SIRegisterInfo *TRI = static_cast<const SIRegisterInfo *>(
77 MF->getSubtarget<AMDGPUSubtarget>().getRegisterInfo());
Tom Stellardc5cf2f02014-08-21 20:40:54 +000078 MachineRegisterInfo &MRI = MF->getRegInfo();
79 int64_t Offset = FrameInfo->getObjectOffset(FrameIndex);
80 Offset += SubIdx * 4;
81
82 unsigned LaneVGPRIdx = Offset / (64 * 4);
83 unsigned Lane = (Offset / 4) % 64;
84
85 struct SpilledReg Spill;
86
87 if (!LaneVGPRs.count(LaneVGPRIdx)) {
Tom Stellard42fb60e2015-01-14 15:42:31 +000088 unsigned LaneVGPR = TRI->findUnusedRegister(MRI, &AMDGPU::VGPR_32RegClass);
Tom Stellardc5cf2f02014-08-21 20:40:54 +000089 LaneVGPRs[LaneVGPRIdx] = LaneVGPR;
Tom Stellardc5cf2f02014-08-21 20:40:54 +000090
91 // Add this register as live-in to all blocks to avoid machine verifer
92 // complaining about use of an undefined physical register.
93 for (MachineFunction::iterator BI = MF->begin(), BE = MF->end();
94 BI != BE; ++BI) {
95 BI->addLiveIn(LaneVGPR);
96 }
97 }
98
99 Spill.VGPR = LaneVGPRs[LaneVGPRIdx];
100 Spill.Lane = Lane;
101 return Spill;
Tom Stellardc149dc02013-11-27 21:23:35 +0000102}
Tom Stellard96468902014-09-24 01:33:17 +0000103
104unsigned SIMachineFunctionInfo::getMaximumWorkGroupSize(
105 const MachineFunction &MF) const {
Eric Christopher0795a2e2015-02-19 01:10:55 +0000106 const AMDGPUSubtarget &ST = MF.getSubtarget<AMDGPUSubtarget>();
Tom Stellard96468902014-09-24 01:33:17 +0000107 // FIXME: We should get this information from kernel attributes if it
108 // is available.
109 return getShaderType() == ShaderType::COMPUTE ? 256 : ST.getWavefrontSize();
110}