Skip to content

Commit

Permalink
This change is based on the new dessa framework and
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jgu222 authored and gfxbot committed May 30, 2019
1 parent ae3d230 commit f2d1e14
Show file tree
Hide file tree
Showing 6 changed files with 1,087 additions and 99 deletions.
63 changes: 61 additions & 2 deletions IGC/Compiler/CISACodeGen/CShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,64 @@ void CShader::CreateImplicitArgs()
CVariable* ArgCVar = GetNewVector(ArgVal, algn);
updateArgSymbolMapping(ArgVal, ArgCVar);
}

// Create CVariables for vector aliasing (This is more
// efficient than doing it on-fly inside getSymbol()).
if (IGC_IS_FLAG_ENABLED(VATemp) &&
!m_VRA->m_aliasMap.empty())
{
// For each vector alias root, generate cvariable
// for it and all its component sub-vector
for (auto& II : m_VRA->m_aliasMap)
{
SSubVecDesc* SV = II.second;
Value* rootVal = SV->BaseVector;
if (SV->Aliaser != rootVal)
continue;
CVariable* rootCVar = GetSymbol(rootVal);

// Generate all vector aliasers and their
// dessa root if any.
for (int i = 0, sz = (int)SV->Aliasers.size(); i < sz; ++i)
{
SSubVecDesc* aSV = SV->Aliasers[i];
Value* V = aSV->Aliaser;
// Create alias cvariable for Aliaser and its dessa root if any
Value* Vals[2] = { V, nullptr };
if (m_deSSA) {
Value* dessaRootVal = m_deSSA->getRootValue(V);
if (dessaRootVal && dessaRootVal != V)
Vals[1] = dessaRootVal;
}
int startIx = aSV->StartElementOffset;

for (int i = 0; i < 2; ++i)
{
V = Vals[i];
if (!V)
continue;

Type *Ty = V->getType();
VectorType* VTy = dyn_cast<VectorType>(Ty);
Type *BTy = VTy ? VTy->getElementType() : Ty;
int nelts = (VTy ? (int)VTy->getNumElements() : 1);

VISA_Type visaTy = GetType(BTy);
int typeBytes = (int)CEncoder::GetCISADataTypeSize(visaTy);
int offsetInBytes = typeBytes * startIx;
int nbelts = nelts;
if (!rootCVar->IsUniform())
{
int width = (int)numLanes(m_SIMDSize);
offsetInBytes *= width;
nbelts *= width;
}
CVariable* Var = GetNewAlias(rootCVar, visaTy, offsetInBytes, nbelts);
symbolMapping.insert(std::pair<llvm::Value*, CVariable*>(V, Var));
}
}
}
}
}

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

if (IGC_IS_FLAG_ENABLED(EnableVariableAlias))
if (IGC_IS_FLAG_ENABLED(EnableVariableAlias) &&
IGC_GET_FLAG_VALUE(VATemp) == 0)
{
if (m_VRA->m_ValueAliasMap.count(value))
{
// Generate alias
SSubVector& SV = m_VRA->m_ValueAliasMap[value];
SSubVecDesc& SV = m_VRA->m_ValueAliasMap[value];
Value* BaseVec = SV.BaseVector;
int startIx = SV.StartElementOffset;

Expand Down
37 changes: 31 additions & 6 deletions IGC/Compiler/CISACodeGen/DeSSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,16 +1361,17 @@ bool DeSSA::isAliasee(Value* V) const
return AI->first == AI->second;
}

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

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

//
// If aliasee is in InsEltMap, it is not single valued
// and cannot be excluded from interfere checking.
//
// For example:
// x = bitcast y
// z = InsElt y, ...
// = x
// = y
//
// {y, z} are coalesced via InsElt, interfere(x, y)
// must be checked.
// However, if y (and x too) is not in InsEltMap, no need
// to check interfere(x, y) as they have the same value
// as the following:
// x = bitcast y
// = x
// = y
//
bool V0_oneValue = (InsEltMap.count(V0_aliasee) == 0);
bool V1_oneValue = (InsEltMap.count(V1_aliasee) == 0);
bool both_singleValue = (V0_oneValue && V1_oneValue);

for (int i0 = 0, sz0 = (int)allCC0.size(); i0 < sz0; ++i0)
{
Value* val0 = allCC0[i0];
for (int i1 = 0, sz1 = (int)allCC1.size(); i1 < sz1; ++i1)
{
Value* val1 = allCC1[i1];
if (val0 == V0_aliasee && val1 == V1_aliasee) {
if (both_singleValue &&
val0 == V0_aliasee && val1 == V1_aliasee) {
continue;
}
if (LV->hasInterference(val0, val1)) {
Expand Down
4 changes: 2 additions & 2 deletions IGC/Compiler/CISACodeGen/DeSSA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class DeSSA : public llvm::FunctionPass {
bool isAliasee(llvm::Value* V) const;
bool isAliaser(llvm::Value* V) const;
bool isNoopAliaser(llvm::Value* V) const;
bool isCoalesced(llvm::Value* V) const;
bool isSingleValued(llvm::Value* V) const;
bool interfere(llvm::Value* V0, llvm::Value* V1);
bool aliasInterfere(llvm::Value* V0, llvm::Value* V1);
bool alignInterfere(e_alignment a1, e_alignment a2);
Expand All @@ -312,7 +312,7 @@ class DeSSA : public llvm::FunctionPass {
llvm::InsertElementInst* IEI,
llvm::SmallVector<llvm::Value*, 16>& AllIEIs);

// Add Val into aliasMap if it is not in the map yet.
// Add Val->Val into aliasMap if it is not in the map yet.
// Return Val's aliasee.
void AddAlias(llvm::Value *Val) {
if (AliasMap.find(Val) == AliasMap.end())
Expand Down
11 changes: 7 additions & 4 deletions IGC/Compiler/CISACodeGen/EmitVISAPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ bool EmitPass::runOnFunction(llvm::Function &F)
m_encoder->SetSecondHalf(false);
// insert constant initializations.
InitConstant(block.bb);
// insert the de-ssa movs.
MovPhiSources(block.bb);
// Insert lifetime start if there are any
emitLifetimeStartAtEndOfBB(block.bb);
// insert the de-ssa movs.
MovPhiSources(block.bb);
}

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

void EmitPass::emitLifetimeStartAtEndOfBB(BasicBlock* BB)
{
if (IGC_IS_FLAG_DISABLED(EnableVATemp)) {
if (IGC_IS_FLAG_DISABLED(EnableVATemp) &&
IGC_GET_FLAG_VALUE(VATemp) == 0) {
return;
}

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

Expand Down
Loading

0 comments on commit f2d1e14

Please sign in to comment.