[lld] 2d9d291 - [LLD] Do not combine cg_profile from obj and ordering file (#121325)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 4 18:38:18 PST 2025
Author: Haohai Wen
Date: 2025-01-05T10:38:14+08:00
New Revision: 2d9d291da0fb94c05b31de0b08ccb881dbead798
URL: https://github.com/llvm/llvm-project/commit/2d9d291da0fb94c05b31de0b08ccb881dbead798
DIFF: https://github.com/llvm/llvm-project/commit/2d9d291da0fb94c05b31de0b08ccb881dbead798.diff
LOG: [LLD] Do not combine cg_profile from obj and ordering file (#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.
Added:
Modified:
lld/COFF/Driver.cpp
lld/ELF/Driver.cpp
lld/test/COFF/cgprofile-obj.s
lld/test/ELF/cgprofile-obj.s
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 83d3f5d4cf99c6..791382fd9bdd4a 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2878,10 +2878,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// Handle /call-graph-ordering-file and /call-graph-profile-sort (default on).
if (config->callGraphProfileSort) {
llvm::TimeTraceScope timeScope("Call graph");
- if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) {
+ if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file))
parseCallGraphFile(arg->getValue());
- }
- readCallGraphsFromObjectFiles(ctx);
+ else
+ readCallGraphsFromObjectFiles(ctx);
}
// Handle /print-symbol-order.
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index f573a8d3e19f3b..e8e99fa874b5d5 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -3215,11 +3215,12 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
// Read the callgraph now that we know what was gced or icfed
if (ctx.arg.callGraphProfileSort != CGProfileSortKind::None) {
- if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file))
+ if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file)) {
if (std::optional<MemoryBufferRef> buffer =
readFile(ctx, arg->getValue()))
readCallGraph(ctx, *buffer);
- readCallGraphsFromObjectFiles<ELFT>(ctx);
+ } else
+ readCallGraphsFromObjectFiles<ELFT>(ctx);
}
// Write the result to the file.
diff --git a/lld/test/COFF/cgprofile-obj.s b/lld/test/COFF/cgprofile-obj.s
index 3cb16df80eb468..756279a8b5759a 100644
--- a/lld/test/COFF/cgprofile-obj.s
+++ b/lld/test/COFF/cgprofile-obj.s
@@ -46,7 +46,7 @@ Aa:
# NO-CG: 140001002 T B
# NO-CG: 140001003 T A
-# CG-OBJ-OF: 140001000 T C
-# CG-OBJ-OF: 140001001 t D
-# CG-OBJ-OF: 140001002 T A
-# CG-OBJ-OF: 140001003 T B
+# CG-OBJ-OF: 140001000 t D
+# CG-OBJ-OF: 140001001 T A
+# CG-OBJ-OF: 140001004 T C
+# CG-OBJ-OF: 140001005 T B
\ No newline at end of file
diff --git a/lld/test/ELF/cgprofile-obj.s b/lld/test/ELF/cgprofile-obj.s
index 82c5d035540a95..14016658707af4 100644
--- a/lld/test/ELF/cgprofile-obj.s
+++ b/lld/test/ELF/cgprofile-obj.s
@@ -49,7 +49,7 @@ Aa:
# NO-CG: 0000000000201122 T B
# NO-CG: 0000000000201123 T A
-# CG-OBJ-OF: 0000000000201121 t D
-# CG-OBJ-OF: 0000000000201120 T C
-# CG-OBJ-OF: 0000000000201123 T B
-# CG-OBJ-OF: 0000000000201122 T A
+# CG-OBJ-OF: 0000000000201120 t D
+# CG-OBJ-OF: 0000000000201124 T C
+# CG-OBJ-OF: 0000000000201125 T B
+# CG-OBJ-OF: 0000000000201121 T A
More information about the llvm-commits
mailing list