Skip to content

Commit

Permalink
Enable the equivalent of -O3 for --opt=aggressive
Browse files Browse the repository at this point in the history
When using `inko build --opt=aggressive`, we not set LLVM's optimization
level to "aggressive", which is the equivalent of -O3 for clang. This
gives users to ability to have their code optimized at least somewhat,
provided they're willing to deal with the significant increase in
compile times. For example, Inko's test suite takes about 3 seconds to
compile without optimizations, while taking just under 10 seconds when
using --opt=aggressive.

The option --opt=balanced still doesn't apply optimizations as we've yet
to figure out which ones we want to explicitly opt-in to.

See #595 for more details.

Changelog: performance
  • Loading branch information
yorickpeterse committed Nov 17, 2023
1 parent a386c8b commit 1a30de9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 15 additions & 2 deletions compiler/src/llvm/passes.rs
@@ -1,4 +1,4 @@
use crate::config::BuildDirectories;
use crate::config::{BuildDirectories, Opt};
use crate::llvm::builder::Builder;
use crate::llvm::constants::{
ARRAY_BUF_INDEX, ARRAY_CAPA_INDEX, ARRAY_LENGTH_INDEX,
Expand Down Expand Up @@ -75,7 +75,20 @@ impl<'a, 'b, 'ctx> Compile<'a, 'b, 'ctx> {
// of those may not be relevant to Inko, while slowing down compile
// times. Thus instead of using this knob, we provide our own list of
// passes. Swift and Rust (and possibly others) take a similar approach.
let opt = OptimizationLevel::None;
//
// For the aggressive mode we simply enable the full suite of LLVM
// optimizations, likely greatly increasing the compilation times.
let opt = match state.config.opt {
Opt::None => OptimizationLevel::None,

// We have yet to figure out what optimizations we want to enable
// here, hence we don't apply any at all.
Opt::Balanced => OptimizationLevel::None,

// This is the equivalent of -O3 for clang.
Opt::Aggressive => OptimizationLevel::Aggressive,
};

let reloc = RelocMode::PIC;
let model = CodeModel::Default;
let triple = TargetTriple::create(&state.config.target.llvm_triple());
Expand Down
5 changes: 2 additions & 3 deletions docs/source/getting-started/cli.md
Expand Up @@ -45,9 +45,8 @@ For `--opt none` the executable is placed in `./build/none/hello`, and
`./build/aggressive/hello` for `--opt aggressive`.

!!! tip
Only use `--opt aggressive` if you have determined the increase in compile
times is worth the increase in runtime performance. Most users will want to
avoid this option entirely.
Only use `--opt aggressive` if you have determined a significant increase in
compile times is worth the increase in runtime performance.

You can specify an alternative output path using the `-o` option:

Expand Down

0 comments on commit 1a30de9

Please sign in to comment.