mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
WIP add llvm optimisation passes
This commit is contained in:
parent
67d7f0a933
commit
4c9610b147
3 changed files with 50 additions and 1 deletions
|
@ -3,6 +3,10 @@ use crate::link::{
|
|||
};
|
||||
use bumpalo::Bump;
|
||||
use inkwell::memory_buffer::MemoryBuffer;
|
||||
use inkwell::{
|
||||
passes::PassBuilderOptions,
|
||||
targets::{InitializationConfig, TargetMachine},
|
||||
};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_gen_dev::AssemblyBackendMode;
|
||||
use roc_gen_llvm::llvm::build::{module_from_builtins, LlvmBackendMode};
|
||||
|
@ -259,8 +263,36 @@ fn gen_from_mono_module_llvm<'a>(
|
|||
|
||||
// Uncomment this to see the module's optimized LLVM instruction output:
|
||||
// env.module.print_to_stderr();
|
||||
//
|
||||
inkwell::targets::Target::initialize_all(&InitializationConfig::default());
|
||||
let target_triple = TargetMachine::get_default_triple();
|
||||
let inkwell_target = inkwell::targets::Target::from_triple(&target_triple).unwrap();
|
||||
let inkwell_opt_level = match opt_level {
|
||||
OptLevel::Development | OptLevel::Normal => inkwell::OptimizationLevel::None,
|
||||
OptLevel::Size => inkwell::OptimizationLevel::Default,
|
||||
OptLevel::Optimize => inkwell::OptimizationLevel::Aggressive,
|
||||
};
|
||||
|
||||
mpm.run_on(module);
|
||||
let inkwell_target_machine = inkwell_target
|
||||
.create_target_machine(
|
||||
&target_triple,
|
||||
"generic",
|
||||
"",
|
||||
inkwell_opt_level,
|
||||
inkwell::targets::RelocMode::PIC,
|
||||
inkwell::targets::CodeModel::Default,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
module
|
||||
.run_passes(
|
||||
crate::llvm_passes::get_llvm_passes_str(opt_level),
|
||||
&inkwell_target_machine,
|
||||
PassBuilderOptions::create(),
|
||||
)
|
||||
.expect("valid llvm optimization passes");
|
||||
|
||||
// mpm.run_on(module);
|
||||
|
||||
// Verify the module
|
||||
if let Err(errors) = env.module.verify() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue