@@ -60,7 +60,7 @@ bool PurgeMetaDataUtils::runOnModule(Module& M)
60
60
CodeGenContext* pContext = getAnalysis<CodeGenContextWrapper>().getCodeGenContext ();
61
61
IGCMD::MetaDataUtils* pMdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils ();
62
62
63
- auto toBeDeleted = [=](llvm::Module* M, void * ptr)
63
+ auto shouldRemoveFunction = [=](llvm::Module* M, void * ptr)
64
64
{
65
65
llvm::Function* F = nullptr ;
66
66
@@ -98,14 +98,21 @@ bool PurgeMetaDataUtils::runOnModule(Module& M)
98
98
};
99
99
100
100
// 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 )
105
105
{
106
- ToBeDeleted.push_back (i->first );
106
+ if (shouldRemoveFunction (pContext->getModule (), it->first ))
107
+ {
108
+ ToBeDeleted.insert (it->first );
109
+ }
107
110
}
108
- }
111
+ };
112
+
113
+ auto & FuncMD = pContext->getModuleMetaData ()->FuncMD ;
114
+ checkFuncRange (pMdUtils->begin_FunctionsInfo (), pMdUtils->end_FunctionsInfo ());
115
+ checkFuncRange (FuncMD.begin (), FuncMD.end ());
109
116
110
117
// Remove them.
111
118
for (auto F : ToBeDeleted)
@@ -116,9 +123,9 @@ bool PurgeMetaDataUtils::runOnModule(Module& M)
116
123
pMdUtils->eraseFunctionsInfoItem (Iter);
117
124
}
118
125
119
- if (pContext-> getModuleMetaData ()-> FuncMD .find (F) != pContext-> getModuleMetaData ()-> FuncMD .end ())
126
+ if (FuncMD.find (F) != FuncMD.end ())
120
127
{
121
- pContext-> getModuleMetaData ()-> FuncMD .erase (F);
128
+ FuncMD.erase (F);
122
129
}
123
130
}
124
131
0 commit comments