Skip to content

Commit 2d9d291

Browse files
authored
[LLD] Do not combine cg_profile from obj and ordering file (llvm#121325)
cg_profile in object is from CGProfilePass and it is often inaccurate. While call-graph-ordering-file is provided by user. It is weird to aggregate them together especially when call-graph-ordering-file is accurate enough.
1 parent 36dd421 commit 2d9d291

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

lld/COFF/Driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,10 +2878,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
28782878
// Handle /call-graph-ordering-file and /call-graph-profile-sort (default on).
28792879
if (config->callGraphProfileSort) {
28802880
llvm::TimeTraceScope timeScope("Call graph");
2881-
if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) {
2881+
if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file))
28822882
parseCallGraphFile(arg->getValue());
2883-
}
2884-
readCallGraphsFromObjectFiles(ctx);
2883+
else
2884+
readCallGraphsFromObjectFiles(ctx);
28852885
}
28862886

28872887
// Handle /print-symbol-order.

lld/ELF/Driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,11 +3215,12 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
32153215

32163216
// Read the callgraph now that we know what was gced or icfed
32173217
if (ctx.arg.callGraphProfileSort != CGProfileSortKind::None) {
3218-
if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file))
3218+
if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) {
32193219
if (std::optional<MemoryBufferRef> buffer =
32203220
readFile(ctx, arg->getValue()))
32213221
readCallGraph(ctx, *buffer);
3222-
readCallGraphsFromObjectFiles<ELFT>(ctx);
3222+
} else
3223+
readCallGraphsFromObjectFiles<ELFT>(ctx);
32233224
}
32243225

32253226
// Write the result to the file.

lld/test/COFF/cgprofile-obj.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Aa:
4646
# NO-CG: 140001002 T B
4747
# NO-CG: 140001003 T A
4848

49-
# CG-OBJ-OF: 140001000 T C
50-
# CG-OBJ-OF: 140001001 t D
51-
# CG-OBJ-OF: 140001002 T A
52-
# CG-OBJ-OF: 140001003 T B
49+
# CG-OBJ-OF: 140001000 t D
50+
# CG-OBJ-OF: 140001001 T A
51+
# CG-OBJ-OF: 140001004 T C
52+
# CG-OBJ-OF: 140001005 T B

lld/test/ELF/cgprofile-obj.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Aa:
4949
# NO-CG: 0000000000201122 T B
5050
# NO-CG: 0000000000201123 T A
5151

52-
# CG-OBJ-OF: 0000000000201121 t D
53-
# CG-OBJ-OF: 0000000000201120 T C
54-
# CG-OBJ-OF: 0000000000201123 T B
55-
# CG-OBJ-OF: 0000000000201122 T A
52+
# CG-OBJ-OF: 0000000000201120 t D
53+
# CG-OBJ-OF: 0000000000201124 T C
54+
# CG-OBJ-OF: 0000000000201125 T B
55+
# CG-OBJ-OF: 0000000000201121 T A

0 commit comments

Comments
 (0)