[llvm] r261013 - [LTO] Support Statistics

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 13:41:52 PST 2016


Author: anemet
Date: Tue Feb 16 15:41:51 2016
New Revision: 261013

URL: http://llvm.org/viewvc/llvm-project?rev=261013&view=rev
Log:
[LTO] Support Statistics

Summary:
I thought -Xlinker -mllvm -Xlinker -stats worked at some point but maybe
it never did.

For clang, I believe that stats are printed from cc1_main.  This patch
also prints them for LTO, specifically right after codegen happens.

I only looked at the C API for LTO briefly to see if this is a good
place.  Probably there are still cases where this wouldn't be printed
but it seems to be working for the common case.  I also experimented
putting this in the LTOCodeGenerator destructor but that didn't trigger
for me because ld64 does not destroy the LTOCodeGenerator.

Reviewers: dexonsmith, joker.eph

Subscribers: rafael, joker.eph, llvm-commits

Differential Revision: http://reviews.llvm.org/D17302

Added:
    llvm/trunk/test/tools/lto/print-stats.ll
Modified:
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=261013&r1=261012&r2=261013&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Tue Feb 16 15:41:51 2016
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/LTO/LTOCodeGenerator.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
@@ -553,6 +554,10 @@ bool LTOCodeGenerator::compileOptimized(
                    RelocModel, CodeModel::Default, CGOptLevel, FileType,
                    ShouldRestoreGlobalsLinkage);
 
+  // If statistics were requested, print them out after codegen.
+  if (llvm::AreStatisticsEnabled())
+    llvm::PrintStatistics();
+
   return true;
 }
 

Added: llvm/trunk/test/tools/lto/print-stats.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/lto/print-stats.ll?rev=261013&view=auto
==============================================================================
--- llvm/trunk/test/tools/lto/print-stats.ll (added)
+++ llvm/trunk/test/tools/lto/print-stats.ll Tue Feb 16 15:41:51 2016
@@ -0,0 +1,8 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -mllvm -stats -o %t.dylib %t.o 2>&1 | FileCheck --check-prefix=STATS %s
+; RUN: %ld64 -lto_library %llvmshlibdir/libLTO.dylib -arch x86_64 -dylib -o %t.dylib %t.o 2>&1 | FileCheck --check-prefix=NO_STATS %s
+
+target triple = "x86_64-apple-macosx10.8.0"
+
+; STATS: Statistics Collected
+; NO_STATS-NOT: Statistics Collected




More information about the llvm-commits mailing list