1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[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

llvm-svn: 347145
This commit is contained in:
Teresa Johnson 2018-11-17 20:03:22 +00:00
parent ce14247d94
commit fc275f07c1
2 changed files with 24 additions and 1 deletions

View File

@ -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::propagateConstants(
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)

View File

@ -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.
@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 ()*)()