Skip to content

Commit 58e2687

Browse files
aparshin-inteligcbot
authored andcommitted
simplify extraction of DISubprogram nodes
simplify extraction of DISubprogram nodes
1 parent f938945 commit 58e2687

File tree

8 files changed

+199
-211
lines changed

8 files changed

+199
-211
lines changed

IGC/Compiler/CISACodeGen/DebugInfo.cpp

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SPDX-License-Identifier: MIT
1111
#include "CLElfLib/ElfReader.h"
1212

1313
#include "DebugInfo/ScalarVISAModule.h"
14+
#include "DebugInfo/DwarfDebug.hpp"
1415
#include "Compiler/CISACodeGen/DebugInfo.hpp"
1516

1617
using namespace llvm;
@@ -20,8 +21,6 @@ using namespace std;
2021
// ElfReader related typedefs
2122
using namespace CLElfLib;
2223

23-
void gatherDISubprogramNodes(llvm::Module& M, std::unordered_map<llvm::Function*, std::vector<llvm::DISubprogram*>>& DISubprogramNodes);
24-
2524
char DebugInfoPass::ID = 0;
2625
char CatchAllLineNumber::ID = 0;
2726

@@ -74,43 +73,7 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
7473
if (simd32) units.push_back(simd32);
7574
}
7675

77-
std::unordered_map<llvm::Function*, std::vector<llvm::DISubprogram*>> DISubprogramNodes;
78-
gatherDISubprogramNodes(M, DISubprogramNodes);
79-
80-
auto getSPDiesCollection = [&DISubprogramNodes](std::vector<llvm::Function*>& functions)
81-
{
82-
// Function argument is list of all functions for elf.
83-
// Each function may require emission of one or more DISubprogram nodes.
84-
// Return value should be a stable vector of collection of all DISubprogram nodes
85-
// but without duplicates.
86-
std::vector<llvm::DISubprogram*> retUniqueFuncVec;
87-
std::unordered_set<llvm::DISubprogram*> uniqueDISP;
88-
for (auto& f : functions)
89-
{
90-
// iterate over all DISubprogram nodes references by llvm::Function f
91-
auto& DISPNodesForF = DISubprogramNodes[f];
92-
for (auto& SP : DISPNodesForF)
93-
{
94-
if (uniqueDISP.find(SP) == uniqueDISP.end())
95-
{
96-
retUniqueFuncVec.push_back(SP);
97-
uniqueDISP.insert(SP);
98-
}
99-
}
100-
}
101-
// This vector contains DISubprogram node pointers for which DIEs will be emitted elf
102-
// for current kernel.
103-
//
104-
// Input to IGC may have 100s of kernels. When emitting to dwarf, we can emit subprogram
105-
// DIEs defined in current kernel (+ it's recursive callees) as well as declarations of
106-
// other kernels and functions in input. These declarations quickly add up and cause
107-
// bloat of elf size without adding much benefit. This function is responsible to filter
108-
// and return only those DISubprogram nodes for which we want DIE emitted to elf. This
109-
// only includes DIEs for subprograms ever referenced in this kernel (+ it's recursive
110-
// callees). We skip emitting declaration DIEs for which no code is emitted in current
111-
// kernel.
112-
return retUniqueFuncVec;
113-
};
76+
DwarfDISubprogramCache DISPCache;
11477

11578
for (auto& currShader : units)
11679
{
@@ -242,6 +205,7 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
242205
return p1.first < p2.first;
243206
});
244207

208+
m_pDebugEmitter->SetDISPCache(&DISPCache);
245209
for (auto& m : sortedVISAModules)
246210
{
247211
m_pDebugEmitter->registerVISA(m.second.second);
@@ -250,15 +214,15 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
250214
std::vector<llvm::Function*> functions;
251215
std::for_each(sortedVISAModules.begin(), sortedVISAModules.end(),
252216
[&functions](auto& item) { functions.push_back(item.second.first); });
253-
auto SPDiesToBuild = getSPDiesCollection(functions);
217+
254218
for (auto& m : sortedVISAModules)
255219
{
256220
m_pDebugEmitter->setCurrentVISA(m.second.second);
257221

258222
if (--size == 0)
259223
finalize = true;
260224

261-
EmitDebugInfo(finalize, &decodedDbg, SPDiesToBuild);
225+
EmitDebugInfo(finalize, &decodedDbg);
262226
}
263227

264228
// set VISA dbg info to nullptr to indicate 1-step debug is enabled
@@ -274,13 +238,11 @@ bool DebugInfoPass::runOnModule(llvm::Module& M)
274238
return false;
275239
}
276240

277-
void DebugInfoPass::EmitDebugInfo(bool finalize, DbgDecoder* decodedDbg,
278-
const std::vector<llvm::DISubprogram*>& DISubprogramNodes)
241+
void DebugInfoPass::EmitDebugInfo(bool finalize, DbgDecoder* decodedDbg)
279242
{
280243
IGC_ASSERT(m_pDebugEmitter);
281244

282-
std::vector<char> buffer =
283-
m_pDebugEmitter->Finalize(finalize, decodedDbg, DISubprogramNodes);
245+
std::vector<char> buffer = m_pDebugEmitter->Finalize(finalize, decodedDbg);
284246

285247
if (!buffer.empty())
286248
{

IGC/Compiler/CISACodeGen/DebugInfo.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace IGC
5252
AU.setPreservesAll();
5353
}
5454

55-
void EmitDebugInfo(bool, DbgDecoder*, const std::vector<llvm::DISubprogram*>&);
55+
void EmitDebugInfo(bool, DbgDecoder*);
5656
};
5757

5858
class CatchAllLineNumber : public llvm::FunctionPass

0 commit comments

Comments
 (0)