Skip to content

Commit

Permalink
Merge pull request torvalds#846 from ojeda/drop-optlevel-diff-c
Browse files Browse the repository at this point in the history
rust: drop support for different optimization levels than C
  • Loading branch information
ojeda authored Aug 1, 2022
2 parents 246f942 + fee989b commit 5f48fa8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 89 deletions.
6 changes: 2 additions & 4 deletions Documentation/rust/arch-support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
============ ================ ==============================================
Architecture Level of support Constraints
============ ================ ==============================================
``arm`` Maintained ``armv6`` and compatible only,
``RUST_OPT_LEVEL >= 2``.
``arm`` Maintained ``armv6`` and compatible only.
``arm64`` Maintained None.
``powerpc`` Maintained ``ppc64le`` only, ``RUST_OPT_LEVEL < 2``
requires ``CONFIG_THREAD_SHIFT=15``.
``powerpc`` Maintained ``ppc64le`` only.
``riscv`` Maintained ``riscv64`` only.
``x86`` Maintained ``x86_64`` only.
============ ================ ==============================================
14 changes: 3 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -819,27 +819,19 @@ KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)

ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
KBUILD_CFLAGS += -O2
KBUILD_RUSTFLAGS_OPT_LEVEL_MAP := 2
KBUILD_RUSTFLAGS += -Copt-level=2
else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
KBUILD_CFLAGS += -O3
KBUILD_RUSTFLAGS_OPT_LEVEL_MAP := 3
KBUILD_RUSTFLAGS += -Copt-level=3
else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -Os
KBUILD_RUSTFLAGS_OPT_LEVEL_MAP := s
KBUILD_RUSTFLAGS += -Copt-level=s
endif

# Always set `debug-assertions` and `overflow-checks` because their default
# depends on `opt-level` and `debug-assertions`, respectively.
KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
KBUILD_RUSTFLAGS += -Copt-level=$\
$(if $(CONFIG_RUST_OPT_LEVEL_SIMILAR_AS_CHOSEN_FOR_C),$(KBUILD_RUSTFLAGS_OPT_LEVEL_MAP))$\
$(if $(CONFIG_RUST_OPT_LEVEL_0),0)$\
$(if $(CONFIG_RUST_OPT_LEVEL_1),1)$\
$(if $(CONFIG_RUST_OPT_LEVEL_2),2)$\
$(if $(CONFIG_RUST_OPT_LEVEL_3),3)$\
$(if $(CONFIG_RUST_OPT_LEVEL_S),s)$\
$(if $(CONFIG_RUST_OPT_LEVEL_Z),z)

# Tell gcc to never replace conditional load with a non-conditional one
ifdef CONFIG_CC_IS_GCC
Expand Down
75 changes: 1 addition & 74 deletions lib/Kconfig.debug
Original file line number Diff line number Diff line change
Expand Up @@ -2720,81 +2720,9 @@ config RUST_OVERFLOW_CHECKS

If unsure, say Y.

choice
prompt "Optimization level"
default RUST_OPT_LEVEL_SIMILAR_AS_CHOSEN_FOR_C
depends on RUST
help
Controls rustc's `-Copt-level` codegen option.

This flag controls the optimization level.

If unsure, say "Similar as chosen for C".

config RUST_OPT_LEVEL_SIMILAR_AS_CHOSEN_FOR_C
bool "Similar as chosen for C"
help
This choice will pick a similar optimization level as chosen in
the "Compiler optimization level" for C:

-O2 is currently mapped to -Copt-level=2
-O3 is currently mapped to -Copt-level=3
-Os is currently mapped to -Copt-level=s

The mapping may change over time to follow the intended semantics
of the choice for C as sensibly as possible.

This is the default.

config RUST_OPT_LEVEL_0
bool "No optimizations (-Copt-level=0)"
help
Not recommended for most purposes. It may come in handy for debugging
suspected optimizer bugs, unexpected undefined behavior, etc.

Note that this level will *not* enable debug assertions nor overflow
checks on its own (like it happens when interacting with rustc
directly). Use the corresponding configuration options to control
that instead, orthogonally.

Note this level may cause excessive stack usage, which can lead to stack
overflow and subsequent crashes.

config RUST_OPT_LEVEL_1
bool "Basic optimizations (-Copt-level=1)"
help
Useful for debugging without getting too lost, but without
the overhead and boilerplate of no optimizations at all.

Note this level may cause excessive stack usage, which can lead to stack
overflow and subsequent crashes.

config RUST_OPT_LEVEL_2
bool "Some optimizations (-Copt-level=2)"
help
The sensible choice in most cases.

config RUST_OPT_LEVEL_3
bool "All optimizations (-Copt-level=3)"
help
Yet more performance (hopefully).

config RUST_OPT_LEVEL_S
bool "Optimize for size (-Copt-level=s)"
help
Smaller kernel, ideally without too much performance loss.

config RUST_OPT_LEVEL_Z
bool "Optimize for size, no loop vectorization (-Copt-level=z)"
help
Like the previous level, but also turn off loop vectorization.

endchoice

choice
prompt "Build-time assertions"
default RUST_BUILD_ASSERT_ALLOW if RUST_OPT_LEVEL_0
default RUST_BUILD_ASSERT_DENY if !RUST_OPT_LEVEL_0
default RUST_BUILD_ASSERT_DENY
depends on RUST
help
Controls how are `build_error!` and `build_assert!` handled during build.
Expand Down Expand Up @@ -2822,7 +2750,6 @@ config RUST_BUILD_ASSERT_WARN

config RUST_BUILD_ASSERT_DENY
bool "Deny"
depends on !RUST_OPT_LEVEL_0
help
Unoptimized calls to `build_error!` will abort compilation.

Expand Down

0 comments on commit 5f48fa8

Please sign in to comment.