@@ -143,7 +143,7 @@ static void computeImportForFunction(
143
143
const std::map<GlobalValue::GUID, FunctionSummary *> &DefinedFunctions,
144
144
SmallVectorImpl<EdgeInfo> &Worklist,
145
145
FunctionImporter::ImportMapTy &ImportsForModule,
146
- StringMap<FunctionImporter::ExportSetTy> & ExportLists) {
146
+ StringMap<FunctionImporter::ExportSetTy> * ExportLists = nullptr ) {
147
147
for (auto &Edge : Summary.calls ()) {
148
148
auto GUID = Edge.first .getGUID ();
149
149
DEBUG (dbgs () << " edge -> " << GUID << " Threshold:" << Threshold << " \n " );
@@ -176,19 +176,21 @@ static void computeImportForFunction(
176
176
177
177
// Make exports in the source module.
178
178
auto ExportModulePath = CalleeSummary->modulePath ();
179
- auto ExportList = ExportLists[ExportModulePath];
180
- ExportList.insert (GUID);
181
- // Mark all functions and globals referenced by this function as exported to
182
- // the outside if they are defined in the same source module.
183
- for (auto &Edge : CalleeSummary->calls ()) {
184
- auto CalleeGUID = Edge.first .getGUID ();
185
- if (isGlobalExported (Index, ExportModulePath, CalleeGUID))
186
- ExportList.insert (CalleeGUID);
187
- }
188
- for (auto &Ref : CalleeSummary->refs ()) {
189
- auto GUID = Ref.getGUID ();
190
- if (isGlobalExported (Index, ExportModulePath, GUID))
191
- ExportList.insert (GUID);
179
+ if (ExportLists) {
180
+ auto ExportList = (*ExportLists)[ExportModulePath];
181
+ ExportList.insert (GUID);
182
+ // Mark all functions and globals referenced by this function as exported
183
+ // to the outside if they are defined in the same source module.
184
+ for (auto &Edge : CalleeSummary->calls ()) {
185
+ auto CalleeGUID = Edge.first .getGUID ();
186
+ if (isGlobalExported (Index, ExportModulePath, CalleeGUID))
187
+ ExportList.insert (CalleeGUID);
188
+ }
189
+ for (auto &Ref : CalleeSummary->refs ()) {
190
+ auto GUID = Ref.getGUID ();
191
+ if (isGlobalExported (Index, ExportModulePath, GUID))
192
+ ExportList.insert (GUID);
193
+ }
192
194
}
193
195
194
196
// Insert the newly imported function to the worklist.
@@ -203,7 +205,7 @@ static void ComputeImportForModule(
203
205
const std::map<GlobalValue::GUID, FunctionSummary *> &DefinedFunctions,
204
206
const ModuleSummaryIndex &Index,
205
207
FunctionImporter::ImportMapTy &ImportsForModule,
206
- StringMap<FunctionImporter::ExportSetTy> & ExportLists) {
208
+ StringMap<FunctionImporter::ExportSetTy> * ExportLists = nullptr ) {
207
209
// Worklist contains the list of function imported in this module, for which
208
210
// we will analyse the callees and may import further down the callgraph.
209
211
SmallVector<EdgeInfo, 128 > Worklist;
@@ -234,7 +236,7 @@ static void ComputeImportForModule(
234
236
235
237
} // anonymous namespace
236
238
237
- // / Compute all the import and export for every module in the Index.
239
+ // / Compute all the import and export for every module using the Index.
238
240
void llvm::ComputeCrossModuleImport (
239
241
const ModuleSummaryIndex &Index,
240
242
StringMap<FunctionImporter::ImportMapTy> &ImportLists,
@@ -265,7 +267,7 @@ void llvm::ComputeCrossModuleImport(
265
267
DEBUG (dbgs () << " Computing import for Module '" << DefinedFunctions.first ()
266
268
<< " '\n " );
267
269
ComputeImportForModule (DefinedFunctions.second , Index, ImportsForModule,
268
- ExportLists);
270
+ & ExportLists);
269
271
}
270
272
271
273
#ifndef NDEBUG
@@ -286,6 +288,31 @@ void llvm::ComputeCrossModuleImport(
286
288
#endif
287
289
}
288
290
291
+ // / Compute all the imports for the given module in the Index.
292
+ void llvm::ComputeCrossModuleImportForModule (
293
+ StringRef ModulePath, const ModuleSummaryIndex &Index,
294
+ FunctionImporter::ImportMapTy &ImportList) {
295
+
296
+ // Collect the list of functions this module defines.
297
+ // GUID -> Summary
298
+ std::map<GlobalValue::GUID, FunctionSummary *> FunctionInfoMap;
299
+ Index.collectDefinedFunctionsForModule (ModulePath, FunctionInfoMap);
300
+
301
+ // Compute the import list for this module.
302
+ DEBUG (dbgs () << " Computing import for Module '" << ModulePath << " '\n " );
303
+ ComputeImportForModule (FunctionInfoMap, Index, ImportList);
304
+
305
+ #ifndef NDEBUG
306
+ DEBUG (dbgs () << " * Module " << ModulePath << " imports from "
307
+ << ImportList.size () << " modules.\n " );
308
+ for (auto &Src : ImportList) {
309
+ auto SrcModName = Src.first ();
310
+ DEBUG (dbgs () << " - " << Src.second .size () << " functions imported from "
311
+ << SrcModName << " \n " );
312
+ }
313
+ #endif
314
+ }
315
+
289
316
// Automatically import functions in Module \p DestModule based on the summaries
290
317
// index.
291
318
//
@@ -463,13 +490,10 @@ class FunctionImportPass : public ModulePass {
463
490
Index = IndexPtr.get ();
464
491
}
465
492
466
- // First step is collecting the import/export lists
467
- // The export list is not used yet, but could limit the amount of renaming
468
- // performed in renameModuleForThinLTO()
469
- StringMap<FunctionImporter::ImportMapTy> ImportLists;
470
- StringMap<FunctionImporter::ExportSetTy> ExportLists;
471
- ComputeCrossModuleImport (*Index, ImportLists, ExportLists);
472
- auto &ImportList = ImportLists[M.getModuleIdentifier ()];
493
+ // First step is collecting the import list.
494
+ FunctionImporter::ImportMapTy ImportList;
495
+ ComputeCrossModuleImportForModule (M.getModuleIdentifier (), *Index,
496
+ ImportList);
473
497
474
498
// Next we need to promote to global scope and rename any local values that
475
499
// are potentially exported to other modules.
0 commit comments