Skip to content

Commit f2d1e14

Browse files
jgu222gfxbot
authored andcommitted
This change is based on the new dessa framework and
is a re-work of the old sub-vector alising code. The new code is able to handle more cases with less coding. This submit does not turn it on, therefore, there is no functional change from this change. It will be turned on with several steps following this change Change-Id: I68903549e9f678fe1340c92e145a1e402a6ca263
1 parent ae3d230 commit f2d1e14

File tree

6 files changed

+1087
-99
lines changed

6 files changed

+1087
-99
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

+61-2
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,64 @@ void CShader::CreateImplicitArgs()
421421
CVariable* ArgCVar = GetNewVector(ArgVal, algn);
422422
updateArgSymbolMapping(ArgVal, ArgCVar);
423423
}
424+
425+
// Create CVariables for vector aliasing (This is more
426+
// efficient than doing it on-fly inside getSymbol()).
427+
if (IGC_IS_FLAG_ENABLED(VATemp) &&
428+
!m_VRA->m_aliasMap.empty())
429+
{
430+
// For each vector alias root, generate cvariable
431+
// for it and all its component sub-vector
432+
for (auto& II : m_VRA->m_aliasMap)
433+
{
434+
SSubVecDesc* SV = II.second;
435+
Value* rootVal = SV->BaseVector;
436+
if (SV->Aliaser != rootVal)
437+
continue;
438+
CVariable* rootCVar = GetSymbol(rootVal);
439+
440+
// Generate all vector aliasers and their
441+
// dessa root if any.
442+
for (int i = 0, sz = (int)SV->Aliasers.size(); i < sz; ++i)
443+
{
444+
SSubVecDesc* aSV = SV->Aliasers[i];
445+
Value* V = aSV->Aliaser;
446+
// Create alias cvariable for Aliaser and its dessa root if any
447+
Value* Vals[2] = { V, nullptr };
448+
if (m_deSSA) {
449+
Value* dessaRootVal = m_deSSA->getRootValue(V);
450+
if (dessaRootVal && dessaRootVal != V)
451+
Vals[1] = dessaRootVal;
452+
}
453+
int startIx = aSV->StartElementOffset;
454+
455+
for (int i = 0; i < 2; ++i)
456+
{
457+
V = Vals[i];
458+
if (!V)
459+
continue;
460+
461+
Type *Ty = V->getType();
462+
VectorType* VTy = dyn_cast<VectorType>(Ty);
463+
Type *BTy = VTy ? VTy->getElementType() : Ty;
464+
int nelts = (VTy ? (int)VTy->getNumElements() : 1);
465+
466+
VISA_Type visaTy = GetType(BTy);
467+
int typeBytes = (int)CEncoder::GetCISADataTypeSize(visaTy);
468+
int offsetInBytes = typeBytes * startIx;
469+
int nbelts = nelts;
470+
if (!rootCVar->IsUniform())
471+
{
472+
int width = (int)numLanes(m_SIMDSize);
473+
offsetInBytes *= width;
474+
nbelts *= width;
475+
}
476+
CVariable* Var = GetNewAlias(rootCVar, visaTy, offsetInBytes, nbelts);
477+
symbolMapping.insert(std::pair<llvm::Value*, CVariable*>(V, Var));
478+
}
479+
}
480+
}
481+
}
424482
}
425483

426484
void CShader::AddSetup(uint index, CVariable* var)
@@ -2412,12 +2470,13 @@ CVariable* CShader::GetSymbol(llvm::Value *value, bool fromConstantPool)
24122470
return AliasVar;
24132471
}
24142472

