mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Add explicit OptLevel to add_passes
This commit is contained in:
parent
b19386c1f6
commit
ea713023e8
2 changed files with 48 additions and 24 deletions
|
@ -31,6 +31,11 @@ const PRINT_FN_VERIFICATION_OUTPUT: bool = false;
|
||||||
// TODO: experiment with different internal calling conventions, e.g. "fast"
|
// TODO: experiment with different internal calling conventions, e.g. "fast"
|
||||||
const DEFAULT_CALLING_CONVENTION: u32 = 0;
|
const DEFAULT_CALLING_CONVENTION: u32 = 0;
|
||||||
|
|
||||||
|
pub enum OptLevel {
|
||||||
|
Normal,
|
||||||
|
Optimize,
|
||||||
|
}
|
||||||
|
|
||||||
type Scope<'a, 'ctx> = ImMap<Symbol, (Layout<'a>, PointerValue<'ctx>)>;
|
type Scope<'a, 'ctx> = ImMap<Symbol, (Layout<'a>, PointerValue<'ctx>)>;
|
||||||
|
|
||||||
pub struct Env<'a, 'ctx, 'env> {
|
pub struct Env<'a, 'ctx, 'env> {
|
||||||
|
@ -56,7 +61,7 @@ pub fn module_from_builtins<'ctx>(ctx: &'ctx Context, module_name: &str) -> Modu
|
||||||
.unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {:?}", err))
|
.unwrap_or_else(|err| panic!("Unable to import builtins bitcode. LLVM error: {:?}", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_passes(fpm: &PassManager<FunctionValue<'_>>) {
|
pub fn add_passes(fpm: &PassManager<FunctionValue<'_>>, opt_level: OptLevel) {
|
||||||
// tail-call elimination is always on
|
// tail-call elimination is always on
|
||||||
fpm.add_instruction_combining_pass();
|
fpm.add_instruction_combining_pass();
|
||||||
fpm.add_tail_call_elimination_pass();
|
fpm.add_tail_call_elimination_pass();
|
||||||
|
@ -64,9 +69,11 @@ pub fn add_passes(fpm: &PassManager<FunctionValue<'_>>) {
|
||||||
let pmb = PassManagerBuilder::create();
|
let pmb = PassManagerBuilder::create();
|
||||||
|
|
||||||
// Enable more optimizations when running cargo test --release
|
// Enable more optimizations when running cargo test --release
|
||||||
if cfg!(debug_assertions) {
|
match opt_level {
|
||||||
|
OptLevel::Normal => {
|
||||||
pmb.set_optimization_level(OptimizationLevel::None);
|
pmb.set_optimization_level(OptimizationLevel::None);
|
||||||
} else {
|
}
|
||||||
|
OptLevel::Optimize => {
|
||||||
// Default is O2, Aggressive is O3
|
// Default is O2, Aggressive is O3
|
||||||
//
|
//
|
||||||
// See https://llvm.org/doxygen/CodeGen_8h_source.html
|
// See https://llvm.org/doxygen/CodeGen_8h_source.html
|
||||||
|
@ -86,6 +93,8 @@ pub fn add_passes(fpm: &PassManager<FunctionValue<'_>>) {
|
||||||
// fpm.add_function_inlining_pass();
|
// fpm.add_function_inlining_pass();
|
||||||
// pmb.set_inliner_with_threshold(4);
|
// pmb.set_inliner_with_threshold(4);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pmb.populate_function_pass_manager(&fpm);
|
pmb.populate_function_pass_manager(&fpm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,14 @@ macro_rules! assert_llvm_evals_to {
|
||||||
let context = Context::create();
|
let context = Context::create();
|
||||||
let module = roc_gen::llvm::build::module_from_builtins(&context, "app");
|
let module = roc_gen::llvm::build::module_from_builtins(&context, "app");
|
||||||
let builder = context.create_builder();
|
let builder = context.create_builder();
|
||||||
let fpm = inkwell::passes::PassManager::create(&module);
|
let opt_level = if(cfg!(debug_assertions)) {
|
||||||
|
roc_gen::llvm::build::OptLevel::Normal
|
||||||
|
} else {
|
||||||
|
roc_gen::llvm::build::OptLevel::Optimize
|
||||||
|
};
|
||||||
|
let fpm = PassManager::create(&module);
|
||||||
|
|
||||||
roc_gen::llvm::build::add_passes(&fpm);
|
roc_gen::llvm::build::add_passes(&fpm, opt_level);
|
||||||
|
|
||||||
fpm.initialize();
|
fpm.initialize();
|
||||||
|
|
||||||
|
@ -147,9 +152,14 @@ macro_rules! assert_opt_evals_to {
|
||||||
let context = Context::create();
|
let context = Context::create();
|
||||||
let module = roc_gen::llvm::build::module_from_builtins(&context, "app");
|
let module = roc_gen::llvm::build::module_from_builtins(&context, "app");
|
||||||
let builder = context.create_builder();
|
let builder = context.create_builder();
|
||||||
|
let opt_level = if(cfg!(debug_assertions)) {
|
||||||
|
roc_gen::llvm::build::OptLevel::Normal
|
||||||
|
} else {
|
||||||
|
roc_gen::llvm::build::OptLevel::Optimize
|
||||||
|
};
|
||||||
let fpm = PassManager::create(&module);
|
let fpm = PassManager::create(&module);
|
||||||
|
|
||||||
roc_gen::llvm::build::add_passes(&fpm);
|
roc_gen::llvm::build::add_passes(&fpm, opt_level);
|
||||||
|
|
||||||
fpm.initialize();
|
fpm.initialize();
|
||||||
|
|
||||||
|
@ -278,9 +288,14 @@ macro_rules! emit_expr {
|
||||||
let context = Context::create();
|
let context = Context::create();
|
||||||
let module = context.create_module("app");
|
let module = context.create_module("app");
|
||||||
let builder = context.create_builder();
|
let builder = context.create_builder();
|
||||||
|
let opt_level = if(cfg!(debug_assertions)) {
|
||||||
|
roc_gen::llvm::build::OptLevel::Normal
|
||||||
|
} else {
|
||||||
|
roc_gen::llvm::build::OptLevel::Optimize
|
||||||
|
};
|
||||||
let fpm = PassManager::create(&module);
|
let fpm = PassManager::create(&module);
|
||||||
|
|
||||||
roc_gen::llvm::build::add_passes(&fpm);
|
roc_gen::llvm::build::add_passes(&fpm, opt_level);
|
||||||
|
|
||||||
fpm.initialize();
|
fpm.initialize();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue