Skip to content

Commit 48b46d6

Browse files
mmereckiigcbot
authored andcommitted
Update CheckInstrTypes pass to provide more detailed statistics wrt. the global
memory and storage buffer accesses.
1 parent 83ff70f commit 48b46d6

File tree

4 files changed

+98
-13
lines changed

4 files changed

+98
-13
lines changed

IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ CheckInstrTypes::CheckInstrTypes(IGC::SInstrTypes* instrList) : FunctionPass(ID)
7373
instrList->hasPointer = false;
7474
instrList->hasGenericAddressSpacePointers = false;
7575
instrList->hasLocalLoadStore = false;
76-
instrList->hasBufferStore = false;
76+
instrList->hasGlobalLoad = false;
77+
instrList->hasGlobalStore = false;
78+
instrList->hasStorageBufferLoad = false;
79+
instrList->hasStorageBufferStore = false;
7780
instrList->hasSubroutines = false;
7881
instrList->hasPrimitiveAlloca = false;
7982
instrList->hasNonPrimitiveAlloca = false;
@@ -85,6 +88,7 @@ CheckInstrTypes::CheckInstrTypes(IGC::SInstrTypes* instrList) : FunctionPass(ID)
8588
instrList->hasAtomics = false;
8689
instrList->hasBarrier = false;
8790
instrList->hasDiscard = false;
91+
instrList->hasTypedRead = false;
8892
instrList->hasTypedwrite = false;
8993
instrList->mayHaveIndirectOperands = false;
9094
instrList->hasUniformAssumptions = false;
@@ -238,6 +242,9 @@ void CheckInstrTypes::visitCallInst(CallInst& C)
238242
case GenISAIntrinsic::GenISA_is_uniform:
239243
g_InstrTypes->hasUniformAssumptions = true;
240244
break;
245+
case GenISAIntrinsic::GenISA_typedread:
246+
g_InstrTypes->hasTypedRead = true;
247+
break;
241248
case GenISAIntrinsic::GenISA_typedwrite:
242249
g_InstrTypes->hasTypedwrite = true;
243250
break;
@@ -260,6 +267,28 @@ void CheckInstrTypes::visitCallInst(CallInst& C)
260267
case GenISAIntrinsic::GenISA_PullCentroidBarys:
261268
g_InstrTypes->hasPullBary = true;
262269
break;
270+
case GenISAIntrinsic::GenISA_ldraw_indexed:
271+
case GenISAIntrinsic::GenISA_ldrawvector_indexed:
272+
{
273+
BufferType bufferType = DecodeBufferType(
274+
CI->getArgOperand(0)->getType()->getPointerAddressSpace());
275+
if (bufferType == UAV || bufferType == BINDLESS)
276+
{
277+
g_InstrTypes->hasStorageBufferLoad = true;
278+
}
279+
break;
280+
}
281+
case GenISAIntrinsic::GenISA_storeraw_indexed:
282+
case GenISAIntrinsic::GenISA_storerawvector_indexed:
283+
{
284+
BufferType bufferType = DecodeBufferType(
285+
CI->getArgOperand(0)->getType()->getPointerAddressSpace());
286+
if (bufferType == UAV || bufferType == BINDLESS)
287+
{
288+
g_InstrTypes->hasStorageBufferStore = true;
289+
}
290+
break;
291+
}
263292
default:
264293
break;
265294
}
@@ -326,13 +355,27 @@ void CheckInstrTypes::visitLoadInst(LoadInst& I)
326355
{
327356
g_InstrTypes->numInsts++;
328357
g_InstrTypes->hasLoadStore = true;
329-
if (I.getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
358+
uint as = I.getPointerAddressSpace();
359+
switch (as)
330360
{
361+
case ADDRESS_SPACE_LOCAL:
331362
g_InstrTypes->hasLocalLoadStore = true;
332-
}
333-
if (I.getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
334-
{
363+
break;
364+
case ADDRESS_SPACE_GENERIC:
335365
g_InstrTypes->hasGenericAddressSpacePointers = true;
366+
break;
367+
case ADDRESS_SPACE_GLOBAL:
368+
g_InstrTypes->hasGlobalLoad = true;
369+
break;
370+
default:
371+
{
372+
BufferType bufferType = DecodeBufferType(as);
373+
if (bufferType == UAV || bufferType == BINDLESS)
374+
{
375+
g_InstrTypes->hasStorageBufferLoad = true;
376+
}
377+
break;
378+
}
336379
}
337380
}
338381

@@ -345,17 +388,26 @@ void CheckInstrTypes::visitStoreInst(StoreInst& I)
345388
{
346389
g_InstrTypes->psHasSideEffect = true;
347390
}
348-
if (as == ADDRESS_SPACE_LOCAL)
391+
switch (as)
349392
{
393+
case ADDRESS_SPACE_LOCAL:
350394
g_InstrTypes->hasLocalLoadStore = true;
351-
}
352-
if (as == ADDRESS_SPACE_GENERIC)
353-
{
395+
break;
396+
case ADDRESS_SPACE_GENERIC:
354397
g_InstrTypes->hasGenericAddressSpacePointers = true;
355-
}
356-
if (as == ADDRESS_SPACE_GLOBAL)
398+
break;
399+
case ADDRESS_SPACE_GLOBAL:
400+
g_InstrTypes->hasGlobalStore = true;
401+
break;
402+
default:
357403
{
358-
g_InstrTypes->hasBufferStore = true;
404+
BufferType bufferType = DecodeBufferType(as);
405+
if (bufferType == UAV || bufferType == BINDLESS)
406+
{
407+
g_InstrTypes->hasStorageBufferStore = true;
408+
}
409+
break;
410+
}
359411
}
360412
}
361413

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,34 @@ namespace IGC
188188
}
189189
return BUFFER_TYPE_UNKNOWN;
190190
}
191+
192+
///
193+
/// returns buffer type from addressspace
194+
///
195+
BufferType DecodeBufferType(unsigned addrSpace)
196+
{
197+
switch (addrSpace)
198+
{
199+
case ADDRESS_SPACE_CONSTANT:
200+
return STATELESS_READONLY;
201+
case ADDRESS_SPACE_LOCAL:
202+
return SLM;
203+
case ADDRESS_SPACE_GLOBAL:
204+
return STATELESS;
205+
default:
206+
break;
207+
}
208+
GFXResourceAddrSpace temp;
209+
temp.u32Val = addrSpace;
210+
BufferType type = BUFFER_TYPE_UNKNOWN;
211+
if (addrSpace > ADDRESS_SPACE_NUM_ADDRESSES &&
212+
(temp.bits.bufType - 1) < BUFFER_TYPE_UNKNOWN)
213+
{
214+
type = static_cast<BufferType>(temp.bits.bufType - 1);
215+
}
216+
return type;
217+
}
218+
191219
///
192220
/// returns constant buffer load offset
193221
///

