@@ -225,8 +225,10 @@ bool GenericAddressDynamicResolution::visitLoadStoreInst(Instruction& I)
225
225
IGC_ASSERT_EXIT_MESSAGE (0 , " Unable to resolve generic address space pointer" );
226
226
}
227
227
228
+ m_ctx->m_instrTypes .hasDynamicGenericLoadStore = true ;
229
+
228
230
if (pointerAddressSpace == ADDRESS_SPACE_GENERIC) {
229
- if (m_ctx->forceGlobalMemoryAllocation () && m_ctx->hasNoLocalToGenericCast ())
231
+ if (( m_ctx->forceGlobalMemoryAllocation () || m_ctx-> platform . canForcePrivateToGlobal () ) && m_ctx->hasNoLocalToGenericCast ())
230
232
{
231
233
resolveGASWithoutBranches (I, pointerOperand);
232
234
}
@@ -271,27 +273,32 @@ void GenericAddressDynamicResolution::resolveGAS(Instruction& I, Value* pointerO
271
273
Value* privateLoad = nullptr ;
272
274
Value* globalLoad = nullptr ;
273
275
276
+ bool hasPrivate = !m_ctx->platform .canForcePrivateToGlobal ();
277
+ bool hasLocal = !m_ctx->hasNoLocalToGenericCast ();
274
278
275
279
// Private branch
276
- privateBlock = BasicBlock::Create (I. getContext (), " PrivateBlock " , convergeBlock-> getParent (), convergeBlock);
280
+ if (hasPrivate)
277
281
{
278
- IRBuilder<> privateBuilder (privateBlock);
279
- PointerType* ptrType = pointerType->getElementType ()->getPointerTo (ADDRESS_SPACE_PRIVATE);
280
- Value* privatePtr = privateBuilder.CreateAddrSpaceCast (pointerOperand, ptrType);
281
-
282
- if (LoadInst* LI = dyn_cast<LoadInst>(&I))
282
+ privateBlock = BasicBlock::Create (I.getContext (), " PrivateBlock" , convergeBlock->getParent (), convergeBlock);
283
283
{
284
- privateLoad = privateBuilder.CreateAlignedLoad (privatePtr, getAlign (LI->getAlignment ()), LI->isVolatile (), " privateLoad" );
285
- }
286
- else if (StoreInst* SI = dyn_cast<StoreInst>(&I))
287
- {
288
- privateBuilder.CreateAlignedStore (I.getOperand (0 ), privatePtr, getAlign (SI->getAlignment ()), SI->isVolatile ());
284
+ IRBuilder<> privateBuilder (privateBlock);
285
+ PointerType* ptrType = pointerType->getElementType ()->getPointerTo (ADDRESS_SPACE_PRIVATE);
286
+ Value* privatePtr = privateBuilder.CreateAddrSpaceCast (pointerOperand, ptrType);
287
+
288
+ if (LoadInst* LI = dyn_cast<LoadInst>(&I))
289
+ {
290
+ privateLoad = privateBuilder.CreateAlignedLoad (privatePtr, getAlign (LI->getAlignment ()), LI->isVolatile (), " privateLoad" );
291
+ }
292
+ else if (StoreInst* SI = dyn_cast<StoreInst>(&I))
293
+ {
294
+ privateBuilder.CreateAlignedStore (I.getOperand (0 ), privatePtr, getAlign (SI->getAlignment ()), SI->isVolatile ());
295
+ }
296
+ privateBuilder.CreateBr (convergeBlock);
289
297
}
290
- privateBuilder.CreateBr (convergeBlock);
291
298
}
292
299
293
300
// Local Branch
294
- if (!m_ctx-> hasNoLocalToGenericCast () )
301
+ if (hasLocal )
295
302
{
296
303
localBlock = BasicBlock::Create (I.getContext (), " LocalBlock" , convergeBlock->getParent (), convergeBlock);
297
304
// Local
@@ -332,35 +339,33 @@ void GenericAddressDynamicResolution::resolveGAS(Instruction& I, Value* pointerO
332
339
currentBlock->getTerminator ()->eraseFromParent ();
333
340
builder.SetInsertPoint (currentBlock);
334
341
335
- // Local branch can be saved if there are no local to generic casts
336
- if (m_ctx->hasNoLocalToGenericCast ())
337
- {
338
- SwitchInst* switchTag = builder.CreateSwitch (tag, globalBlock, 1 );
339
- // Based on tag there are two cases 001: private, 000/111: global
340
- switchTag->addCase (privateTag, privateBlock);
342
+ int numPrivateLocal = (hasPrivate && hasLocal) ? 2 : ((hasPrivate || hasLocal) ? 1 : 0 );
343
+ assert (numPrivateLocal > 0 );
341
344
342
- if ((privateLoad != nullptr ) && (globalLoad != nullptr ))
343
- {
344
- IRBuilder<> phiBuilder (&(*convergeBlock->begin ()));
345
- PHINode* phi = phiBuilder.CreatePHI (I.getType (), 2 , I.getName ());
346
- phi->addIncoming (privateLoad, privateBlock);
347
- phi->addIncoming (globalLoad, globalBlock);
348
- I.replaceAllUsesWith (phi);
349
- }
350
- }
351
- else
352
345
{
353
- SwitchInst* switchTag = builder.CreateSwitch (tag, globalBlock, 2 );
346
+ SwitchInst* switchTag = builder.CreateSwitch (tag, globalBlock, numPrivateLocal );
354
347
// Based on tag there are two cases 001: private, 010: local, 000/111: global
355
- switchTag->addCase (privateTag, privateBlock);
356
- switchTag->addCase (localTag, localBlock);
348
+ if (hasPrivate)
349
+ {
350
+ switchTag->addCase (privateTag, privateBlock);
351
+ }
352
+ if (hasLocal)
353
+ {
354
+ switchTag->addCase (localTag, localBlock);
355
+ }
357
356
358
- if ((privateLoad != nullptr ) && (localLoad != nullptr ) && (globalLoad != nullptr ))
357
+ if (isa<LoadInst>(&I ))
359
358
{
360
359
IRBuilder<> phiBuilder (&(*convergeBlock->begin ()));
361
- PHINode* phi = phiBuilder.CreatePHI (I.getType (), 3 , I.getName ());
362
- phi->addIncoming (privateLoad, privateBlock);
363
- phi->addIncoming (localLoad, localBlock);
360
+ PHINode* phi = phiBuilder.CreatePHI (I.getType (), numPrivateLocal + 1 , I.getName ());
361
+ if (privateLoad)
362
+ {
363
+ phi->addIncoming (privateLoad, privateBlock);
364
+ }
365
+ if (localLoad)
366
+ {
367
+ phi->addIncoming (localLoad, localBlock);
368
+ }
364
369
phi->addIncoming (globalLoad, globalBlock);
365
370
I.replaceAllUsesWith (phi);
366
371
}
0 commit comments