2415-
if (IGC_IS_FLAG_ENABLED(EnableVariableAlias))
2473+
if (IGC_IS_FLAG_ENABLED(EnableVariableAlias) &&
2474+
IGC_GET_FLAG_VALUE(VATemp) == 0)
24162475
{
24172476
if (m_VRA->m_ValueAliasMap.count(value))
24182477
{
24192478
// Generate alias
2420-
SSubVector& SV = m_VRA->m_ValueAliasMap[value];
2479+
SSubVecDesc& SV = m_VRA->m_ValueAliasMap[value];
24212480
Value* BaseVec = SV.BaseVector;
24222481
int startIx = SV.StartElementOffset;
24232482

IGC/Compiler/CISACodeGen/DeSSA.cpp

+31-6
Original file line numberDiff line numberDiff line change
@@ -1361,16 +1361,17 @@ bool DeSSA::isAliasee(Value* V) const
13611361
return AI->first == AI->second;
13621362
}
13631363

1364-
// If V is either in InsElt or in an DeSSA CC, return true;
1365-
// otherwise return false;
1366-
bool DeSSA::isCoalesced(llvm::Value* V) const
1364+
// If V is neither InsElt'ed, nor phi-coalesced, it is said to be
1365+
// single valued. In another word, if it is at most aliased only,
1366+
// it will have a single value during V's lifetime.
1367+
bool DeSSA::isSingleValued(llvm::Value* V) const
13671368
{
13681369
Value* aliasee = getAliasee(V);
13691370
Value* insEltRootV = getInsEltRoot(aliasee);
13701371
if (InsEltMap.count(aliasee) || !isIsolated(insEltRootV)) {
1371-
return true;
1372+
return false;
13721373
}
1373-
return false;
1374+
return true;
13741375
}
13751376

13761377
// The following paper explains an approach to check if two
@@ -1425,13 +1426,37 @@ bool DeSSA::aliasInterfere(llvm::Value* V0, llvm::Value* V1)
14251426
Value* V0_aliasee = getAliasee(V0);
14261427
Value* V1_aliasee = getAliasee(V1);
14271428

1429+
//
1430+
// If aliasee is in InsEltMap, it is not single valued
1431+
// and cannot be excluded from interfere checking.
1432+
//
1433+
// For example:
1434+
// x = bitcast y
1435+
// z = InsElt y, ...
1436+
// = x
1437+
// = y
1438+
//
1439+
// {y, z} are coalesced via InsElt, interfere(x, y)
1440+
// must be checked.
1441+
// However, if y (and x too) is not in InsEltMap, no need
1442+
// to check interfere(x, y) as they have the same value
1443+
// as the following:
1444+
// x = bitcast y
1445+
// = x
1446+
// = y
1447+
//
1448+
bool V0_oneValue = (InsEltMap.count(V0_aliasee) == 0);
1449+
bool V1_oneValue = (InsEltMap.count(V1_aliasee) == 0);
1450+
bool both_singleValue = (V0_oneValue && V1_oneValue);
1451+
14281452
for (int i0 = 0, sz0 = (int)allCC0.size(); i0 < sz0; ++i0)
14291453
{
14301454
Value* val0 = allCC0[i0];
14311455
for (int i1 = 0, sz1 = (int)allCC1.size(); i1 < sz1; ++i1)
14321456
{
14331457
Value* val1 = allCC1[i1];
1434-
if (val0 == V0_aliasee && val1 == V1_aliasee) {
1458+
if (both_singleValue &&
1459+
val0 == V0_aliasee && val1 == V1_aliasee) {
14351460
continue;
14361461
}
14371462
if (LV->hasInterference(val0, val1)) {

IGC/Compiler/CISACodeGen/DeSSA.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class DeSSA : public llvm::FunctionPass {
288288
bool isAliasee(llvm::Value* V) const;
289289
bool isAliaser(llvm::Value* V) const;
290290
bool isNoopAliaser(llvm::Value* V) const;
291-
bool isCoalesced(llvm::Value* V) const;
291+
bool isSingleValued(llvm::Value* V) const;
292292
bool interfere(llvm::Value* V0, llvm::Value* V1);
293293
bool aliasInterfere(llvm::Value* V0, llvm::Value* V1);
294294
bool alignInterfere(e_alignment a1, e_alignment a2);
@@ -312,7 +312,7 @@ class DeSSA : public llvm::FunctionPass {
312312
llvm::InsertElementInst* IEI,
313313
llvm::SmallVector<llvm::Value*, 16>& AllIEIs);
314314

315-
// Add Val into aliasMap if it is not in the map yet.
315+
// Add Val->Val into aliasMap if it is not in the map yet.
316316
// Return Val's aliasee.
317317
void AddAlias(llvm::Value *Val) {
318318
if (AliasMap.find(Val) == AliasMap.end())

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,10 @@ bool EmitPass::runOnFunction(llvm::Function &F)
600600
m_encoder->SetSecondHalf(false);
601601
// insert constant initializations.
602602
InitConstant(block.bb);
603-
// insert the de-ssa movs.
604-
MovPhiSources(block.bb);
605603
// Insert lifetime start if there are any
606604
emitLifetimeStartAtEndOfBB(block.bb);
605+
// insert the de-ssa movs.
606+
MovPhiSources(block.bb);
607607
}
608608

609609
// If slicing happens, then recalculate the number of instances.
@@ -1113,7 +1113,8 @@ void EmitPass::InitConstant(llvm::BasicBlock *BB)
11131113

11141114
void EmitPass::emitLifetimeStartAtEndOfBB(BasicBlock* BB)
11151115
{
1116-
if (IGC_IS_FLAG_DISABLED(EnableVATemp)) {
1116+
if (IGC_IS_FLAG_DISABLED(EnableVATemp) &&
1117+
IGC_GET_FLAG_VALUE(VATemp) == 0) {
11171118
return;
11181119
}
11191120

@@ -7831,7 +7832,9 @@ CVariable *EmitPass::Add(CVariable *Src0, CVariable *Src1, const CVariable *DstP
78317832
// Insert lifetime start right before instruction I if it is a candidate.
78327833
void EmitPass::emitLifetimeStart(CVariable* Var, BasicBlock* BB, Instruction* I, bool ForAllInstance)
78337834
{
7834-
if (IGC_IS_FLAG_DISABLED(EnableVATemp) || Var == nullptr) {
7835+
if ((IGC_IS_FLAG_DISABLED(EnableVATemp) &&
7836+
IGC_GET_FLAG_VALUE(VATemp) == 0) ||
7837+
Var == nullptr) {
78357838
return;
78367839
}
78377840

0 commit comments

Comments
 (0)