summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-lto/llvm-lto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-lto/llvm-lto.cpp')
-rw-r--r--llvm/tools/llvm-lto/llvm-lto.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp
index 05d1bbdd1f7..2e9d8b7ed2f 100644
--- a/llvm/tools/llvm-lto/llvm-lto.cpp
+++ b/llvm/tools/llvm-lto/llvm-lto.cpp
@@ -42,6 +42,11 @@ static cl::opt<char>
"(default = '-O2')"),
cl::Prefix, cl::ZeroOrMore, cl::init('2'));
+static cl::opt<bool>
+ IndexStats("thinlto-index-stats",
+ cl::desc("Print statistic for the index in every input files"),
+ cl::init(false));
+
static cl::opt<bool> DisableVerify(
"disable-verify", cl::init(false),
cl::desc("Do not run the verifier during the optimization pipeline"));
@@ -264,6 +269,40 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer,
return std::move(*Ret);
}
+/// Print some statistics on the index for each input files.
+void printIndexStats() {
+ for (auto &Filename : InputFilenames) {
+ CurrentActivity = "loading file '" + Filename + "'";
+ ErrorOr<std::unique_ptr<ModuleSummaryIndex>> IndexOrErr =
+ llvm::getModuleSummaryIndexForFile(Filename, diagnosticHandler);
+ error(IndexOrErr, "error " + CurrentActivity);
+ std::unique_ptr<ModuleSummaryIndex> Index = std::move(IndexOrErr.get());
+ CurrentActivity = "";
+ // Skip files without a module summary.
+ if (!Index)
+ report_fatal_error(Filename + " does not contain an index");
+
+ unsigned Calls = 0, Refs = 0, Functions = 0, Alias = 0, Globals = 0;
+ for (auto &Summaries : *Index) {
+ for (auto &Summary : Summaries.second) {
+ Refs += Summary->refs().size();
+ if (auto *FuncSummary = dyn_cast<FunctionSummary>(Summary.get())) {
+ Functions++;
+ Calls += FuncSummary->calls().size();
+ } else if (isa<AliasSummary>(Summary.get()))
+ Alias++;
+ else
+ Globals++;
+ }
+ }
+ outs() << "Index " << Filename << " contains "
+ << (Alias + Globals + Functions) << " nodes (" << Functions
+ << " functions, " << Alias << " alias, " << Globals
+ << " globals) and " << (Calls + Refs) << " edges (" << Refs
+ << " refs and " << Calls << " calls)\n";
+ }
+}
+
/// \brief List symbols in each IR file.
///
/// The main point here is to provide lit-testable coverage for the LTOModule
@@ -725,6 +764,11 @@ int main(int argc, char **argv) {
return 0;
}
+ if (IndexStats) {
+ printIndexStats();
+ return 0;
+ }
+
if (CheckHasObjC) {
for (auto &Filename : InputFilenames) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
OpenPOWER on IntegriCloud