llvm.org GIT mirror llvm / 48ba666
[gold] Add support for optimization remarks Summary: Adds support for LTO opt remarks (optionally with hotness) to gold-plugin. Reviewers: anemet Subscribers: fhahn, mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D45752 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330252 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 2 years ago
2 changed file(s) with 88 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ; Test plugin options for opt-remarks.
1 ; RUN: llvm-as %s -o %t.o
2 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \
3 ; RUN: -plugin-opt=save-temps \
4 ; RUN: -plugin-opt=opt-remarks-filename=%t.yaml %t.o -o %t2.o 2>&1
5 ; RUN: llvm-dis %t2.o.0.4.opt.bc -o - | FileCheck %s
6 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext -shared \
7 ; RUN: -plugin-opt=opt-remarks-with-hotness \
8 ; RUN: -plugin-opt=opt-remarks-filename=%t.hot.yaml %t.o -o %t2.o 2>&1
9 ; RUN: cat %t.yaml | FileCheck %s -check-prefix=YAML
10 ; RUN: cat %t.hot.yaml | FileCheck %s -check-prefix=YAML-HOT
11
12 ; Check that @f is inlined after optimizations.
13 ; CHECK-LABEL: define i32 @_start
14 ; CHECK-NEXT: %a.i = call i32 @bar()
15 ; CHECK-NEXT: ret i32 %a.i
16 ; CHECK-NEXT: }
17
18 ; YAML: --- !Missed
19 ; YAML-NEXT: Pass: inline
20 ; YAML-NEXT: Name: NoDefinition
21 ; YAML-NEXT: Function: f
22 ; YAML-NEXT: Args:
23 ; YAML-NEXT: - Callee: bar
24 ; YAML-NEXT: - String: ' will not be inlined into '
25 ; YAML-NEXT: - Caller: f
26 ; YAML-NEXT: - String: ' because its definition is unavailable'
27 ; YAML-NEXT: ...
28 ; YAML-NEXT: --- !Passed
29 ; YAML-NEXT: Pass: inline
30 ; YAML-NEXT: Name: Inlined
31 ; YAML-NEXT: Function: _start
32 ; YAML-NEXT: Args:
33 ; YAML-NEXT: - Callee: f
34 ; YAML-NEXT: - String: ' inlined into '
35 ; YAML-NEXT: - Caller: _start
36 ; YAML-NEXT: - String: ' with cost='
37 ; YAML-NEXT: - Cost: '0'
38 ; YAML-NEXT: - String: ' (threshold='
39 ; YAML-NEXT: - Threshold: '337'
40 ; YAML-NEXT: - String: ')'
41 ; YAML-NEXT: ...
42
43 ; YAML-HOT: ...
44 ; YAML-HOT: --- !Passed
45 ; YAML-HOT: Pass: inline
46 ; YAML-HOT-NEXT: Name: Inlined
47 ; YAML-HOT-NEXT: Function: _start
48 ; YAML-HOT-NEXT: Hotness: 300
49 ; YAML-HOT-NEXT: Args:
50 ; YAML-HOT-NEXT: - Callee: f
51 ; YAML-HOT-NEXT: - String: ' inlined into '
52 ; YAML-HOT-NEXT: - Caller: _start
53 ; YAML-HOT-NEXT: - String: ' with cost='
54 ; YAML-HOT-NEXT: - Cost: '0'
55 ; YAML-HOT-NEXT: - String: ' (threshold='
56 ; YAML-HOT-NEXT: - Threshold: '337'
57 ; YAML-HOT-NEXT: - String: ')'
58 ; YAML-HOT-NEXT: ...
59
60 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
61 target triple = "x86_64-unknown-linux-gnu"
62
63 declare i32 @bar()
64
65 define i32 @f() {
66 %a = call i32 @bar()
67 ret i32 %a
68 }
69
70 define i32 @_start() !prof !0 {
71 %call = call i32 @f()
72 ret i32 %call
73 }
74
75 !0 = !{!"function_entry_count", i64 300}
203203 // Directory to store the .dwo files.
204204 static std::string dwo_dir;
205205
206 // Optimization remarks filename and hotness options
207 static std::string OptRemarksFilename;
208 static bool OptRemarksWithHotness = false;
209
206210 static void process_plugin_option(const char *opt_)
207211 {
208212 if (opt_ == nullptr)
269273 objcopy = opt.substr(strlen("objcopy="));
270274 } else if (opt.startswith("dwo_dir=")) {
271275 dwo_dir = opt.substr(strlen("dwo_dir="));
276 } else if (opt.startswith("opt-remarks-filename=")) {
277 OptRemarksFilename = opt.substr(strlen("opt-remarks-filename="));
278 } else if (opt == "opt-remarks-with-hotness") {
279 OptRemarksWithHotness = true;
272280 } else {
273281 // Save this option to pass to the code generator.
274282 // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
880888 Conf.DwoDir = options::dwo_dir;
881889
882890 Conf.Objcopy = options::objcopy;
891
892 // Set up optimization remarks handling.
893 Conf.RemarksFilename = options::OptRemarksFilename;
894 Conf.RemarksWithHotness = options::OptRemarksWithHotness;
883895
884896 // Use new pass manager if set in driver
885897 Conf.UseNewPM = options::new_pass_manager;