Skip to content

Commit 9522043

Browse files
pratikasharigcbot
authored andcommitted
Add comment.
1 parent 6b0689d commit 9522043

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

IGC/Compiler/CISACodeGen/DebugInfo.cpp

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace std;
3636
// ElfReader related typedefs
3737
using namespace CLElfLib;
3838

39-
std::vector<llvm::DISubprogram*> gatherDISubprogramNodes(llvm::Module& M);
39+
void gatherDISubprogramNodes(llvm::Module& M, std::unordered_map<llvm::Function*, std::vector<llvm::DISubprogram*>>& DISubprogramNodes);
4040

4141
char DebugInfoPass::ID = 0;
4242
char CatchAllLineNumber::ID = 0;
@@ -92,7 +92,43 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
9292
if (simd32) units.push_back(simd32);
9393
}
9494

95-
std::vector<llvm::DISubprogram*> DISubprogramNodes = gatherDISubprogramNodes(M);
95+
std::unordered_map<llvm::Function*, std::vector<llvm::DISubprogram*>> DISubprogramNodes;
96+
gatherDISubprogramNodes(M, DISubprogramNodes);
97+
98+
auto getSPDiesCollection = [&DISubprogramNodes](std::vector<llvm::Function*>& functions)
99+
{
100+
// Function argument is list of all functions for elf.
101+
// Each function may require emission of one or more DISubprogram nodes.
102+
// Return value should be a stable vector of collection of all DISubprogram nodes
103+
// but without duplicates.
104+
std::vector<llvm::DISubprogram*> retUniqueFuncVec;
105+
std::unordered_set<llvm::DISubprogram*> uniqueDISP;
106+
for (auto& f : functions)
107+
{
108+
// iterate over all DISubprogram nodes references by llvm::Function f
109+
auto& DISPNodesForF = DISubprogramNodes[f];
110+
for (auto& SP : DISPNodesForF)
111+
{
112+
if (uniqueDISP.find(SP) == uniqueDISP.end())
113+
{
114+
retUniqueFuncVec.push_back(SP);
115+
uniqueDISP.insert(SP);
116+
}
117+
}
118+
}
119+
// This vector contains DISubprogram node pointers for which DIEs will be emitted elf
120+
// for current kernel.
121+
//
122+
// Input to IGC may have 100s of kernels. When emitting to dwarf, we can emit subprogram
123+
// DIEs defined in current kernel (+ it's recursive callees) as well as declarations of
124+
// other kernels and functions in input. These declarations quickly add up and cause
125+
// bloat of elf size without adding much benefit. This function is responsible to filter
126+
// and return only those DISubprogram nodes for which we want DIE emitted to elf. This
127+
// only includes DIEs for subprograms ever referenced in this kernel (+ it's recursive
128+
// callees). We skip emitting declaration DIEs for which no code is emitted in current
129+
// kernel.
130+
return retUniqueFuncVec;
131+
};
96132

97133
for (auto& currShader : units)
98134
{
@@ -234,6 +270,10 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
234270
m_pDebugEmitter->registerVISA(m.second.second);
235271
}
236272

273+
std::vector<llvm::Function*> functions;
274+
std::for_each(sortedVISAModules.begin(), sortedVISAModules.end(),
275+
[&functions](auto& item) { functions.push_back(item.second.first); });
276+
auto SPDiesToBuild = getSPDiesCollection(functions);
237277
for (auto& m : sortedVISAModules)
238278
{
239279
isOneStepElf |= m.second.second->isDirectElfInput;
@@ -242,7 +282,7 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
242282
if (--size == 0)
243283
finalize = true;
244284

245-
EmitDebugInfo(finalize, &decodedDbg, DISubprogramNodes);
285+
EmitDebugInfo(finalize, &decodedDbg, SPDiesToBuild);
246286
}
247287

248288
// set VISA dbg info to nullptr to indicate 1-step debug is enabled

IGC/DebugInfo/DwarfDebug.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,3 +3610,48 @@ std::vector<llvm::DISubprogram*> gatherDISubprogramNodes(llvm::Module& M)
36103610
}
36113611
return DISubprogramNodes;
36123612
}
3613+
3614+
void gatherDISubprogramNodes(llvm::Module& M, std::unordered_map<llvm::Function*, std::vector<llvm::DISubprogram*>>& DISubprogramNodes)
3615+
{
3616+
// Discover all DISubprogram nodes referenced by every llvm::Function
3617+
// in the module. These referenced DISubprogram nodes will be emitted
3618+
// to dwarf.
3619+
for (auto& F : M)
3620+
{
3621+
llvm::DenseSet<DISubprogram*> DISPToFunction;
3622+
llvm::DenseSet<MDNode*> Processed;
3623+
if (auto* diSubprogram = F.getSubprogram())
3624+
{
3625+
DISubprogramNodes[&F].push_back(diSubprogram);
3626+
}
3627+
3628+
for (auto& bb : F)
3629+
{
3630+
for (auto& inst : bb)
3631+
{
3632+
auto debugLoc = inst.getDebugLoc().get();
3633+
while (debugLoc)
3634+
{
3635+
auto scope = debugLoc->getScope();
3636+
if (scope &&
3637+
dyn_cast_or_null<llvm::DILocalScope>(scope) &&
3638+
Processed.find(scope) == Processed.end())
3639+
{
3640+
auto DISP = cast<llvm::DILocalScope>(scope)->getSubprogram();
3641+
if (DISPToFunction.find(DISP) == DISPToFunction.end())
3642+
{
3643+
DISubprogramNodes[&F].push_back(DISP);
3644+
DISPToFunction.insert(DISP);
3645+
Processed.insert(scope);
3646+
}
3647+
}
3648+
3649+
if (debugLoc->getInlinedAt())
3650+
debugLoc = debugLoc->getInlinedAt();
3651+
else
3652+
debugLoc = nullptr;
3653+
}
3654+
}
3655+
}
3656+
}
3657+
}

0 commit comments

Comments
 (0)