Skip to content

Commit ad8cfcf

Browse files
PawelJureksys_zuul
authored andcommitted
PurgeMetadataUtils: erase metadata for removed functions in CodeGenContext object.
Change-Id: I72dc0bfb631bc05d3ba8e30988a5b0cd1db4bac7
1 parent 460670c commit ad8cfcf

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

IGC/Compiler/MetaDataApi/PurgeMetaDataUtils.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool PurgeMetaDataUtils::runOnModule(Module& M)
6060
CodeGenContext* pContext = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
6161
IGCMD::MetaDataUtils* pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
6262

63-
auto toBeDeleted = [=](llvm::Module* M, void* ptr)
63+
auto shouldRemoveFunction = [=](llvm::Module* M, void* ptr)
6464
{
6565
llvm::Function* F = nullptr;
6666

@@ -98,14 +98,21 @@ bool PurgeMetaDataUtils::runOnModule(Module& M)
9898
};
9999

100100
// Collect all functions for which metadata will be removed.
101-
SmallVector<llvm::Function*, 8> ToBeDeleted;
102-
for (auto i = pMdUtils->begin_FunctionsInfo(), e = pMdUtils->end_FunctionsInfo(); i != e; ++i)
103-
{
104-
if (toBeDeleted(pContext->getModule(), i->first))
101+
SmallSet<llvm::Function*, 8> ToBeDeleted;
102+
103+
auto checkFuncRange = [&](auto beginIt, auto endIt) {
104+
for (auto it = beginIt, e = endIt; it != e; ++it)
105105
{
106-
ToBeDeleted.push_back(i->first);
106+
if (shouldRemoveFunction(pContext->getModule(), it->first))
107+
{
108+
ToBeDeleted.insert(it->first);
109+
}
107110
}
108-
}
111+
};
112+
113+
auto& FuncMD = pContext->getModuleMetaData()->FuncMD;
114+
checkFuncRange(pMdUtils->begin_FunctionsInfo(), pMdUtils->end_FunctionsInfo());
115+
checkFuncRange(FuncMD.begin(), FuncMD.end());
109116

110117
// Remove them.
111118
for (auto F : ToBeDeleted)
@@ -116,9 +123,9 @@ bool PurgeMetaDataUtils::runOnModule(Module& M)
116123
pMdUtils->eraseFunctionsInfoItem(Iter);
117124
}
118125

119-
if (pContext->getModuleMetaData()->FuncMD.find(F) != pContext->getModuleMetaData()->FuncMD.end())
126+
if (FuncMD.find(F) != FuncMD.end())
120127
{
121-
pContext->getModuleMetaData()->FuncMD.erase(F);
128+
FuncMD.erase(F);
122129
}
123130
}
124131

0 commit comments

Comments
 (0)