1
- # Profile Guided Optimization
1
+ # Profile-guided optimization
2
2
3
3
<!-- toc -->
4
4
5
5
` rustc ` supports doing profile-guided optimization (PGO).
6
6
This chapter describes what PGO is and how the support for it is
7
7
implemented in ` rustc ` .
8
8
9
- ## What Is Profiled-Guided Optimization ?
9
+ ## What is profiled-guided optimization ?
10
10
11
11
The basic concept of PGO is to collect data about the typical execution of
12
12
a program (e.g. which branches it is likely to take) and then use this data
@@ -52,7 +52,7 @@ instrumentation, via the experimental option
52
52
[ ` -C instrument-coverage ` ] ( ./llvm-coverage-instrumentation.md ) , but using these
53
53
coverage results for PGO has not been attempted at this time.
54
54
55
- ### Overall Workflow
55
+ ### Overall workflow
56
56
57
57
Generating a PGO-optimized program involves the following four steps:
58
58
@@ -62,12 +62,12 @@ Generating a PGO-optimized program involves the following four steps:
62
62
4 . Compile the program again, this time making use of the profiling data
63
63
(e.g. ` rustc -C profile-use=merged.profdata main.rs ` )
64
64
65
- ### Compile-Time Aspects
65
+ ### Compile-time aspects
66
66
67
67
Depending on which step in the above workflow we are in, two different things
68
68
can happen at compile time:
69
69
70
- #### Create Binaries with Instrumentation
70
+ #### Create binaries with instrumentation
71
71
72
72
As mentioned above, the profiling instrumentation is added by LLVM.
73
73
` rustc ` instructs LLVM to do so [ by setting the appropriate] [ pgo-gen-passmanager ]
@@ -88,7 +88,7 @@ runtime are not removed [by marking the with the right export level][pgo-gen-sym
88
88
[pgo-gen-symbols]:https://github.com/rust-lang/rust/blob/1.34.1/src/librustc_codegen_ssa/back/symbol_export.rs#L212-L225
89
89
90
90
91
- #### Compile Binaries Where Optimizations Make Use Of Profiling Data
91
+ #### Compile binaries where optimizations make use of profiling data
92
92
93
93
In the final step of the workflow described above, the program is compiled
94
94
again, with the compiler using the gathered profiling data in order to drive
@@ -106,7 +106,7 @@ LLVM does the rest (e.g. setting branch weights, marking functions with
106
106
` cold ` or ` inlinehint ` , etc).
107
107
108
108
109
- ### Runtime Aspects
109
+ ### Runtime aspects
110
110
111
111
Instrumentation-based approaches always also have a runtime component, i.e.
112
112
once we have an instrumented program, that program needs to be run in order
@@ -134,7 +134,7 @@ instrumentation artifacts show up in LLVM IR.
134
134
[ rmake-tests ] : https://github.com/rust-lang/rust/tree/master/tests/run-make
135
135
[ codegen-test ] : https://github.com/rust-lang/rust/blob/master/tests/codegen/pgo-instrumentation.rs
136
136
137
- ## Additional Information
137
+ ## Additional information
138
138
139
139
Clang's documentation contains a good overview on [ PGO in LLVM] [ llvm-pgo ] .
140
140
0 commit comments