Skip to content

Commit 2ca5dd0

Browse files
weiyu-chengfxbot
authored andcommitted
Refactor code for getting the register size
Change-Id: I6e451921f6aebe559a36ef157222f73ddd0727ca
1 parent bfffc16 commit 2ca5dd0

21 files changed

+226
-233
lines changed

IGC/AdaptorCommon/ImplicitArgs.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,19 @@ ImplicitArgs::ImplicitArgs(const llvm::Function& func , const MetaDataUtils* pMd
232232
{
233233
if (IMPLICIT_ARGS.size() == 0)
234234
{
235-
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::R0, "r0", ImplicitArg::INT, WIAnalysis::UNIFORM, SIZE_GRF / SIZE_DWORD, ImplicitArg::ALIGN_GRF, false));
235+
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::R0, "r0", ImplicitArg::INT, WIAnalysis::UNIFORM, 8, ImplicitArg::ALIGN_GRF, false));
236236

237-
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::PAYLOAD_HEADER, "payloadHeader", ImplicitArg::INT, WIAnalysis::UNIFORM, SIZE_GRF / SIZE_DWORD, ImplicitArg::ALIGN_GRF, true));
237+
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::PAYLOAD_HEADER, "payloadHeader", ImplicitArg::INT, WIAnalysis::UNIFORM, 8, ImplicitArg::ALIGN_GRF, true));
238238
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::WORK_DIM, "workDim", ImplicitArg::INT, WIAnalysis::UNIFORM, 1, ImplicitArg::ALIGN_DWORD, true));
239239

240240
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::NUM_GROUPS, "numWorkGroups", ImplicitArg::INT, WIAnalysis::UNIFORM, 3, ImplicitArg::ALIGN_DWORD, true));
241241
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::GLOBAL_SIZE, "globalSize", ImplicitArg::INT, WIAnalysis::UNIFORM, 3, ImplicitArg::ALIGN_DWORD, true));
242242
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_SIZE, "localSize", ImplicitArg::INT, WIAnalysis::UNIFORM, 3, ImplicitArg::ALIGN_DWORD, true));
243243
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::ENQUEUED_LOCAL_WORK_SIZE, "enqueuedLocalSize", ImplicitArg::INT, WIAnalysis::UNIFORM, 3, ImplicitArg::ALIGN_DWORD, true));
244244

245-
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_ID_X, "localIdX", ImplicitArg::SHORT, WIAnalysis::RANDOM, SIZE_GRF / SIZE_WORD, ImplicitArg::ALIGN_GRF, false));
246-
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_ID_Y, "localIdY", ImplicitArg::SHORT, WIAnalysis::RANDOM, SIZE_GRF / SIZE_WORD, ImplicitArg::ALIGN_GRF, false));
247-
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_ID_Z, "localIdZ", ImplicitArg::SHORT, WIAnalysis::RANDOM, SIZE_GRF / SIZE_WORD, ImplicitArg::ALIGN_GRF, false));
245+
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_ID_X, "localIdX", ImplicitArg::SHORT, WIAnalysis::RANDOM, 16, ImplicitArg::ALIGN_GRF, false));
246+
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_ID_Y, "localIdY", ImplicitArg::SHORT, WIAnalysis::RANDOM, 16, ImplicitArg::ALIGN_GRF, false));
247+
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::LOCAL_ID_Z, "localIdZ", ImplicitArg::SHORT, WIAnalysis::RANDOM, 16, ImplicitArg::ALIGN_GRF, false));
248248

249249
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::CONSTANT_BASE, "constBase", ImplicitArg::CONSTPTR, WIAnalysis::UNIFORM, 1, ImplicitArg::ALIGN_PTR, true));
250250
IMPLICIT_ARGS.push_back(ImplicitArg(ImplicitArg::GLOBAL_BASE, "globalBase", ImplicitArg::GLOBALPTR, WIAnalysis::UNIFORM, 1, ImplicitArg::ALIGN_PTR, true));

IGC/Compiler/CISACodeGen/CISABuilder.cpp

