Skip to content

Commit a9fe23c

Browse files
[LLD] [COFF] Port -lto-sample-profile to COFF version of LLD (#85701)
Following the commit of #83972 which added COFF support for SPGO, this patch ports the support of the option -lto-sample-profile that was only available in the ELF variant of LLD to the COFF variant to enable running the SPGO passes in the LTO/thinLTO pipelines.
1 parent 647d75d commit a9fe23c

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

lld/COFF/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ struct Configuration {
263263
// Used for /lto-pgo-warn-mismatch:
264264
bool ltoPGOWarnMismatch = true;
265265

266+
// Used for /lto-sample-profile:
267+
llvm::StringRef ltoSampleProfileName;
268+
266269
// Used for /call-graph-ordering-file:
267270
llvm::MapVector<std::pair<const SectionChunk *, const SectionChunk *>,
268271
uint64_t>

lld/COFF/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
20282028
config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);
20292029
config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate);
20302030
config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file);
2031+
config->ltoSampleProfileName = args.getLastArgValue(OPT_lto_sample_profile);
20312032
// Handle miscellaneous boolean flags.
20322033
config->ltoPGOWarnMismatch = args.hasFlag(OPT_lto_pgo_warn_mismatch,
20332034
OPT_lto_pgo_warn_mismatch_no, true);

lld/COFF/LTO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ lto::Config BitcodeCompiler::createConfig() {
8686
c.CSIRProfile = std::string(ctx.config.ltoCSProfileFile);
8787
c.RunCSIRInstr = ctx.config.ltoCSProfileGenerate;
8888
c.PGOWarnMismatch = ctx.config.ltoPGOWarnMismatch;
89+
c.SampleProfile = ctx.config.ltoSampleProfileName;
8990
c.TimeTraceEnabled = ctx.config.timeTraceEnabled;
9091
c.TimeTraceGranularity = ctx.config.timeTraceGranularity;
9192

lld/COFF/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def lldltocachepolicy : P<"lldltocachepolicy",
7979
"Pruning policy for the ThinLTO cache">;
8080
def lldsavetemps : F<"lldsavetemps">,
8181
HelpText<"Save intermediate LTO compilation results">;
82+
def lto_sample_profile: P<"lto-sample-profile", "Sample profile file path">;
8283
def machine : P<"machine", "Specify target platform">;
8384
def merge : P<"merge", "Combine sections">;
8485
def mllvm : P<"mllvm", "Options to pass to LLVM">;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f:0:0

lld/test/COFF/lto-sample-profile.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; REQUIRES: x86
2+
; RUN: opt -module-summary %s -o %t1.o
3+
; RUN: opt -module-summary %p/Inputs/thinlto.ll -o %t2.o
4+
5+
; RUN: rm -f %t1.o.4.opt.bc
6+
; RUN: lld-link /lto-sample-profile:%p/Inputs/lto-sample-profile.prof /lldsavetemps /entry:f /subsystem:console %t1.o %t2.o /out:%t3.exe
7+
; RUN: opt -S %t1.o.4.opt.bc | FileCheck %s
8+
9+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10+
target triple = "x86_64-pc-windows-msvc19.0.24215"
11+
12+
; CHECK: ![[#]] = !{i32 1, !"ProfileSummary", ![[#]]}
13+
declare void @g(...)
14+
15+
define void @h() {
16+
ret void
17+
}
18+
define void @f() {
19+
entry:
20+
call void (...) @g()
21+
call void (...) @h()
22+
ret void
23+
}

0 commit comments

Comments
 (0)