@@ -42,6 +42,11 @@ static cl::opt<char>
42
42
" (default = '-O2')" ),
43
43
cl::Prefix, cl::ZeroOrMore, cl::init(' 2' ));
44
44
45
+ static cl::opt<bool >
46
+ IndexStats (" thinlto-index-stats" ,
47
+ cl::desc (" Print statistic for the index in every input files" ),
48
+ cl::init(false ));
49
+
45
50
static cl::opt<bool > DisableVerify (
46
51
" disable-verify" , cl::init(false ),
47
52
cl::desc(" Do not run the verifier during the optimization pipeline" ));
@@ -264,6 +269,40 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer,
264
269
return std::move (*Ret);
265
270
}
266
271
272
+ // / Print some statistics on the index for each input files.
273
+ void printIndexStats () {
274
+ for (auto &Filename : InputFilenames) {
275
+ CurrentActivity = " loading file '" + Filename + " '" ;
276
+ ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr =
277
+ llvm::getModuleSummaryIndexForFile (Filename, diagnosticHandler);
278
+ error (IndexOrErr, " error " + CurrentActivity);
279
+ std::unique_ptr<ModuleSummaryIndex> Index = std::move (IndexOrErr.get ());
280
+ CurrentActivity = " " ;
281
+ // Skip files without a module summary.
282
+ if (!Index)
283
+ report_fatal_error (Filename + " does not contain an index" );
284
+
285
+ unsigned Calls = 0 , Refs = 0 , Functions = 0 , Alias = 0 , Globals = 0 ;
286
+ for (auto &Summaries : *Index) {
287
+ for (auto &Summary : Summaries.second ) {
288
+ Refs += Summary->refs ().size ();
289
+ if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get ())) {
290
+ Functions++;
291
+ Calls += FuncSummary->calls ().size ();
292
+ } else if (isa<AliasSummary>(Summary.get ()))
293
+ Alias++;
294
+ else
295
+ Globals++;
296
+ }
297
+ }
298
+ outs () << " Index " << Filename << " contains "
299
+ << (Alias + Globals + Functions) << " nodes (" << Functions
300
+ << " functions, " << Alias << " alias, " << Globals
301
+ << " globals) and " << (Calls + Refs) << " edges (" << Refs
302
+ << " refs and " << Calls << " calls)\n " ;
303
+ }
304
+ }
305
+
267
306
// / \brief List symbols in each IR file.
268
307
// /
269
308
// / The main point here is to provide lit-testable coverage for the LTOModule
@@ -725,6 +764,11 @@ int main(int argc, char **argv) {
725
764
return 0 ;
726
765
}
727
766
767
+ if (IndexStats) {
768
+ printIndexStats ();
769
+ return 0 ;
770
+ }
771
+
728
772
if (CheckHasObjC) {
729
773
for (auto &Filename : InputFilenames) {
730
774
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
0 commit comments