[llvm] r347145 - [ThinLTO] Add some stats for read only variable internalization

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 17 12:03:22 PST 2018


Author: tejohnson
Date: Sat Nov 17 12:03:22 2018
New Revision: 347145

URL: http://llvm.org/viewvc/llvm-project?rev=347145&view=rev
Log:
[ThinLTO] Add some stats for read only variable internalization

Summary:
Follow up to D49362 ([ThinLTO] Internalize read only globals). Add a
statistic on the number of read only variables (only counting live
variables since dead variables will be dropped anyway).

Reviewers: evgeny777

Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, arphaman, llvm-commits

Differential Revision: https://reviews.llvm.org/D54642

Modified:
    llvm/trunk/lib/IR/ModuleSummaryIndex.cpp
    llvm/trunk/test/ThinLTO/X86/index-const-prop.ll

Modified: llvm/trunk/lib/IR/ModuleSummaryIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ModuleSummaryIndex.cpp?rev=347145&r1=347144&r2=347145&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ModuleSummaryIndex.cpp (original)
+++ llvm/trunk/lib/IR/ModuleSummaryIndex.cpp Sat Nov 17 12:03:22 2018
@@ -14,11 +14,17 @@
 
 #include "llvm/IR/ModuleSummaryIndex.h"
 #include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
+#define DEBUG_TYPE "module-summary-index"
+
+STATISTIC(ReadOnlyLiveGVars,
+          "Number of live global variables marked read only");
+
 FunctionSummary FunctionSummary::ExternalNode =
     FunctionSummary::makeDummyFunctionSummary({});
 bool ValueInfo::isDSOLocal() const {
@@ -160,6 +166,14 @@ void ModuleSummaryIndex::propagateConsta
           GVS->setReadOnly(false);
       propagateConstantsToRefs(S.get());
     }
+#if LLVM_ENABLE_STATS
+  for (auto &P : *this)
+    if (P.second.SummaryList.size())
+      if (auto *GVS = dyn_cast<GlobalVarSummary>(
+              P.second.SummaryList[0]->getBaseObject()))
+        if (isGlobalValueLive(GVS) && GVS->isReadOnly())
+          ReadOnlyLiveGVars++;
+#endif
 }
 
 // TODO: write a graphviz dumper for SCCs (see ModuleSummaryIndex::exportToDot)

Modified: llvm/trunk/test/ThinLTO/X86/index-const-prop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/index-const-prop.ll?rev=347145&r1=347144&r2=347145&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/index-const-prop.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/index-const-prop.ll Sat Nov 17 12:03:22 2018
@@ -3,13 +3,18 @@
 ;  2. Make a local copy of internal definition if all accesses to it are readonly. This allows constant
 ;     folding it during optimziation phase.
 
+; -stats requires asserts
+; REQUIRES: asserts
+
 ; RUN: opt -module-summary %s -o %t1.bc
 ; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
 ; RUN: llvm-lto -thinlto-action=thinlink -o %t3.index.bc %t1.bc %t2.bc
-; RUN: llvm-lto -thinlto-action=import -exported-symbol=main  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc
+; RUN: llvm-lto -thinlto-action=import -exported-symbol=main  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc -stats 2>&1 | FileCheck %s --check-prefix=STATS
 ; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT
 ; RUN: llvm-lto -thinlto-action=optimize %t1.imported.bc -o - | llvm-dis - -o - | FileCheck %s --check-prefix=OPTIMIZE
 
+; STATS: 2 module-summary-index - Number of live global variables marked read only
+
 ; Check that we don't internalize gBar when it is exported
 ; RUN: llvm-lto -thinlto-action=import -exported-symbol main -exported-symbol gBar  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported2.bc
 ; RUN: llvm-dis %t1.imported2.bc -o - | FileCheck %s --check-prefix=IMPORT2
@@ -28,6 +33,10 @@ target triple = "x86_64-pc-linux-gnu"
 
 @gBar = external global i32
 
+; Should not be counted in the stats of live read only variables since it is
+; dead and will be dropped anyway.
+ at gDead = internal unnamed_addr global i32 1, align 4
+
 define i32 @main() local_unnamed_addr {
   %call = tail call i32 bitcast (i32 (...)* @foo to i32 ()*)()
   %call1 = tail call i32 bitcast (i32 (...)* @bar to i32 ()*)()




More information about the llvm-commits mailing list