Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Base.Experimental.@min_optlevel to set a min-optlevel for a module #57125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NHDaly
Copy link
Member

@NHDaly NHDaly commented Jan 22, 2025

Adds the complement to Experimental.@optlevel, which allows setting a min_optlevel.

    Experimental.@min_optlevel n::Int

Set the minimum optimization level (equivalent to the `--min-optlevel` command line
argument) for code in the current module. Submodules inherit the setting of their
parent module.

Supported values are 0, 1, 2, and 3.

This sets a lower-bound for optimization level, such that the effective optimization
level, `o` is `@min_optlevel <= o <= @optlevel`, overriding the defaults that come
from the command line arguments: `--min-optlevel <= o <= -O`.

NOTE: This min optimization level will only be applied to LLVM functions that are compiled
from this module. If a function defined in this module is *inlined* into a function defined
outside the module, that function will not inherit this min optimization level. Consider
whether you need to introduce `@noinline` if you require users to observe your min optlevel.

This is useful for the case where you have a very optimization-sensitive part of your codebase, but you otherwise want to run with a low optimization level such as -O0 or -O1, either for tests or even in production.

base/experimental.jl Outdated Show resolved Hide resolved
@nickrobinson251
Copy link
Contributor

What happens when @optlevel and @min_optlevel disagree? Is it undefined, or is there a defined answer worth documenting?
e.g. both are used in the same module

module AA
@optlevel 1
@min_optlevel 2
...
end

or in submodules

module AA
@optlevel 1
    module BB
    @min_optlevel 2
    ...
    end
...
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants