Skip to content

Commit 1c04b52

Browse files
[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
1 parent b8038a9 commit 1c04b52

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

lld/ELF/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct Configuration {
122122
llvm::Optional<uint64_t> optRemarksHotnessThreshold = 0;
123123
llvm::StringRef optRemarksPasses;
124124
llvm::StringRef optRemarksFormat;
125+
llvm::StringRef optStatsFilename;
125126
llvm::StringRef progName;
126127
llvm::StringRef printArchiveStats;
127128
llvm::StringRef printSymbolOrder;

lld/ELF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ static void readConfigs(opt::InputArgList &args) {
11031103
config->oFormatBinary = isOutputFormatBinary(args);
11041104
config->omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);
11051105
config->optRemarksFilename = args.getLastArgValue(OPT_opt_remarks_filename);
1106+
config->optStatsFilename = args.getLastArgValue(OPT_opt_stats_filename);
11061107

11071108
// Parse remarks hotness threshold. Valid value is either integer or 'auto'.
11081109
if (auto *arg = args.getLastArg(OPT_opt_remarks_hotness_threshold)) {

lld/ELF/LTO.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ static lto::Config createConfig() {
142142
c.RemarksHotnessThreshold = config->optRemarksHotnessThreshold;
143143
c.RemarksFormat = std::string(config->optRemarksFormat);
144144

145+
// Set up output file to emit statistics.
146+
c.StatsFile = std::string(config->optStatsFilename);
147+
145148
c.SampleProfile = std::string(config->ltoSampleProfile);
146149
c.UseNewPM = config->ltoNewPassManager;
147150
c.DebugPassManager = config->ltoDebugPassManager;

lld/ELF/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ def opt_remarks_with_hotness: FF<"opt-remarks-with-hotness">,
583583
HelpText<"Include hotness information in the optimization remarks file">;
584584
def opt_remarks_format: Separate<["--"], "opt-remarks-format">,
585585
HelpText<"The format used for serializing remarks (default: YAML)">;
586+
def opt_stats_filename: JJ<"stats-file=">,
587+
HelpText<"Filename to write statistics to">;
586588
def save_temps: F<"save-temps">, HelpText<"Save intermediate LTO compilation results">;
587589
def lto_basic_block_sections: JJ<"lto-basic-block-sections=">,
588590
HelpText<"Enable basic block sections for LTO">;

lld/test/ELF/lto/stats-file-option.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llvm-as -o %t.bc %s
2+
3+
;; Try to save statistics to file.
4+
; RUN: ld.lld --stats-file=%t2.stats -m elf_x86_64 -r -o %t.o %t.bc
5+
; RUN: FileCheck --input-file=%t2.stats %s
6+
7+
; CHECK: {
8+
; CHECK: "asm-printer.EmittedInsts":
9+
; CHECK: "inline.NumInlined":
10+
; CHECK: "prologepilog.NumFuncSeen":
11+
; CHECK: }
12+
13+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
14+
target triple = "x86_64-unknown-linux-gnu"
15+
16+
declare i32 @patatino()
17+
18+
define i32 @tinkywinky() {
19+
%a = call i32 @patatino()
20+
ret i32 %a
21+
}
22+
23+
define i32 @main() !prof !0 {
24+
%i = call i32 @tinkywinky()
25+
ret i32 %i
26+
}
27+
28+
!0 = !{!"function_entry_count", i64 300}

0 commit comments

Comments
 (0)