Skip to content

Commit db4b0a7

Browse files
committedFeb 13, 2017
[LTO] Add support for optimization remarks.
Differential Revision: https://reviews.llvm.org/D29878 llvm-svn: 294971
1 parent fbae5fc commit db4b0a7

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed
 

‎lld/ELF/Config.h

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct Configuration {
8282
llvm::StringRef LTONewPmPasses;
8383
llvm::StringRef MapFile;
8484
llvm::StringRef OutputFile;
85+
llvm::StringRef OptRemarksFilename;
8586
llvm::StringRef SoName;
8687
llvm::StringRef Sysroot;
8788
std::string RPath;
@@ -117,6 +118,7 @@ struct Configuration {
117118
bool Nostdlib;
118119
bool OFormatBinary;
119120
bool OMagic;
121+
bool OptRemarksWithHotness;
120122
bool Pic;
121123
bool Pie;
122124
bool PrintGcSections;

‎lld/ELF/Driver.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
533533
Config->NoUndefinedVersion = Args.hasArg(OPT_no_undefined_version);
534534
Config->Nostdlib = Args.hasArg(OPT_nostdlib);
535535
Config->OMagic = Args.hasArg(OPT_omagic);
536+
Config->OptRemarksWithHotness = Args.hasArg(OPT_opt_remarks_with_hotness);
536537
Config->Pie = getArg(Args, OPT_pie, OPT_nopie, false);
537538
Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections);
538539
Config->Relocatable = Args.hasArg(OPT_relocatable);
@@ -555,6 +556,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
555556
Config->LTOAAPipeline = getString(Args, OPT_lto_aa_pipeline);
556557
Config->LTONewPmPasses = getString(Args, OPT_lto_newpm_passes);
557558
Config->MapFile = getString(Args, OPT_Map);
559+
Config->OptRemarksFilename = getString(Args, OPT_opt_remarks_filename);
558560
Config->OutputFile = getString(Args, OPT_o);
559561
Config->SoName = getString(Args, OPT_soname);
560562
Config->Sysroot = getString(Args, OPT_sysroot);

‎lld/ELF/LTO.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ static std::unique_ptr<lto::LTO> createLTO() {
8181
Conf.OptPipeline = Config->LTONewPmPasses;
8282
Conf.AAPipeline = Config->LTOAAPipeline;
8383

84+
// Set up optimization remarks if we've been asked to.
85+
Conf.RemarksFilename = Config->OptRemarksFilename;
86+
Conf.RemarksWithHotness = Config->OptRemarksWithHotness;
87+
8488
if (Config->SaveTemps)
8589
checkError(Conf.addSaveTemps(std::string(Config->OutputFile) + ".",
8690
/*UseInputModulePath*/ true));

‎lld/ELF/Options.td

+4
Original file line numberDiff line numberDiff line change
@@ -385,5 +385,9 @@ def lto_partitions: J<"lto-partitions=">,
385385
HelpText<"Number of LTO codegen partitions">;
386386
def disable_verify: F<"disable-verify">;
387387
def mllvm: S<"mllvm">;
388+
def opt_remarks_filename: S<"opt-remarks-filename">,
389+
HelpText<"YAML output file for optimization remarks">;
390+
def opt_remarks_with_hotness: F<"opt-remarks-with-hotness">,
391+
HelpText<"Include hotness informations in the optimization remarks file">;
388392
def save_temps: F<"save-temps">;
389393
def thinlto_jobs: J<"thinlto-jobs=">, HelpText<"Number of ThinLTO jobs">;

‎lld/test/ELF/lto/opt-remarks.ll

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: llvm-as %s -o %t.o
2+
3+
; RUN: rm -f %t.yaml
4+
; RUN: ld.lld -opt-remarks-filename %t.yaml %t.o -o %t -shared -save-temps
5+
; RUN: llvm-dis %t.0.4.opt.bc -o - | FileCheck %s
6+
; RUN: ld.lld -opt-remarks-with-hotness -opt-remarks-filename %t.hot.yaml \
7+
; RUN: %t.o -o %t -shared
8+
; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
9+
; RUN: cat %t.hot.yaml | FileCheck %s -check-prefix=YAML-HOT
10+
11+
; Check that @tinkywinky is inlined after optimizations.
12+
; CHECK-LABEL: define i32 @main
13+
; CHECK-NEXT: %a.i = call i32 @patatino()
14+
; CHECK-NEXT: ret i32 %a.i
15+
; CHECK-NEXT: }
16+
17+
; YAML: --- !Analysis
18+
; YAML-NEXT: Pass: inline
19+
; YAML-NEXT: Name: CanBeInlined
20+
; YAML-NEXT: Function: main
21+
; YAML-NEXT: Args:
22+
; YAML-NEXT: - Callee: tinkywinky
23+
; YAML-NEXT: - String: ' can be 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+
; YAML-NEXT: --- !Passed
32+
; YAML-NEXT: Pass: inline
33+
; YAML-NEXT: Name: Inlined
34+
; YAML-NEXT: Function: main
35+
; YAML-NEXT: Args:
36+
; YAML-NEXT: - Callee: tinkywinky
37+
; YAML-NEXT: - String: ' inlined into '
38+
; YAML-NEXT: - Caller: main
39+
; YAML-NEXT: ...
40+
41+
; YAML-HOT: ...
42+
; YAML-HOT: --- !Passed
43+
; YAML-HOT: Pass: inline
44+
; YAML-HOT-NEXT: Name: Inlined
45+
; YAML-HOT-NEXT: Function: main
46+
; YAML-HOT-NEXT: Hotness: 300
47+
; YAML-HOT-NEXT: Args:
48+
; YAML-HOT-NEXT: - Callee: tinkywinky
49+
; YAML-HOT-NEXT: - String: ' inlined into '
50+
; YAML-HOT-NEXT: - Caller: main
51+
; YAML-HOT-NEXT: ...
52+
53+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
54+
target triple = "x86_64-scei-ps4"
55+
56+
declare i32 @patatino()
57+
58+
define i32 @tinkywinky() {
59+
%a = call i32 @patatino()
60+
ret i32 %a
61+
}
62+
63+
define i32 @main() !prof !0 {
64+
%i = call i32 @tinkywinky()
65+
ret i32 %i
66+
}
67+
68+
!0 = !{!"function_entry_count", i64 300}

0 commit comments

Comments
 (0)
Please sign in to comment.