Skip to content

Commit 4ef9315

Browse files
committed
[ThinLTO] Make ValueInfo::operator bool() explicit
Differential revision: https://reviews.llvm.org/D70383
1 parent 4fb8ecd commit 4ef9315

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct ValueInfo {
173173
RefAndFlags.setInt(HaveGVs);
174174
}
175175

176-
operator bool() const { return getRef(); }
176+
explicit operator bool() const { return getRef(); }
177177

178178
GlobalValue::GUID getGUID() const { return getRef()->first; }
179179
const GlobalValue *getValue() const {

llvm/lib/Transforms/IPO/FunctionImport.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -604,24 +604,26 @@ static void ComputeImportForModule(
604604
}
605605

606606
#ifndef NDEBUG
607+
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index, ValueInfo VI) {
608+
auto SL = VI.getSummaryList();
609+
return SL.empty()
610+
? false
611+
: SL[0]->getSummaryKind() == GlobalValueSummary::GlobalVarKind;
612+
}
613+
607614
static bool isGlobalVarSummary(const ModuleSummaryIndex &Index,
608615
GlobalValue::GUID G) {
609-
if (const auto &VI = Index.getValueInfo(G)) {
610-
auto SL = VI.getSummaryList();
611-
if (!SL.empty())
612-
return SL[0]->getSummaryKind() == GlobalValueSummary::GlobalVarKind;
613-
}
616+
if (const auto &VI = Index.getValueInfo(G))
617+
return isGlobalVarSummary(Index, VI);
614618
return false;
615619
}
616620

617-
static GlobalValue::GUID getGUID(GlobalValue::GUID G) { return G; }
618-
619621
template <class T>
620622
static unsigned numGlobalVarSummaries(const ModuleSummaryIndex &Index,
621623
T &Cont) {
622624
unsigned NumGVS = 0;
623625
for (auto &V : Cont)
624-
if (isGlobalVarSummary(Index, getGUID(V)))
626+
if (isGlobalVarSummary(Index, V))
625627
++NumGVS;
626628
return NumGVS;
627629
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; REQUIRES: asserts
2+
; RUN: opt -module-summary %p/funcimport.ll -o %t.bc
3+
; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc
4+
; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
5+
6+
; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc -o /dev/null -debug-only=function-import -stats > %t4 2>&1
7+
; RUN: cat %t4 | grep 'Is importing global' | count 4
8+
; RUN: cat %t4 | grep 'Is importing function' | count 8
9+
; RUN: cat %t4 | grep 'Is importing aliasee' | count 1
10+
; RUN: cat %t4 | FileCheck %s
11+
12+
; CHECK: - [[NUM_FUNCS:[0-9]+]] functions imported from
13+
; CHECK-NEXT: - [[NUM_VARS:[0-9]+]] global vars imported from
14+
15+
; CHECK: [[NUM_FUNCS]] function-import - Number of functions imported in backend
16+
; CHECK-NEXT: [[NUM_FUNCS]] function-import - Number of functions thin link decided to import
17+
; CHECK-NEXT: [[NUM_VARS]] function-import - Number of global variables imported in backend
18+
; CHECK-NEXT: [[NUM_VARS]] function-import - Number of global variables thin link decided to import
19+
; CHECK-NEXT: 1 function-import - Number of modules imported from
20+
; CHECK-NEXT: [[NUM_VARS]] module-summary-index - Number of live global variables marked read only
21+
; CHECK-NEXT: 1 module-summary-index - Number of live global variables marked write only

0 commit comments

Comments
 (0)