IGC/Compiler/CISACodeGen/helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ namespace IGC
192192
bool isStatefulAddrSpace(unsigned AS);
193193

194194
BufferType DecodeAS4GFXResource(unsigned addrSpace, bool& directIdx, unsigned& bufId);
195+
BufferType DecodeBufferType(unsigned addrSpace);
195196
int getConstantBufferLoadOffset(llvm::LoadInst* ld);
196197

197198
bool isDummyBasicBlock(llvm::BasicBlock* BB);

IGC/Compiler/CodeGenPublic.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ namespace IGC
244244
bool hasSel;
245245
bool hasPointer;
246246
bool hasLocalLoadStore;
247-
bool hasBufferStore;
247+
bool hasGlobalLoad; // has (stateless) loads from global addresspace
248+
bool hasGlobalStore; // has (stateless) stores to global addresspace
249+
bool hasStorageBufferLoad; // has (stateful) loads from storage buffers (UAV/SSBO)
250+
bool hasStorageBufferStore; // has (stateful) stores to storage buffers (UAV/SSBO)
248251
bool hasSubroutines;
249252
bool hasPrimitiveAlloca;
250253
bool hasNonPrimitiveAlloca;
@@ -257,6 +260,7 @@ namespace IGC
257260
bool hasAtomics;
258261
bool hasBarrier; //<! true if module has thread group barrier
259262
bool hasDiscard;
263+
bool hasTypedRead;
260264
bool hasTypedwrite;
261265
bool mayHaveIndirectOperands; //<! true if code may have indirect operands like r5[a0].
262266
bool hasUniformAssumptions;

0 commit comments

Comments
 (0)