@@ -57,24 +57,34 @@ IGC_INITIALIZE_PASS_END(ScalarizeFunction, PASS_FLAG, PASS_DESCRIPTION, PASS_CFG
57
57
58
58
char ScalarizeFunction::ID = 0;
59
59
60
- ScalarizeFunction::ScalarizeFunction (bool selectiveScalarization ) : FunctionPass(ID)
60
+ ScalarizeFunction::ScalarizeFunction (IGC::SelectiveScalarizer selectiveMode ) : FunctionPass(ID)
61
61
{
62
62
initializeScalarizeFunctionPass (*PassRegistry::getPassRegistry ());
63
63
64
64
for (int i = 0 ; i < Instruction::OtherOpsEnd; i++) m_transposeCtr[i] = 0 ;
65
65
66
- // Needs IGC_EnableSelectiveScalarizer = 1
67
- m_SelectiveScalarization = selectiveScalarization;
66
+ V_PRINT (scalarizer, " ScalarizeFunction constructor\n " );
67
+ switch (selectiveMode) {
68
+ case IGC::SelectiveScalarizer::Off:
69
+ V_PRINT (scalarizer, " IGC_EnableSelectiveScalarizer forced off" );
70
+ m_SelectiveScalarization = false ;
71
+ break ;
72
+ case IGC::SelectiveScalarizer::On:
73
+ V_PRINT (scalarizer, " IGC_EnableSelectiveScalarizer forced on" );
74
+ m_SelectiveScalarization = true ;
75
+ break ;
76
+ case IGC::SelectiveScalarizer::Auto:
77
+ V_PRINT (scalarizer, " IGC_EnableSelectiveScalarizer = " );
78
+ V_PRINT (scalarizer, IGC_IS_FLAG_ENABLED (EnableSelectiveScalarizer));
79
+ m_SelectiveScalarization = IGC_IS_FLAG_ENABLED (EnableSelectiveScalarizer);
80
+ break ;
81
+ }
82
+ V_PRINT (scalarizer, " \n " );
68
83
69
84
// Initialize SCM buffers and allocation
70
85
m_SCMAllocationArray = new SCMEntry[ESTIMATED_INST_NUM];
71
86
m_SCMArrays.push_back (m_SCMAllocationArray);
72
87
m_SCMArrayLocation = 0 ;
73
-
74
- V_PRINT (scalarizer, " ScalarizeFunction constructor\n " );
75
- V_PRINT (scalarizer, " IGC_EnableSelectiveScalarizer = " );
76
- V_PRINT (scalarizer, IGC_IS_FLAG_ENABLED (EnableSelectiveScalarizer));
77
- V_PRINT (scalarizer, " \n " );
78
88
}
79
89
80
90
bool ScalarizeFunction::doFinalization (llvm::Module& M) {
@@ -244,20 +254,40 @@ void ScalarizeFunction::buildExclusiveSet()
244
254
}
245
255
else if (BitCastInst* BCI = dyn_cast<BitCastInst>(currInst))
246
256
{
257
+ auto isBitcastSink = [](BitCastInst *BCI) -> bool {
258
+ auto *SrcVTy = dyn_cast<IGCLLVM::FixedVectorType>(
259
+ BCI->getOperand (0 )->getType ());
260
+
261
+ // If source is not a vector, we don't care about this bitcast
262
+ if (!SrcVTy)
263
+ return false ;
264
+
265
+ // If destination is a vector then we scalarize if the number of
266
+ // elements are the same (elementwise bitcast)
267
+ if (auto *DestVTy =
268
+ dyn_cast<IGCLLVM::FixedVectorType>(BCI->getType ()))
269
+ return DestVTy->getNumElements () != SrcVTy->getNumElements ();
270
+
271
+ // If destination is not a vector, we don't want to scalarize
272
+ return true ;
273
+ };
274
+
275
+ if (isBitcastSink (BCI)) {
247
276
workset.push_back (BCI->getOperand (0 ));
277
+ }
248
278
}
249
279
// try to find a web from the seed
250
280
std::set<Value*> defweb;
251
281
while (!workset.empty ())
252
282
{
253
- auto Def = workset.back ();
283
+ auto * Def = workset.back ();
254
284
workset.pop_back ();
255
285
if (m_Excludes.count (Def) || defweb.count (Def))
256
286
{
257
287
continue ;
258
288
}
259
289
260
- // The web grows "up" through BitCasts and PHI nodes
290
+ // The web grows "up" (towards producers) through BitCasts and PHI nodes
261
291
// but insert/extract elements and vector shuffles should be scalarized
262
292
if (!isAddToWeb (Def)) continue ;
263
293
@@ -285,7 +315,7 @@ void ScalarizeFunction::buildExclusiveSet()
285
315
continue ;
286
316
}
287
317
288
- // The web grows "down" through BitCasts and PHI nodes as well
318
+ // The web grows "down" (towards users) through BitCasts and PHI nodes as well
289
319
for (auto U : Def->users ())
290
320
{
291
321
if (!defweb.count (U) && isAddToWeb (U))
@@ -1458,8 +1488,8 @@ void ScalarizeFunction::resolveDeferredInstructions()
1458
1488
m_DRL.clear ();
1459
1489
}
1460
1490
1461
- extern " C" FunctionPass * createScalarizerPass (bool selectiveScalarization )
1491
+ extern " C" FunctionPass * createScalarizerPass (IGC::SelectiveScalarizer selectiveMode )
1462
1492
{
1463
- return new ScalarizeFunction (selectiveScalarization );
1493
+ return new ScalarizeFunction (selectiveMode );
1464
1494
}
1465
1495
0 commit comments