2012-12-12 05:25:42 +08:00
|
|
|
//===- SIMachineFunctionInfo.h - SIMachineFunctionInfo interface -*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-11 16:00:27 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_SIMACHINEFUNCTIONINFO_H
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2013-04-02 05:47:53 +08:00
|
|
|
#include "AMDGPUMachineFunction.h"
|
2014-09-24 09:33:17 +08:00
|
|
|
#include "SIRegisterInfo.h"
|
2013-11-28 05:23:35 +08:00
|
|
|
#include <map>
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2013-11-28 05:23:35 +08:00
|
|
|
class MachineRegisterInfo;
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
/// This class keeps track of the SPI_SP_INPUT_ADDR config register, which
|
|
|
|
/// tells the hardware which interpolation parameters to load.
|
2016-03-11 16:00:27 +08:00
|
|
|
class SIMachineFunctionInfo final : public AMDGPUMachineFunction {
|
2015-12-01 05:16:03 +08:00
|
|
|
// FIXME: This should be removed and getPreloadedValue moved here.
|
|
|
|
friend struct SIRegisterInfo;
|
2014-04-29 15:57:24 +08:00
|
|
|
void anchor() override;
|
2014-09-24 09:33:17 +08:00
|
|
|
|
|
|
|
unsigned TIDReg;
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
// Registers that may be reserved for spilling purposes. These may be the same
|
|
|
|
// as the input registers.
|
2015-11-26 04:55:12 +08:00
|
|
|
unsigned ScratchRSrcReg;
|
2015-12-01 05:16:03 +08:00
|
|
|
unsigned ScratchWaveOffsetReg;
|
|
|
|
|
|
|
|
// Input registers setup for the HSA ABI.
|
|
|
|
// User SGPRs in allocation order.
|
|
|
|
unsigned PrivateSegmentBufferUserSGPR;
|
|
|
|
unsigned DispatchPtrUserSGPR;
|
|
|
|
unsigned QueuePtrUserSGPR;
|
|
|
|
unsigned KernargSegmentPtrUserSGPR;
|
|
|
|
unsigned DispatchIDUserSGPR;
|
|
|
|
unsigned FlatScratchInitUserSGPR;
|
|
|
|
unsigned PrivateSegmentSizeUserSGPR;
|
|
|
|
unsigned GridWorkGroupCountXUserSGPR;
|
|
|
|
unsigned GridWorkGroupCountYUserSGPR;
|
|
|
|
unsigned GridWorkGroupCountZUserSGPR;
|
|
|
|
|
|
|
|
// System SGPRs in allocation order.
|
|
|
|
unsigned WorkGroupIDXSystemSGPR;
|
|
|
|
unsigned WorkGroupIDYSystemSGPR;
|
|
|
|
unsigned WorkGroupIDZSystemSGPR;
|
|
|
|
unsigned WorkGroupInfoSystemSGPR;
|
|
|
|
unsigned PrivateSegmentWaveByteOffsetSystemSGPR;
|
2015-11-26 04:55:12 +08:00
|
|
|
|
2016-01-13 19:45:36 +08:00
|
|
|
// Graphics info.
|
|
|
|
unsigned PSInputAddr;
|
2016-01-14 01:23:09 +08:00
|
|
|
bool ReturnsVoid;
|
2016-01-13 19:45:36 +08:00
|
|
|
|
AMDGPU: allow specifying a workgroup size that needs to fit in a compute unit
Summary:
For GL_ARB_compute_shader we need to support workgroup sizes of at least 1024. However, if we want to allow large workgroup sizes, we may need to use less registers, as we have to run more waves per SIMD.
This patch adds an attribute to specify the maximum work group size the compiled program needs to support. It defaults, to 256, as that has no wave restrictions.
Reducing the number of registers available is done similarly to how the registers were reserved for chips with the sgpr init bug.
Reviewers: mareko, arsenm, tstellarAMD, nhaehnle
Subscribers: FireBurn, kerberizer, llvm-commits, arsenm
Differential Revision: http://reviews.llvm.org/D18340
Patch By: Bas Nieuwenhuizen
llvm-svn: 266337
2016-04-15 00:27:07 +08:00
|
|
|
unsigned MaximumWorkGroupSize;
|
|
|
|
|
2016-05-25 02:37:18 +08:00
|
|
|
// Number of reserved VGPRs for debugger usage.
|
|
|
|
unsigned DebuggerReservedVGPRCount;
|
2016-04-27 01:24:40 +08:00
|
|
|
|
2015-11-26 04:55:12 +08:00
|
|
|
public:
|
|
|
|
// FIXME: Make private
|
|
|
|
unsigned LDSWaveSpillSize;
|
2016-01-13 19:45:36 +08:00
|
|
|
unsigned PSInputEna;
|
2015-11-26 04:55:12 +08:00
|
|
|
std::map<unsigned, unsigned> LaneVGPRs;
|
|
|
|
unsigned ScratchOffsetReg;
|
|
|
|
unsigned NumUserSGPRs;
|
2015-12-01 05:16:03 +08:00
|
|
|
unsigned NumSystemSGPRs;
|
2015-11-26 04:55:12 +08:00
|
|
|
|
|
|
|
private:
|
2015-11-05 13:27:10 +08:00
|
|
|
bool HasSpilledSGPRs;
|
2015-01-14 23:42:31 +08:00
|
|
|
bool HasSpilledVGPRs;
|
2016-02-12 14:31:30 +08:00
|
|
|
bool HasNonSpillStackObjects;
|
|
|
|
bool HasFlatInstructions;
|
2014-09-24 09:33:17 +08:00
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
// Feature bits required for inputs passed in user SGPRs.
|
|
|
|
bool PrivateSegmentBuffer : 1;
|
2015-11-26 04:55:12 +08:00
|
|
|
bool DispatchPtr : 1;
|
|
|
|
bool QueuePtr : 1;
|
|
|
|
bool DispatchID : 1;
|
|
|
|
bool KernargSegmentPtr : 1;
|
|
|
|
bool FlatScratchInit : 1;
|
|
|
|
bool GridWorkgroupCountX : 1;
|
|
|
|
bool GridWorkgroupCountY : 1;
|
|
|
|
bool GridWorkgroupCountZ : 1;
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
// Feature bits required for inputs passed in system SGPRs.
|
2015-11-26 04:55:12 +08:00
|
|
|
bool WorkGroupIDX : 1; // Always initialized.
|
|
|
|
bool WorkGroupIDY : 1;
|
|
|
|
bool WorkGroupIDZ : 1;
|
|
|
|
bool WorkGroupInfo : 1;
|
2015-12-01 05:16:03 +08:00
|
|
|
bool PrivateSegmentWaveByteOffset : 1;
|
2015-11-26 04:55:12 +08:00
|
|
|
|
|
|
|
bool WorkItemIDX : 1; // Always initialized.
|
|
|
|
bool WorkItemIDY : 1;
|
|
|
|
bool WorkItemIDZ : 1;
|
2013-11-28 05:23:35 +08:00
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
MCPhysReg getNextUserSGPR() const {
|
|
|
|
assert(NumSystemSGPRs == 0 && "System SGPRs must be added after user SGPRs");
|
|
|
|
return AMDGPU::SGPR0 + NumUserSGPRs;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCPhysReg getNextSystemSGPR() const {
|
|
|
|
return AMDGPU::SGPR0 + NumUserSGPRs + NumSystemSGPRs;
|
|
|
|
}
|
|
|
|
|
2015-11-26 04:55:12 +08:00
|
|
|
public:
|
2013-11-28 05:23:35 +08:00
|
|
|
struct SpilledReg {
|
|
|
|
unsigned VGPR;
|
|
|
|
int Lane;
|
|
|
|
SpilledReg(unsigned R, int L) : VGPR (R), Lane (L) { }
|
2016-03-05 02:31:18 +08:00
|
|
|
SpilledReg() : VGPR(AMDGPU::NoRegister), Lane(-1) { }
|
2013-11-28 05:23:35 +08:00
|
|
|
bool hasLane() { return Lane != -1;}
|
2016-03-05 02:31:18 +08:00
|
|
|
bool hasReg() { return VGPR != AMDGPU::NoRegister;}
|
2013-11-28 05:23:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// SIMachineFunctionInfo definition
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
SIMachineFunctionInfo(const MachineFunction &MF);
|
2014-08-22 04:40:54 +08:00
|
|
|
SpilledReg getSpilledReg(MachineFunction *MF, unsigned FrameIndex,
|
|
|
|
unsigned SubIdx);
|
2014-09-24 09:33:17 +08:00
|
|
|
bool hasCalculatedTID() const { return TIDReg != AMDGPU::NoRegister; };
|
|
|
|
unsigned getTIDReg() const { return TIDReg; };
|
|
|
|
void setTIDReg(unsigned Reg) { TIDReg = Reg; }
|
2015-11-05 13:27:10 +08:00
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
// Add user SGPRs.
|
|
|
|
unsigned addPrivateSegmentBuffer(const SIRegisterInfo &TRI);
|
|
|
|
unsigned addDispatchPtr(const SIRegisterInfo &TRI);
|
|
|
|
unsigned addQueuePtr(const SIRegisterInfo &TRI);
|
|
|
|
unsigned addKernargSegmentPtr(const SIRegisterInfo &TRI);
|
2016-02-12 14:31:30 +08:00
|
|
|
unsigned addFlatScratchInit(const SIRegisterInfo &TRI);
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
// Add system SGPRs.
|
|
|
|
unsigned addWorkGroupIDX() {
|
|
|
|
WorkGroupIDXSystemSGPR = getNextSystemSGPR();
|
|
|
|
NumSystemSGPRs += 1;
|
|
|
|
return WorkGroupIDXSystemSGPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned addWorkGroupIDY() {
|
|
|
|
WorkGroupIDYSystemSGPR = getNextSystemSGPR();
|
|
|
|
NumSystemSGPRs += 1;
|
|
|
|
return WorkGroupIDYSystemSGPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned addWorkGroupIDZ() {
|
|
|
|
WorkGroupIDZSystemSGPR = getNextSystemSGPR();
|
|
|
|
NumSystemSGPRs += 1;
|
|
|
|
return WorkGroupIDZSystemSGPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned addWorkGroupInfo() {
|
|
|
|
WorkGroupInfoSystemSGPR = getNextSystemSGPR();
|
|
|
|
NumSystemSGPRs += 1;
|
|
|
|
return WorkGroupInfoSystemSGPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned addPrivateSegmentWaveByteOffset() {
|
|
|
|
PrivateSegmentWaveByteOffsetSystemSGPR = getNextSystemSGPR();
|
|
|
|
NumSystemSGPRs += 1;
|
|
|
|
return PrivateSegmentWaveByteOffsetSystemSGPR;
|
|
|
|
}
|
|
|
|
|
2016-04-15 00:27:03 +08:00
|
|
|
void setPrivateSegmentWaveByteOffset(unsigned Reg) {
|
|
|
|
PrivateSegmentWaveByteOffsetSystemSGPR = Reg;
|
|
|
|
}
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
bool hasPrivateSegmentBuffer() const {
|
|
|
|
return PrivateSegmentBuffer;
|
|
|
|
}
|
|
|
|
|
2015-11-26 04:55:12 +08:00
|
|
|
bool hasDispatchPtr() const {
|
|
|
|
return DispatchPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasQueuePtr() const {
|
|
|
|
return QueuePtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasDispatchID() const {
|
|
|
|
return DispatchID;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasKernargSegmentPtr() const {
|
|
|
|
return KernargSegmentPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasFlatScratchInit() const {
|
|
|
|
return FlatScratchInit;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasGridWorkgroupCountX() const {
|
|
|
|
return GridWorkgroupCountX;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasGridWorkgroupCountY() const {
|
|
|
|
return GridWorkgroupCountY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasGridWorkgroupCountZ() const {
|
|
|
|
return GridWorkgroupCountZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWorkGroupIDX() const {
|
|
|
|
return WorkGroupIDX;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWorkGroupIDY() const {
|
|
|
|
return WorkGroupIDY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWorkGroupIDZ() const {
|
|
|
|
return WorkGroupIDZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWorkGroupInfo() const {
|
|
|
|
return WorkGroupInfo;
|
|
|
|
}
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
bool hasPrivateSegmentWaveByteOffset() const {
|
|
|
|
return PrivateSegmentWaveByteOffset;
|
|
|
|
}
|
|
|
|
|
2015-11-26 04:55:12 +08:00
|
|
|
bool hasWorkItemIDX() const {
|
|
|
|
return WorkItemIDX;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWorkItemIDY() const {
|
|
|
|
return WorkItemIDY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasWorkItemIDZ() const {
|
|
|
|
return WorkItemIDZ;
|
|
|
|
}
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
unsigned getNumUserSGPRs() const {
|
|
|
|
return NumUserSGPRs;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumPreloadedSGPRs() const {
|
|
|
|
return NumUserSGPRs + NumSystemSGPRs;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getPrivateSegmentWaveByteOffsetSystemSGPR() const {
|
|
|
|
return PrivateSegmentWaveByteOffsetSystemSGPR;
|
|
|
|
}
|
|
|
|
|
2015-11-26 04:55:12 +08:00
|
|
|
/// \brief Returns the physical register reserved for use as the resource
|
|
|
|
/// descriptor for scratch accesses.
|
|
|
|
unsigned getScratchRSrcReg() const {
|
|
|
|
return ScratchRSrcReg;
|
|
|
|
}
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
void setScratchRSrcReg(unsigned Reg) {
|
|
|
|
assert(Reg != AMDGPU::NoRegister && "Should never be unset");
|
|
|
|
ScratchRSrcReg = Reg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getScratchWaveOffsetReg() const {
|
|
|
|
return ScratchWaveOffsetReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setScratchWaveOffsetReg(unsigned Reg) {
|
|
|
|
assert(Reg != AMDGPU::NoRegister && "Should never be unset");
|
|
|
|
ScratchWaveOffsetReg = Reg;
|
|
|
|
}
|
2015-11-26 04:55:12 +08:00
|
|
|
|
2016-04-26 03:27:24 +08:00
|
|
|
unsigned getQueuePtrUserSGPR() const {
|
|
|
|
return QueuePtrUserSGPR;
|
|
|
|
}
|
|
|
|
|
2015-11-05 13:27:10 +08:00
|
|
|
bool hasSpilledSGPRs() const {
|
|
|
|
return HasSpilledSGPRs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setHasSpilledSGPRs(bool Spill = true) {
|
|
|
|
HasSpilledSGPRs = Spill;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSpilledVGPRs() const {
|
|
|
|
return HasSpilledVGPRs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setHasSpilledVGPRs(bool Spill = true) {
|
|
|
|
HasSpilledVGPRs = Spill;
|
|
|
|
}
|
2014-09-24 09:33:17 +08:00
|
|
|
|
2016-02-12 14:31:30 +08:00
|
|
|
bool hasNonSpillStackObjects() const {
|
|
|
|
return HasNonSpillStackObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setHasNonSpillStackObjects(bool StackObject = true) {
|
|
|
|
HasNonSpillStackObjects = StackObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasFlatInstructions() const {
|
|
|
|
return HasFlatInstructions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setHasFlatInstructions(bool UseFlat = true) {
|
|
|
|
HasFlatInstructions = UseFlat;
|
|
|
|
}
|
|
|
|
|
2016-01-13 19:45:36 +08:00
|
|
|
unsigned getPSInputAddr() const {
|
|
|
|
return PSInputAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPSInputAllocated(unsigned Index) const {
|
|
|
|
return PSInputAddr & (1 << Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void markPSInputAllocated(unsigned Index) {
|
|
|
|
PSInputAddr |= 1 << Index;
|
|
|
|
}
|
|
|
|
|
2016-01-14 01:23:09 +08:00
|
|
|
bool returnsVoid() const {
|
|
|
|
return ReturnsVoid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIfReturnsVoid(bool Value) {
|
|
|
|
ReturnsVoid = Value;
|
|
|
|
}
|
|
|
|
|
2016-05-25 02:37:18 +08:00
|
|
|
/// \returns Number of reserved VGPRs for debugger usage.
|
|
|
|
unsigned getDebuggerReservedVGPRCount() const {
|
|
|
|
return DebuggerReservedVGPRCount;
|
2016-04-27 01:24:40 +08:00
|
|
|
}
|
|
|
|
|
2014-09-24 09:33:17 +08:00
|
|
|
unsigned getMaximumWorkGroupSize(const MachineFunction &MF) const;
|
2012-12-12 05:25:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace llvm
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#endif
|