From 1a30de95ae23c5fa54a04a535b94bd3c74d60a9c Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 17 Nov 2023 17:38:40 +0100 Subject: [PATCH] Enable the equivalent of -O3 for --opt=aggressive 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 https://github.com/inko-lang/inko/issues/595 for more details. Changelog: performance --- compiler/src/llvm/passes.rs | 17 +++++++++++++++-- docs/source/getting-started/cli.md | 5 ++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/src/llvm/passes.rs b/compiler/src/llvm/passes.rs index 91c66915c..4eb368fb4 100644 --- a/compiler/src/llvm/passes.rs +++ b/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, @@ -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()); diff --git a/docs/source/getting-started/cli.md b/docs/source/getting-started/cli.md index 7907ac7d3..f94178044 100644 --- a/docs/source/getting-started/cli.md +++ b/docs/source/getting-started/cli.md @@ -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: