Skip to content

Commit 66744f8

Browse files
committed
[ThinLTO] Support opt remarks options with distributed ThinLTO backends
Summary: Passes down the necessary code ge options to the LTO Config to enable -fdiagnostics-show-hotness and -fsave-optimization-record in the ThinLTO backend for a distributed build. Also, remove warning about not having PGO when the input is IR. Reviewers: pcc Subscribers: mehdi_amini, inglorion, eraman, cfe-commits Differential Revision: https://reviews.llvm.org/D46464 llvm-svn: 331592
1 parent 81d9207 commit 66744f8

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,8 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
11361136
Conf.SampleProfile = std::move(SampleProfile);
11371137
Conf.UseNewPM = CGOpts.ExperimentalNewPassManager;
11381138
Conf.DebugPassManager = CGOpts.DebugPassManager;
1139+
Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1140+
Conf.RemarksFilename = CGOpts.OptRecordFile;
11391141
switch (Action) {
11401142
case Backend_EmitNothing:
11411143
Conf.PreCodeGenModuleHook = [](size_t Task, const Module &Mod) {
@@ -1159,7 +1161,7 @@ static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M,
11591161
break;
11601162
}
11611163
if (Error E = thinBackend(
1162-
Conf, 0, AddStream, *M, *CombinedIndex, ImportList,
1164+
Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
11631165
ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) {
11641166
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
11651167
errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,9 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
10751075
bool UsingProfile = UsingSampleProfile ||
10761076
(Opts.getProfileUse() != CodeGenOptions::ProfileNone);
10771077

1078-
if (Opts.DiagnosticsWithHotness && !UsingProfile)
1078+
if (Opts.DiagnosticsWithHotness && !UsingProfile &&
1079+
// An IR file will contain PGO as metadata
1080+
IK.getLanguage() != InputKind::LLVM_IR)
10791081
Diags.Report(diag::warn_drv_diagnostics_hotness_requires_pgo)
10801082
<< "-fdiagnostics-show-hotness";
10811083

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; Test to ensure -fdiagnostics-show-hotness and -fsave-optimization-record
2+
; work when invoking the ThinLTO backend path.
3+
; RUN: opt -module-summary -o %t.o %s
4+
; RUN: llvm-lto -thinlto -o %t %t.o
5+
6+
; First try with pass remarks to stderr
7+
; RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -mllvm -pass-remarks=inline -fdiagnostics-show-hotness -o %t2.o -c 2>&1 | FileCheck %s
8+
9+
; CHECK: tinkywinky inlined into main with cost=0 (threshold=337) (hotness: 300)
10+
11+
; Next try YAML pass remarks file
12+
; RUN: rm -f %t2.opt.yaml
13+
; RUN: %clang -O2 -x ir %t.o -fthinlto-index=%t.thinlto.bc -fsave-optimization-record -fdiagnostics-show-hotness -o %t2.o -c
14+
; RUN: cat %t2.opt.yaml | FileCheck %s -check-prefix=YAML
15+
16+
; YAML: --- !Passed
17+
; YAML-NEXT: Pass: inline
18+
; YAML-NEXT: Name: Inlined
19+
; YAML-NEXT: Function: main
20+
; YAML-NEXT: Hotness: 300
21+
; YAML-NEXT: Args:
22+
; YAML-NEXT: - Callee: tinkywinky
23+
; YAML-NEXT: - String: ' inlined into '
24+
; YAML-NEXT: - Caller: main
25+
; YAML-NEXT: - String: ' with cost='
26+
; YAML-NEXT: - Cost: '0'
27+
; YAML-NEXT: - String: ' (threshold='
28+
; YAML-NEXT: - Threshold: '337'
29+
; YAML-NEXT: - String: ')'
30+
; YAML-NEXT: ...
31+
32+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
33+
target triple = "x86_64-scei-ps4"
34+
35+
declare i32 @patatino()
36+
37+
define i32 @tinkywinky() {
38+
%a = call i32 @patatino()
39+
ret i32 %a
40+
}
41+
42+
define i32 @main() !prof !0 {
43+
%i = call i32 @tinkywinky()
44+
ret i32 %i
45+
}
46+
47+
!0 = !{!"function_entry_count", i64 300}

clang/test/CodeGen/thinlto_backend.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929

3030
; Ensure f2 was imported. Check for all 3 flavors of -save-temps[=cwd|obj].
3131
; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc -save-temps=obj
32-
; RUN: llvm-dis %t1.s.0.3.import.bc -o - | FileCheck --check-prefix=CHECK-IMPORT %s
32+
; RUN: llvm-dis %t1.s.3.import.bc -o - | FileCheck --check-prefix=CHECK-IMPORT %s
3333
; RUN: mkdir -p %T/dir1
3434
; RUN: (cd %T/dir1 && %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc -save-temps=cwd)
35-
; RUN: llvm-dis %T/dir1/*1.s.0.3.import.bc -o - | FileCheck --check-prefix=CHECK-IMPORT %s
35+
; RUN: llvm-dis %T/dir1/*1.s.3.import.bc -o - | FileCheck --check-prefix=CHECK-IMPORT %s
3636
; RUN: mkdir -p %T/dir2
3737
; RUN: (cd %T/dir2 && %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc -save-temps)
38-
; RUN: llvm-dis %T/dir2/*1.s.0.3.import.bc -o - | FileCheck --check-prefix=CHECK-IMPORT %s
38+
; RUN: llvm-dis %T/dir2/*1.s.3.import.bc -o - | FileCheck --check-prefix=CHECK-IMPORT %s
3939
; CHECK-IMPORT: define available_externally void @f2()
4040
; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
4141
; CHECK-OBJ: T f1

0 commit comments

Comments
 (0)