[lld] 1c04b52 - [LTO][ELF] Add --stats-file= option.
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 16 21:01:50 PDT 2022
Author: wangliushuai
Date: 2022-03-17T12:01:39+08:00
New Revision: 1c04b52b2594d403f739ed919ef420b1e47ae343
URL: https://github.com/llvm/llvm-project/commit/1c04b52b2594d403f739ed919ef420b1e47ae343
DIFF: https://github.com/llvm/llvm-project/commit/1c04b52b2594d403f739ed919ef420b1e47ae343.diff
LOG: [LTO][ELF] Add --stats-file= option.
This patch adds a StatsFile option supported by gold to lld, related patch https://reviews.llvm.org/D45531.
Reviewed By: tejohnson, MaskRay
Differential Revision: https://reviews.llvm.org/D121809
Added:
lld/test/ELF/lto/stats-file-option.ll
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/ELF/Options.td
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index c05adb5d178c5..59df5ee596f61 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -122,6 +122,7 @@ struct Configuration {
llvm::Optional<uint64_t> optRemarksHotnessThreshold = 0;
llvm::StringRef optRemarksPasses;
llvm::StringRef optRemarksFormat;
+ llvm::StringRef optStatsFilename;
llvm::StringRef progName;
llvm::StringRef printArchiveStats;
llvm::StringRef printSymbolOrder;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index c51349d4a53a0..ebf0de0949f4f 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1103,6 +1103,7 @@ static void readConfigs(opt::InputArgList &args) {
config->oFormatBinary = isOutputFormatBinary(args);
config->omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);
config->optRemarksFilename = args.getLastArgValue(OPT_opt_remarks_filename);
+ config->optStatsFilename = args.getLastArgValue(OPT_opt_stats_filename);
// Parse remarks hotness threshold. Valid value is either integer or 'auto'.
if (auto *arg = args.getLastArg(OPT_opt_remarks_hotness_threshold)) {
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index a6c6e65b1619e..9ac21ddf18846 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -142,6 +142,9 @@ static lto::Config createConfig() {
c.RemarksHotnessThreshold = config->optRemarksHotnessThreshold;
c.RemarksFormat = std::string(config->optRemarksFormat);
+ // Set up output file to emit statistics.
+ c.StatsFile = std::string(config->optStatsFilename);
+
c.SampleProfile = std::string(config->ltoSampleProfile);
c.UseNewPM = config->ltoNewPassManager;
c.DebugPassManager = config->ltoDebugPassManager;
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index e50fa2b235717..43c163b94b419 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -583,6 +583,8 @@ def opt_remarks_with_hotness: FF<"opt-remarks-with-hotness">,
HelpText<"Include hotness information in the optimization remarks file">;
def opt_remarks_format: Separate<["--"], "opt-remarks-format">,
HelpText<"The format used for serializing remarks (default: YAML)">;
+def opt_stats_filename: JJ<"stats-file=">,
+ HelpText<"Filename to write statistics to">;
def save_temps: F<"save-temps">, HelpText<"Save intermediate LTO compilation results">;
def lto_basic_block_sections: JJ<"lto-basic-block-sections=">,
HelpText<"Enable basic block sections for LTO">;
diff --git a/lld/test/ELF/lto/stats-file-option.ll b/lld/test/ELF/lto/stats-file-option.ll
new file mode 100644
index 0000000000000..fe39001ab192d
--- /dev/null
+++ b/lld/test/ELF/lto/stats-file-option.ll
@@ -0,0 +1,28 @@
+; RUN: llvm-as -o %t.bc %s
+
+;; Try to save statistics to file.
+; RUN: ld.lld --stats-file=%t2.stats -m elf_x86_64 -r -o %t.o %t.bc
+; RUN: FileCheck --input-file=%t2.stats %s
+
+; CHECK: {
+; CHECK: "asm-printer.EmittedInsts":
+; CHECK: "inline.NumInlined":
+; CHECK: "prologepilog.NumFuncSeen":
+; CHECK: }
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare i32 @patatino()
+
+define i32 @tinkywinky() {
+ %a = call i32 @patatino()
+ ret i32 %a
+}
+
+define i32 @main() !prof !0 {
+ %i = call i32 @tinkywinky()
+ ret i32 %i
+}
+
+!0 = !{!"function_entry_count", i64 300}
More information about the llvm-commits
mailing list