+59-78
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ using namespace llvm;
5858
namespace IGC
5959
{
6060

61-
unsigned int getGRFSize()
62-
{
63-
unsigned int byteSize = 32;
64-
65-
return byteSize;
66-
}
67-
6861
Common_ISA_Exec_Size getExecSize(SIMDMode width)
6962
{
7063
switch(width)
@@ -209,10 +202,11 @@ visaBlockNum(unsigned numElems) {
209202
return static_cast<Common_ISA_SVM_Block_Num>(~0U);
210203
}
211204

212-
static unsigned
213-
GetRawOpndSplitOffset(Common_ISA_Exec_Size fromExecSize,
214-
Common_ISA_Exec_Size toExecSize,
215-
unsigned thePart, CVariable *var) {
205+
unsigned
206+
CEncoder::GetRawOpndSplitOffset(Common_ISA_Exec_Size fromExecSize,
207+
Common_ISA_Exec_Size toExecSize,
208+
unsigned thePart, CVariable *var) const
209+
{
216210
if (!var || var->IsUniform())
217211
return 0;
218212

@@ -226,9 +220,9 @@ GetRawOpndSplitOffset(Common_ISA_Exec_Size fromExecSize,
226220

227221
switch (elemSize) {
228222
case 4:
229-
return thePart * SIZE_GRF * 1;
223+
return thePart * getGRFSize() * 1;
230224
case 8:
231-
return thePart * SIZE_GRF * 2;
225+
return thePart * getGRFSize() * 2;
232226
}
233227

234228
assert(false && "Unknown data type to split!");
@@ -278,6 +272,8 @@ CEncoder::~CEncoder()
278272
{
279273
}
280274

275+
uint32_t CEncoder::getGRFSize() const { return m_program->getGRFSize(); }
276+
281277
void CEncoder::SetProgram(CShader* program)
282278
{
283279
m_program = program;
@@ -429,8 +425,7 @@ void CEncoder::Cmp(e_predicate p, CVariable* dst, CVariable* src0, CVariable* sr
429425
// that is, if the execution size is 16 and the comparison type
430426
// is QW.
431427
bool bNeedSplitting = false;
432-
if (flagDst &&
433-
(GetAluExecSize(dst) == EXEC_SIZE_16) &&
428+
if (flagDst && needsSplitting(GetAluExecSize(dst)) &&
434429
(src0->GetElemSize() > 4 || src1->GetElemSize() > 4))
435430
{
436431
bNeedSplitting = true;
@@ -1003,7 +998,8 @@ bool CEncoder::NeedSplitting(CVariable *var, const SModifier &mod,
1003998
return false;
1004999
// If the data type has more than 4 bytes, i.e. 32 bits, it already crosses
10051000
// 2+ GRFs by itself. There's no need to check further.
1006-
if (elemSize > 4) {
1001+
if (elemSize > 4)
1002+
{
10071003
assert(elemSize == 8 && "Only QWORD is supported so far!");
10081004
assert((isSource || !mod.specialRegion) &&
10091005
"It's expected that there's no special region associated with "
@@ -1193,7 +1189,7 @@ void CEncoder::SplitMDP16To8(CVariable* MDP, uint32_t MDPOfst, uint32_t NumBlks,
11931189

11941190
if (eltBytes > 0)
11951191
{
1196-
const uint32_t GRFElts = SIZE_GRF / eltBytes;
1192+
uint32_t GRFElts = getGRFSize() / eltBytes;
11971193

11981194
if (GRFElts > 0)
11991195
{
@@ -1243,7 +1239,7 @@ void CEncoder::MergeMDP8To16(CVariable* V0, CVariable* V1, uint32_t NumBlks, CVa
12431239
if (eltBytes > 0)
12441240
{
12451241
// Number of elements per GRF
1246-
const uint32_t GRFElts = SIZE_GRF / eltBytes;
1242+
const uint32_t GRFElts = getGRFSize() / eltBytes;
12471243

12481244
if (GRFElts > 0)
12491245
{
@@ -1675,7 +1671,8 @@ void CEncoder::AddPair(CVariable *Lo, CVariable *Hi, CVariable *L0, CVariable *H
16751671
ExecSize == EXEC_SIZE_4 || ExecSize == EXEC_SIZE_2 ||
16761672
ExecSize == EXEC_SIZE_1);
16771673

1678-
if (ExecSize == EXEC_SIZE_16) {
1674+
if (needsSplitting(ExecSize))
1675+
{
16791676
// Have to split it because `acc0` has only 8 elements for 32-bit
16801677
// integer types.
16811678
unsigned NumParts = 2;
@@ -1780,7 +1777,8 @@ void CEncoder::SubPair(CVariable *Lo, CVariable *Hi, CVariable *L0, CVariable *H
17801777
if (L1->GetType() != ISA_TYPE_UD && L1->GetType() != ISA_TYPE_UV) L1 = m_program->BitCast(L1, ISA_TYPE_UD);
17811778
if (H1->GetType() != ISA_TYPE_UD && H1->GetType() != ISA_TYPE_UV) H1 = m_program->BitCast(H1, ISA_TYPE_UD);
17821779

1783-
if (ExecSize == EXEC_SIZE_16) {
1780+
if (needsSplitting(ExecSize))
1781+
{
17841782
// Have to split it because `acc0` has only 8 elements for 32-bit
17851783
// integer types.
17861784
unsigned NumParts = 2;
@@ -2023,7 +2021,7 @@ VISA_RawOpnd* CEncoder::GetRawDestination(CVariable* var, unsigned offset)
20232021
{
20242022
V(vKernel->CreateVISARawOperand(
20252023
dstOpnd, GetVISAVariable(var),
2026-
m_encoderState.m_dstOperand.subVar*SIZE_GRF + offset + var->GetAliasOffset()));
2024+
m_encoderState.m_dstOperand.subVar*getGRFSize() + offset + var->GetAliasOffset()));
20272025
}
20282026
else
20292027
{
@@ -2039,8 +2037,8 @@ void CEncoder::Send(CVariable* dst, CVariable* src, uint exDesc, CVariable* mess
20392037
m_encoderState.m_simdSize = m_encoderState.m_uniformSIMDSize;
20402038
}
20412039
unsigned char sendc = isSendc ? 1 : 0;
2042-
unsigned char srcSize = src->GetSize()/SIZE_GRF;
2043-
unsigned char dstSize = dst ? dst->GetSize()/SIZE_GRF : 0;
2040+
unsigned char srcSize = src->GetSize()/getGRFSize();
2041+
unsigned char dstSize = dst ? dst->GetSize()/getGRFSize() : 0;
20442042
VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
20452043
VISA_RawOpnd *srcOpnd0 = GetRawSource(src);
20462044
VISA_RawOpnd *dstOpnd = GetRawDestination(dst);
@@ -2076,9 +2074,9 @@ void CEncoder::Sends(CVariable* dst, CVariable* src0, CVariable* src1, uint ffid
20762074
m_encoderState.m_simdSize = m_encoderState.m_uniformSIMDSize;
20772075
}
20782076
unsigned char sendc = isSendc ? 1 : 0;
2079-
unsigned char src0Size = src0->GetSize()/SIZE_GRF;
2080-
unsigned char src1Size = src1 ? src1->GetSize() / SIZE_GRF : 0;
2081-
unsigned char dstSize = dst ? dst->GetSize()/SIZE_GRF : 0;
2077+
unsigned char src0Size = src0->GetSize()/getGRFSize();
2078+
unsigned char src1Size = src1 ? src1->GetSize() / getGRFSize() : 0;
2079+
unsigned char dstSize = dst ? dst->GetSize()/getGRFSize() : 0;
20822080
VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
20832081
VISA_RawOpnd *srcOpnd0 = GetRawSource(src0);
20842082
VISA_RawOpnd *srcOpnd1 = GetRawSource(src1);
@@ -2875,10 +2873,10 @@ void CEncoder::TypedReadWrite(
28752873
VISA_StateOpndHandle* pSurfStateOpndHandle = GetVISASurfaceOpnd(resource);
28762874

28772875
// TODO unify the way we calculate offset for raw sources, maybe we shouldn't use offset at all
2878-
VISA_RawOpnd* pUOffset = GetRawSource(pU, m_encoderState.m_srcOperand[0].subVar*SIZE_GRF);
2879-
VISA_RawOpnd* pVOffset = GetRawSource(pV, m_encoderState.m_srcOperand[1].subVar*SIZE_GRF);
2880-
VISA_RawOpnd* pROffset = GetRawSource(pR, m_encoderState.m_srcOperand[2].subVar*SIZE_GRF);
2881-
VISA_RawOpnd* pLODOffset = GetRawSource(pLOD, m_encoderState.m_srcOperand[3].subVar*SIZE_GRF);
2876+
VISA_RawOpnd* pUOffset = GetRawSource(pU, m_encoderState.m_srcOperand[0].subVar*getGRFSize());
2877+
VISA_RawOpnd* pVOffset = GetRawSource(pV, m_encoderState.m_srcOperand[1].subVar*getGRFSize());
2878+
VISA_RawOpnd* pROffset = GetRawSource(pR, m_encoderState.m_srcOperand[2].subVar*getGRFSize());
2879+
VISA_RawOpnd* pLODOffset = GetRawSource(pLOD, m_encoderState.m_srcOperand[3].subVar*getGRFSize());
28822880
VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
28832881
assert(m_encoderState.m_dstOperand.subVar == 0);
28842882

@@ -4621,7 +4619,7 @@ void CEncoder::GatherA64(CVariable *dst,
46214619
addressOpnd, dstOpnd));
46224620
}
46234621

4624-
uint32_t dstOfstBytes = dst->GetAliasOffset() + m_encoderState.m_dstOperand.subVar * SIZE_GRF;
4622+
uint32_t dstOfstBytes = dst->GetAliasOffset() + m_encoderState.m_dstOperand.subVar * getGRFSize();
46254623
MergeMDP8To16(V0, V1, numElems, dst, dstOfstBytes);
46264624
}
46274625
return;
@@ -4863,60 +4861,43 @@ void CEncoder::Gather4ScaledNd(CVariable *dst,
48634861
addressOpnd, dstOpnd));
48644862
}
48654863

4866-
4867-
void CEncoder::Gather4Scaled(CVariable *dst,
4868-
const ResourceDescriptor& resource,
4869-
CVariable *offset) {
4870-
unsigned nd = dst->GetSize();
4871-
if (dst->IsUniform())
4864+
uint32_t CEncoder::getNumChannels(CVariable* var) const
4865+
{
4866+
unsigned nd = var->GetSize();
4867+
if (var->IsUniform())
48724868
{
4873-
if (nd > SIZE_GRF)
4869+
if (nd > getGRFSize())
48744870
{
4875-
assert(false && "Unknown DstSize!");
4876-
return;
4871+
assert(false && "Unknown Variable Size!");
48774872
}
4878-
nd = 1;
4873+
return 1;
48794874
}
48804875
else
48814876
{
4882-
switch (m_encoderState.m_simdSize) {
4883-
default: assert(false && "Unknown SIMD size!"); return;
4877+
switch (m_encoderState.m_simdSize)
4878+
{
4879+
default: assert(false && "Unknown SIMD size!"); return 1;
48844880
case SIMDMode::SIMD8:
4885-
nd = nd / (SIZE_GRF * 1);
4886-
break;
4881+
return nd / (8 * SIZE_DWORD);
48874882
case SIMDMode::SIMD16:
4888-
nd = nd / (SIZE_GRF * 2);
4889-
break;
4883+
return nd / (16 * SIZE_DWORD);
48904884
}
48914885
}
4886+
return 1;
4887+
}
4888+
4889+
void CEncoder::Gather4Scaled(CVariable *dst,
4890+
const ResourceDescriptor& resource,
4891+
CVariable *offset)
4892+
{
4893+
unsigned nd = getNumChannels(dst);
48924894
Gather4ScaledNd(dst, resource, offset, nd);
48934895
}
48944896

48954897
void CEncoder::Scatter4Scaled(CVariable *src,
48964898
const ResourceDescriptor& resource,
48974899
CVariable *offset) {
4898-
unsigned nd = src->GetSize();
4899-
if (src->IsUniform())
4900-
{
4901-
if (nd > SIZE_GRF)
4902-
{
4903-
assert(false && "Unknown SrcSize!");
4904-
return;
4905-
}
4906-
nd = 1;
4907-
}
4908-
else
4909-
{
4910-
switch (m_encoderState.m_simdSize) {
4911-
default: assert(false && "Unknown SIMD size!"); return;
4912-
case SIMDMode::SIMD8:
4913-
nd = nd / (SIZE_GRF * 1);
4914-
break;
4915-
case SIMDMode::SIMD16:
4916-
nd = nd / (SIZE_GRF * 2);
4917-
break;
4918-
}
4919-
}
4900+
unsigned nd = getNumChannels(src);
49204901

49214902
VISA_StateOpndHandle* surfaceOpnd = GetVISASurfaceOpnd(resource);
49224903
VISA_PredOpnd* predOpnd = GetFlagOperand(m_encoderState.m_flag);
@@ -4942,15 +4923,15 @@ void CEncoder::Scatter4Scaled(CVariable *src,
49424923
void CEncoder::Gather4A64(CVariable *dst, CVariable *offset) {
49434924
assert(dst->GetElemSize() == 4 && "Gather4 must have 4-byte element");
49444925

4945-
uint32_t dstOfstBytes = m_encoderState.m_dstOperand.subVar * SIZE_GRF + dst->GetAliasOffset();
4926+
uint32_t dstOfstBytes = m_encoderState.m_dstOperand.subVar * getGRFSize() + dst->GetAliasOffset();
49464927
unsigned nd = dst->GetSize();
49474928
switch (m_encoderState.m_simdSize) {
49484929
default: assert(false && "Unknown SIMD size!"); return;
49494930
case SIMDMode::SIMD8:
4950-
nd = nd / (SIZE_GRF * 1);
4931+
nd = nd / (8 * SIZE_DWORD);
49514932
break;
49524933
case SIMDMode::SIMD16:
4953-
nd = nd / (SIZE_GRF * 2);
4934+
nd = nd / (16 * SIZE_DWORD);
49544935
break;
49554936
}
49564937

@@ -5037,10 +5018,10 @@ void CEncoder::Scatter4A64(CVariable *src, CVariable *offset) {
50375018
switch (m_encoderState.m_simdSize) {
50385019
default: assert(false && "Unknown SIMD size!"); return;
50395020
case SIMDMode::SIMD8:
5040-
nd = nd / (SIZE_GRF * 1);
5021+
nd = nd / (8 * SIZE_DWORD);
50415022
break;
50425023
case SIMDMode::SIMD16:
5043-
nd = nd / (SIZE_GRF * 2);
5024+
nd = nd / (16 * SIZE_DWORD);
50445025
break;
50455026
}
50465027

@@ -5390,11 +5371,11 @@ void CEncoder::SetVISAWaTable(WA_TABLE const& waTable)
53905371
void CEncoder::GetRowAndColOffset(CVariable* var, unsigned int subVar, unsigned int subReg, unsigned char& rowOff, unsigned char& colOff)
53915372
{
53925373
unsigned int varTypeSize = GetCISADataTypeSize(var->GetType());
5393-
unsigned int offset = var->GetAliasOffset() + subVar * SIZE_GRF + subReg * varTypeSize;
5394-
assert((offset%SIZE_GRF) % varTypeSize == 0 && "offset has to be aligned on element size");
5395-
rowOff = int_cast<unsigned char>(offset / SIZE_GRF);
5374+
unsigned int offset = var->GetAliasOffset() + subVar * getGRFSize() + subReg * varTypeSize;
5375+
assert((offset%getGRFSize()) % varTypeSize == 0 && "offset has to be aligned on element size");
5376+
rowOff = int_cast<unsigned char>(offset / getGRFSize());
53965377
assert(varTypeSize != 0);
5397-
colOff = int_cast<unsigned char>((offset%SIZE_GRF) / varTypeSize);
5378+
colOff = int_cast<unsigned char>((offset%getGRFSize()) / varTypeSize);
53985379
}
53995380

54005381
void CEncoder::Loc(unsigned int line)

IGC/Compiler/CISACodeGen/CISABuilder.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,19 @@ class CEncoder
486486
void CreateFunctionSymbolTable(void*& buffer, unsigned& bufferSize, unsigned& tableEntries);
487487
void CreateFunctionRelocationTable(void*& buffer, unsigned& bufferSize, unsigned& tableEntries);
488488

489+
uint32_t getGRFSize() const;
490+
491+
bool needsSplitting(Common_ISA_Exec_Size ExecSize) const
492+
{
493+
return ExecSize == EXEC_SIZE_16;
494+
}
495+
496+
unsigned GetRawOpndSplitOffset(Common_ISA_Exec_Size fromExecSize,
497+
Common_ISA_Exec_Size toExecSize,
498+
unsigned thePart, CVariable *var) const;
499+
500+
uint32_t getNumChannels(CVariable* var) const;
501+
489502
protected:
490503
// encoder states
491504
SEncoderState m_encoderState;

IGC/Compiler/CISACodeGen/CISACodeGen.h

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ enum e_alignment : unsigned char
7171
EALIGN_AUTO
7272
};
7373

74-
7574
static const unsigned int alignmentSize[] =
7675
{
7776
1,

0 commit comments

Comments
 (0)