Skip to content

Commit f34ddbb

Browse files
committed
s to z
1 parent 1de6b6d commit f34ddbb

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

text/0000-optimise-attr.md renamed to text/0000-optimize-attr.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66
# Summary
77
[summary]: #summary
88

9-
This RFC introduces the `#[optimize]` attribute for controlling optimisation level on a per-item
9+
This RFC introduces the `#[optimize]` attribute for controlling optimization level on a per-item
1010
basis.
1111

1212
# Motivation
1313
[motivation]: #motivation
1414

15-
Currently, rustc has only a small number of optimisation options that apply globally to the
15+
Currently, rustc has only a small number of optimization options that apply globally to the
1616
crate. With LTO and RLIB-only crates these options become applicable to a whole-program, which
17-
reduces the ability to control optimisation even further.
17+
reduces the ability to control optimization even further.
1818

1919
For applications such as embedded, it is critical, that they satisfy the size constraints. This
20-
means, that code must consciously pick one or the other optimisation level. Absence of a method to
21-
selectively optimise different parts of a program in different ways precludes users from utilising
20+
means, that code must consciously pick one or the other optimization level. Absence of a method to
21+
selectively optimize different parts of a program in different ways precludes users from utilising
2222
the hardware they have to the greatest degree.
2323

24-
With a C toolchain selective optimisation is fairly easy to achieve by compiling the relevant
24+
With a C toolchain selective optimization is fairly easy to achieve by compiling the relevant
2525
codegen units (objects) with different options. In Rust ecosystem, where the concept of such units
2626
does not exist, an alternate solution is necessary.
2727

28-
With the `#[optimize]` attribute it is possible to annotate the optimisation level of separate
29-
items, so that they are optimized differently from the global optimisation option.
28+
With the `#[optimize]` attribute it is possible to annotate the optimization level of separate
29+
items, so that they are optimized differently from the global optimization option.
3030

3131
# Guide-level explanation
3232
[guide-level-explanation]: #guide-level-explanation
3333

3434
## `#[optimize(size)]`
3535

36-
Sometimes, optimisations are a trade-off between execution time and the code size. Some
37-
optimisations, such as loop unrolling increase code size many times on average (compared to
38-
original function size) for marginal performance benefits. In case such optimisation is not
36+
Sometimes, optimizations are a trade-off between execution time and the code size. Some
37+
optimizations, such as loop unrolling increase code size many times on average (compared to
38+
original function size) for marginal performance benefits. In case such optimization is not
3939
desirable…
4040

4141
```rust
@@ -59,7 +59,7 @@ opt-level=z`.
5959

6060
## `#[optimize(speed)]`
6161

62-
Conversely, when one of the global optimisation options for code size is used (`-Copt-level=s` or
62+
Conversely, when one of the global optimization options for code size is used (`-Copt-level=s` or
6363
`-Copt-level=z`), profiling might reveal some functions that are unnecessarily “hot”. In that case,
6464
those functions may be annotated with the `#[optimize(speed)]` to make the compiler make its best
6565
effort to produce faster code.
@@ -72,17 +72,17 @@ fn banana() {
7272
```
7373

7474
Much like with `#[optimize(size)]`, the `speed` counterpart is also a hint and will likely not
75-
yield the same results as using the global optimisation option for speed.
75+
yield the same results as using the global optimization option for speed.
7676

7777
# Reference-level explanation
7878
[reference-level-explanation]: #reference-level-explanation
7979

80-
The `#[optimize(size)]` attribute applied to an item or expression will instruct the optimisation
81-
pipeline to avoid applying optimisations that could result in a size increase and machine code
80+
The `#[optimize(size)]` attribute applied to an item or expression will instruct the optimization
81+
pipeline to avoid applying optimizations that could result in a size increase and machine code
8282
generator to generate code that’s smaller rather than faster.
8383

84-
The `#[optimize(speed)]` attribute applied to an item or expression will instruct the optimisation
85-
pipeline to apply optimisations that are likely to yield performance wins and machine code
84+
The `#[optimize(speed)]` attribute applied to an item or expression will instruct the optimization
85+
pipeline to apply optimizations that are likely to yield performance wins and machine code
8686
generator to generate code that’s faster rather than smaller.
8787

8888
The `#[optimize]` attributes are just a hint to the compiler and are not guaranteed to result in
@@ -99,8 +99,8 @@ function will propagate to other functions or closures defined within the body o
9999
It is an error to specify multiple incompatible `#[optimize]` options to a single item or
100100
expression at once. A more explicit `#[optimize]` attribute overrides a propagated attribute.
101101

102-
`#[optimize(speed)]` is a no-op when a global optimisation for speed option is set (i.e. `-C
103-
opt-level=1-3`). Similarly `#[optimize(size)]` is a no-op when a global optimisation for size
102+
`#[optimize(speed)]` is a no-op when a global optimization for speed option is set (i.e. `-C
103+
opt-level=1-3`). Similarly `#[optimize(size)]` is a no-op when a global optimization for size
104104
option is set (i.e. `-C opt-level=s/z`). `#[optimize]` attributes are no-op when no optimizations
105105
are done globally (i.e. `-C opt-level=0`). In all other cases the *exact* interaction of the
106106
`#[optimize]` attribute with the global optimization level is not specified and is left up to
@@ -119,7 +119,7 @@ For the LLVM backend, these attributes may be implemented in a following manner:
119119
`#[optimize(size)]` – explicit function attributes exist at LLVM level. Items with
120120
`optimize(size)` would simply apply the LLVM attributes to the functions.
121121

122-
`#[optimize(speed)]` in conjunction with `-C opt-level=s/z` – use a global optimisation level of
122+
`#[optimize(speed)]` in conjunction with `-C opt-level=s/z` – use a global optimization level of
123123
`-C opt-level=2/3` and apply the equivalent LLVM function attribute (`optsize`, `minsize`) to all
124124
items which do not have an `#[optimize(speed)]` attribute.
125125

@@ -128,16 +128,16 @@ items which do not have an `#[optimize(speed)]` attribute.
128128

129129
* Not all of the alternative codegen backends may be able to express such a request, hence the
130130
“this is a hint” note on the `#[optimize]` attribute.
131-
* As a fallback, this attribute may be implemented in terms of more specific optimisation hints
131+
* As a fallback, this attribute may be implemented in terms of more specific optimization hints
132132
(such as `inline(never)`, the future `unroll(never)` etc).
133133

134134
# Rationale and alternatives
135135
[alternatives]: #alternatives
136136

137137
Proposed is a very semantic solution (describes the desired result, instead of behaviour) to the
138-
problem of needing to sometimes inhibit some of the trade-off optimisations such as loop unrolling.
138+
problem of needing to sometimes inhibit some of the trade-off optimizations such as loop unrolling.
139139

140-
Alternative, of course, would be to add attributes controlling such optimisations, such as
140+
Alternative, of course, would be to add attributes controlling such optimizations, such as
141141
`#[unroll(no)]` on top of a loop statement. There’s already precedent for this in the `#[inline]`
142142
annotations.
143143

@@ -148,15 +148,15 @@ attributes for people who know *why* the code is not satisfactory.
148148
Furthermore, currently `optimize` is able to do more than any possible combination of targeted
149149
attributes would be able to such as influencing the instruction selection or switch codegen
150150
strategy (jump table, if chain, etc.) This makes the attribute useful even in presence of all the
151-
targeted optimisation knobs we might have in the future.
151+
targeted optimization knobs we might have in the future.
152152

153153
# Prior art
154154
[prior-art]: #prior-art
155155

156156
* LLVM: `optsize`, `optnone`, `minsize` function attributes (exposed in Clang in some way);
157-
* GCC: `__attribute__((optimize))` function attribute which allows setting the optimisation level
157+
* GCC: `__attribute__((optimize))` function attribute which allows setting the optimization level
158158
and using certain(?) `-f` flags for each function;
159-
* IAR: Optimisations have a check box for “No size constraints”, which allows compiler to go out of
159+
* IAR: Optimizations have a check box for “No size constraints”, which allows compiler to go out of
160160
its way to optimize without considering the size trade-off. Can only be applied on a
161161
per-compilation-unit basis. Enabled by default, as is appropriate for a compiler targeting
162162
embedded use-cases.
@@ -166,8 +166,8 @@ embedded use-cases.
166166

167167
* Should we also implement `optimize(always)`? `optimize(level=x)`?
168168
* Left for future discussion, but should make sure such extension is possible.
169-
* Should there be any way to specify what global optimisation for speed level is used in
170-
conjunction with the optimisation for speed option (e.g. `-Copt-level=s3` could be equivalent to
169+
* Should there be any way to specify what global optimization for speed level is used in
170+
conjunction with the optimization for speed option (e.g. `-Copt-level=s3` could be equivalent to
171171
`-Copt-level=3` and `#[optimize(size)]` on the crate item);
172172
* This may matter for users of `#[optimize(speed)]`.
173173
* Are the propagation and `unused_attr` approaches right?

0 commit comments

Comments
 (0)