Skip to content

Commit ec2db33

Browse files
remove new flag and do match default
1 parent 85c630d commit ec2db33

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ static cl::opt<std::string> WorkloadDefinitions(
163163
"}"),
164164
cl::Hidden);
165165

166+
namespace llvm {
167+
extern cl::opt<bool> EnableMemProfContextDisambiguation;
168+
}
169+
166170
// Load lazily a module from \p FileName in \p Context.
167171
static std::unique_ptr<Module> loadFile(const std::string &FileName,
168172
LLVMContext &Context) {
@@ -1643,7 +1647,9 @@ Expected<bool> FunctionImporter::importFunctions(
16431647
if (Import) {
16441648
if (Error Err = F.materialize())
16451649
return std::move(Err);
1646-
if (EnableImportMetadata) {
1650+
// MemProf should match function's definition and summary,
1651+
// 'thinlto_src_module' is needed.
1652+
if (EnableImportMetadata || EnableMemProfContextDisambiguation) {
16471653
// Add 'thinlto_src_module' and 'thinlto_src_file' metadata for
16481654
// statistics and debugging.
16491655
F.setMetadata(

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ static cl::opt<unsigned>
121121
cl::desc("Max depth to recursively search for missing "
122122
"frames through tail calls."));
123123

124-
static cl::opt<bool>
125-
StrictSummaryMatch("memprof-strict-summary-match", cl::init(false),
126-
cl::Hidden,
127-
cl::desc("Match summary and definition strictly."));
128-
129124
namespace llvm {
130125
// Indicate we are linking with an allocator that supports hot/cold operator
131126
// new interfaces.
@@ -3381,23 +3376,20 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
33813376
auto *GVSummary =
33823377
ImportSummary->findSummaryInModule(TheFnVI, M.getModuleIdentifier());
33833378
if (!GVSummary) {
3384-
// Must have been imported, use the first summary (might be multiple if
3385-
// this was a linkonce_odr).
3386-
GVSummary = TheFnVI.getSummaryList().front().get();
3387-
if (StrictSummaryMatch) {
3388-
auto SrcModuleMD = F.getMetadata("thinlto_src_module");
3389-
assert(SrcModuleMD &&
3390-
"enable-import-metadata is needed to emit thinlto_src_module");
3391-
StringRef SrcModule =
3392-
dyn_cast<MDString>(SrcModuleMD->getOperand(0))->getString();
3393-
for (auto &GVS : TheFnVI.getSummaryList()) {
3394-
if (GVS->modulePath() == SrcModule) {
3395-
GVSummary = GVS.get();
3396-
break;
3397-
}
3379+
// Must have been imported, use the summary which matches the definition。
3380+
// (might be multiple if this was a linkonce_odr).
3381+
auto SrcModuleMD = F.getMetadata("thinlto_src_module");
3382+
assert(SrcModuleMD &&
3383+
"enable-import-metadata is needed to emit thinlto_src_module");
3384+
StringRef SrcModule =
3385+
dyn_cast<MDString>(SrcModuleMD->getOperand(0))->getString();
3386+
for (auto &GVS : TheFnVI.getSummaryList()) {
3387+
if (GVS->modulePath() == SrcModule) {
3388+
GVSummary = GVS.get();
3389+
break;
33983390
}
3399-
assert(GVSummary->modulePath() == SrcModule);
34003391
}
3392+
assert(GVSummary && GVSummary->modulePath() == SrcModule);
34013393
}
34023394

34033395
// If this was an imported alias skip it as we won't have the function

llvm/test/ThinLTO/X86/summary-matching.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
; RUN: -r=%t/c.o,_Znwm \
1717
; RUN: -r=%t/main.o,_Z1bv \
1818
; RUN: -r=%t/main.o,_Z1cv \
19-
; RUN: -r=%t/main.o,_Z3fooIiET_S0_S0_ -enable-import-metadata=true -memprof-strict-summary-match=true
19+
; RUN: -r=%t/main.o,_Z3fooIiET_S0_S0_ -enable-import-metadata=true
2020

2121
;; foo has two copys:
2222
;; foo in b.ll is prevailing and inlines bar.

llvm/tools/llvm-link/llvm-link.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ static cl::opt<bool> TryUseNewDbgInfoFormat(
134134
cl::desc("Enable debuginfo iterator positions, if they're built in"),
135135
cl::init(false));
136136

137+
namespace llvm {
138+
cl::opt<bool> EnableMemProfContextDisambiguation(
139+
"enable-memprof-context-disambiguation", cl::init(false), cl::Hidden,
140+
cl::ZeroOrMore, cl::desc("Enable MemProf context disambiguation"));
141+
}
142+
137143
extern cl::opt<bool> UseNewDbgInfoFormat;
138144

139145
static ExitOnError ExitOnErr;

0 commit comments

Comments
 (0)