Skip to content

Commit 4fbd57a

Browse files
wpanpaigeale
authored andcommitted
- defer dynamic GAS resolution. - invoke static GAS resolution
in optimizeIR. - check if a generic pointer is present or not. Change-Id: Ie5aed19e899e50421a55421ee2201843fea09cdb
1 parent 376f04d commit 4fbd57a

File tree

5 files changed

+68
-18
lines changed

5 files changed

+68
-18
lines changed

IGC/AdaptorOCL/UnifyIROCL.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static void CommonOCLBasedPasses(
324324

325325
mpm.add(new BreakConstantExpr());
326326

327-
if(IGC_IS_FLAG_ENABLED(EnableGASResolver))
327+
if (IGC_IS_FLAG_ENABLED(EnableGASResolver))
328328
{
329329
// Add fix up of illegal `addrspacecast` in respect to OCL 2.0 spec.
330330
mpm.add(createFixAddrSpaceCastPass());
@@ -416,9 +416,6 @@ static void CommonOCLBasedPasses(
416416
// forget setting math flags. We expect the generic llvm optimizations after the unification
417417
// (optimizeIR()) will fully take advantage of the flags.
418418
mpm.add(new SetFastMathFlags());
419-
420-
mpm.add(createGenericAddressDynamicResolutionPass());
421-
422419
mpm.add(new FixResourcePtr());
423420

424421
bool isOptDisabled = pContext->getModuleMetaData()->compOpt.OptDisable;

IGC/Compiler/CISACodeGen/CheckInstrTypes.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ char CheckInstrTypes::ID = 0;
5353
CheckInstrTypes::CheckInstrTypes(IGC::SInstrTypes* instrList) : FunctionPass(ID), g_InstrTypes(instrList)
5454
{
5555
initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
56-
initializeCheckInstrTypesPass(*PassRegistry::getPassRegistry());
56+
initializeCheckInstrTypesPass(*PassRegistry::getPassRegistry());
5757

5858
instrList->CorrelatedValuePropagationEnable = false;
5959
instrList->hasLoop = false;
@@ -68,6 +68,7 @@ CheckInstrTypes::CheckInstrTypes(IGC::SInstrTypes* instrList) : FunctionPass(ID)
6868
instrList->hasFunctionAddressTaken = false;
6969
instrList->hasSel = false;
7070
instrList->hasPointer = false;
71+
instrList->hasGenericAddressSpacePointers = false;
7172
instrList->hasLocalLoadStore = false;
7273
instrList->hasSubroutines = false;
7374
instrList->hasPrimitiveAlloca = false;
@@ -79,13 +80,13 @@ CheckInstrTypes::CheckInstrTypes(IGC::SInstrTypes* instrList) : FunctionPass(ID)
7980
instrList->hasBarrier = false;
8081
instrList->hasDiscard = false;
8182
instrList->mayHaveIndirectOperands = false;
82-
instrList->numSample = 0;
83-
instrList->numBB = 0;
84-
instrList->numLoopInsts = 0;
83+
instrList->numSample = 0;
84+
instrList->numBB = 0;
85+
instrList->numLoopInsts = 0;
8586
instrList->numOfLoop = 0;
8687
instrList->numInsts = 0;
87-
instrList->sampleCmpToDiscardOptimizationPossible = false;
88-
instrList->sampleCmpToDiscardOptimizationSlot = 0;
88+
instrList->sampleCmpToDiscardOptimizationPossible = false;
89+
instrList->sampleCmpToDiscardOptimizationSlot = 0;
8990
}
9091

9192
void CheckInstrTypes::SetLoopFlags(Function &F)
@@ -116,15 +117,22 @@ bool CheckInstrTypes::runOnFunction(Function &F)
116117
g_InstrTypes->hasDebugInfo = F.getParent()->getNamedMetadata("llvm.dbg.cu") != nullptr;
117118

118119
visit(F);
119-
SetLoopFlags(F);
120+
SetLoopFlags(F);
120121
return false;
121122
}
122123

123-
void CheckInstrTypes::visitInstruction(llvm::Instruction &I) {
124+
void CheckInstrTypes::visitInstruction(llvm::Instruction &I)
125+
{
124126
if (!llvm::isa<llvm::DbgInfoIntrinsic>(&I))
125127
{
126128
g_InstrTypes->numInsts++;
127129
}
130+
131+
auto PT = dyn_cast<PointerType>(I.getType());
132+
if (PT && PT->getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
133+
{
134+
g_InstrTypes->hasGenericAddressSpacePointers = true;
135+
}
128136
}
129137

130138
void CheckInstrTypes::visitCallInst(CallInst &C)
@@ -245,6 +253,12 @@ void CheckInstrTypes::visitAllocaInst(AllocaInst &I)
245253
{
246254
g_InstrTypes->hasPrimitiveAlloca = true;
247255
}
256+
257+
auto PT = dyn_cast<PointerType>(I.getAllocatedType());
258+
if (PT && PT->getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
259+
{
260+
g_InstrTypes->hasGenericAddressSpacePointers = true;
261+
}
248262
}
249263

250264
void CheckInstrTypes::visitLoadInst(LoadInst &I)
@@ -255,21 +269,29 @@ void CheckInstrTypes::visitLoadInst(LoadInst &I)
255269
{
256270
g_InstrTypes->hasLocalLoadStore = true;
257271
}
272+
if (I.getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
273+
{
274+
g_InstrTypes->hasGenericAddressSpacePointers = true;
275+
}
258276
}
259277

260278
void CheckInstrTypes::visitStoreInst(StoreInst &I)
261279
{
262280
g_InstrTypes->numInsts++;
263281
g_InstrTypes->hasLoadStore = true;
264282
uint as = I.getPointerAddressSpace();
265-
if(as != ADDRESS_SPACE_PRIVATE)
283+
if (as != ADDRESS_SPACE_PRIVATE)
266284
{
267285
g_InstrTypes->psHasSideEffect = true;
268286
}
269-
if (I.getPointerAddressSpace() == ADDRESS_SPACE_LOCAL)
287+
if (as == ADDRESS_SPACE_LOCAL)
270288
{
271289
g_InstrTypes->hasLocalLoadStore = true;
272290
}
291+
if (as == ADDRESS_SPACE_GENERIC)
292+
{
293+
g_InstrTypes->hasGenericAddressSpacePointers = true;
294+
}
273295
}
274296

275297
void CheckInstrTypes::visitPHINode(PHINode &PN)
@@ -283,3 +305,12 @@ void CheckInstrTypes::visitSelectInst(SelectInst &I)
283305
g_InstrTypes->numInsts++;
284306
g_InstrTypes->hasSel = true;
285307
}
308+
309+
void CheckInstrTypes::visitGetElementPtrInst(llvm::GetElementPtrInst &I)
310+
{
311+
g_InstrTypes->numInsts++;
312+
if (I.getPointerAddressSpace() == ADDRESS_SPACE_GENERIC)
313+
{
314+
g_InstrTypes->hasGenericAddressSpacePointers = true;
315+
}
316+
}

IGC/Compiler/CISACodeGen/CheckInstrTypes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace IGC
7272
void visitAllocaInst(llvm::AllocaInst &I);
7373
void visitLoadInst(llvm::LoadInst &I);
7474
void visitStoreInst(llvm::StoreInst &I);
75+
void visitGetElementPtrInst(llvm::GetElementPtrInst &I);
7576
void visitPHINode(llvm::PHINode &PN);
7677
void visitSelectInst(llvm::SelectInst &I);
7778
void SetLoopFlags(llvm::Function &F);

IGC/Compiler/CISACodeGen/FixAddrSpaceCast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ FunctionPass *IGC::createFixAddrSpaceCastPass() {
7373
char AddrSpaceCastFixing::ID = 0;
7474

7575
#define PASS_FLAG "igc-addrspacecast-fix"
76-
#define PASS_DESC "Fix invalid addrspacecast-relevant patterns due to incompatible OCL FE, i.e. clang"
76+
#define PASS_DESC "Fix invalid addrspacecast-relevant patterns"
7777
#define PASS_CFG_ONLY false
7878
#define PASS_ANALYSIS false
7979
namespace IGC {

IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7171
#include "Compiler/CISACodeGen/POSH_RemoveNonPositionOutput.h"
7272

7373
#include "Compiler/CISACodeGen/SLMConstProp.hpp"
74+
#include "Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/GenericAddressDynamicResolution.hpp"
7475
#include "Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryUsageAnalysis.hpp"
7576
#include "Compiler/Optimizer/OpenCLPasses/PrivateMemory/PrivateMemoryResolution.hpp"
7677
#include "Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.hpp"
@@ -435,6 +436,18 @@ inline void AddLegalizationPasses(CodeGenContext &ctx, const CShaderProgram::Ker
435436
// Promotes indirect resource access to direct
436437
mpm.add(new PromoteResourceToDirectAS());
437438

439+
if (ctx.m_instrTypes.hasGenericAddressSpacePointers)
440+
{
441+
if (!isOptDisabled &&
442+
IGC_IS_FLAG_ENABLED(EnableGASResolver))
443+
{
444+
mpm.add(createFixAddrSpaceCastPass());
445+
mpm.add(createResolveGASPass());
446+
mpm.add(createSROAPass());
447+
}
448+
mpm.add(createGenericAddressDynamicResolutionPass());
449+
}
450+
438451
// Resolve the Private memory to register pass
439452
if (!isOptDisabled)
440453
{
@@ -457,8 +470,8 @@ inline void AddLegalizationPasses(CodeGenContext &ctx, const CShaderProgram::Ker
457470
if (ctx.m_enableSubroutine)
458471
{
459472
// Sort functions if subroutine is enabled.
460-
mpm.add(llvm::createGlobalDCEPass());
461-
mpm.add(new PurgeMetaDataUtils());
473+
mpm.add(llvm::createGlobalDCEPass());
474+
mpm.add(new PurgeMetaDataUtils());
462475
mpm.add(createGenXCodeGenModulePass());
463476
}
464477

@@ -1160,7 +1173,15 @@ void OptimizeIR(CodeGenContext* pContext)
11601173
mpm.add(llvm::createInstructionCombiningPass());
11611174
mpm.add(llvm::createDeadCodeEliminationPass()); // this should be done both before/after constant propagation
11621175

1163-
if( pContext->m_instrTypes.hasMultipleBB )
1176+
if (pContext->m_instrTypes.hasGenericAddressSpacePointers &&
1177+
IGC_IS_FLAG_ENABLED(EnableGASResolver))
1178+
{
1179+
mpm.add(createFixAddrSpaceCastPass());
1180+
mpm.add(createResolveGASPass());
1181+
mpm.add(createSROAPass());
1182+
}
1183+
1184+
if (pContext->m_instrTypes.hasMultipleBB)
11641185
{
11651186
// disable loop unroll for excessive large shaders
11661187
if( pContext->m_instrTypes.hasLoop )

0 commit comments

Comments
 (0)