Skip to content

Commit 30e688e

Browse files
authored
[lld][MachO] Add option to suppress mismatch profile errors (#65551)
Both ELF and COFF support `--no-lto-pgo-warn-mismatch` in https://reviews.llvm.org/D104431 to suppress warnings due to mismatching profile hashes. As profiles go stale, it becomes likely that some function's CFGs will change so that their profiles can no longer be used. This commit adds the linker option `--no-pgo-warn-mismatch` to suppress these warnings. Note that we do have the LLVM backend flag `no-pgo-warn-mismatch` https://github.com/llvm/llvm-project/blob/3df1a64ebad8f31231ba05cf6ff43a985fea9235/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp#L210 but that is set to true by default during LTO https://github.com/llvm/llvm-project/blob/3df1a64ebad8f31231ba05cf6ff43a985fea9235/llvm/include/llvm/LTO/Config.h#L76-L77
1 parent 3125bd4 commit 30e688e

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

lld/MachO/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct Configuration {
208208
bool ltoDebugPassManager = false;
209209
bool csProfileGenerate = false;
210210
llvm::StringRef csProfilePath;
211+
bool pgoWarnMismatch;
211212

212213
bool callGraphProfileSort = false;
213214
llvm::StringRef printSymbolOrder;

lld/MachO/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
16701670
config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);
16711671
config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate);
16721672
config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path);
1673+
config->pgoWarnMismatch =
1674+
args.hasFlag(OPT_pgo_warn_mismatch, OPT_no_pgo_warn_mismatch, true);
16731675
config->generateUuid = !args.hasArg(OPT_no_uuid);
16741676

16751677
for (const Arg *arg : args.filtered(OPT_alias)) {

lld/MachO/LTO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static lto::Config createConfig() {
7171
c.DebugPassManager = config->ltoDebugPassManager;
7272
c.CSIRProfile = std::string(config->csProfilePath);
7373
c.RunCSIRInstr = config->csProfileGenerate;
74+
c.PGOWarnMismatch = config->pgoWarnMismatch;
7475
c.OptLevel = config->ltoo;
7576
c.CGOptLevel = config->ltoCgo;
7677
if (config->saveTemps)

lld/MachO/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
include "llvm/Option/OptParser.td"
22

3+
multiclass BB<string name, string help1, string help2> {
4+
def NAME: Flag<["--"], name>, HelpText<help1>;
5+
def no_ # NAME: Flag<["--"], "no-" # name>, HelpText<help2>;
6+
}
7+
38
// Flags that lld/MachO understands but ld64 doesn't. These take
49
// '--' instead of '-' and use dashes instead of underscores, so
510
// they don't collide with the ld64 compat options.
@@ -130,6 +135,9 @@ def cs_profile_generate: Flag<["--"], "cs-profile-generate">,
130135
HelpText<"Perform context senstive PGO instrumentation">, Group<grp_lld>;
131136
def cs_profile_path: Joined<["--"], "cs-profile-path=">,
132137
HelpText<"Context sensitive profile file path">, Group<grp_lld>;
138+
defm pgo_warn_mismatch: BB<"pgo-warn-mismatch",
139+
"turn on warnings about profile cfg mismatch (default)",
140+
"turn off warnings about profile cfg mismatch">, Group<grp_lld>;
133141

134142
// This is a complete Options.td compiled from Apple's ld(1) manpage
135143
// dated 2018-03-07 and cross checked with ld64 source code in repo

lld/test/MachO/pgo-warn-mismatch.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; REQUIRES: x86
2+
3+
; RUN: rm -rf %t && split-file %s %t
4+
; RUN: llvm-as %t/a.ll -o %t/a.o
5+
; RUN: llvm-profdata merge %t/cs.proftext -o %t/cs.profdata
6+
7+
;; Ensure lld generates warnings for profile cfg mismatch.
8+
; RUN: not %lld -dylib --cs-profile-path=%t/cs.profdata %t/a.o -o /dev/null 2>&1 | FileCheck %s
9+
; RUN: not %lld -dylib --cs-profile-path=%t/cs.profdata --pgo-warn-mismatch %t/a.o -o /dev/null 2>&1 | FileCheck %s
10+
11+
;; Ensure lld will not generate warnings for profile cfg mismatch.
12+
; RUN: %lld -dylib --cs-profile-path=%t/cs.profdata --no-pgo-warn-mismatch %t/a.o -o /dev/null
13+
14+
; CHECK: function control flow change detected (hash mismatch) foo Hash = [[#]]
15+
16+
;--- a.ll
17+
target triple = "x86_64-apple-darwin"
18+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
19+
20+
define i32 @foo() {
21+
entry:
22+
ret i32 0
23+
}
24+
25+
;--- cs.proftext
26+
:csir
27+
_foo
28+
# Func Hash:
29+
2277602155505015273
30+
# Num Counters:
31+
2
32+
# Counter Values:
33+
1
34+
0

0 commit comments

Comments
 (0)