WIP fix LLVM compiling

This commit is contained in:
Luke Boswell 2024-07-26 16:09:56 +10:00
parent a8dd6244e9
commit 2ba17a71a4
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
3 changed files with 41 additions and 31 deletions

View file

@ -44,7 +44,7 @@ pub fn call_bitcode_fn<'ctx>(
if ret.get_type() == vec_type.into() {
return env
.builder
.build_bitcast(ret, env.context.i128_type(), "return_i128")
.build_bit_cast(ret, env.context.i128_type(), "return_i128")
.unwrap();
}
}

View file

@ -23,7 +23,7 @@ use inkwell::debug_info::{
};
use inkwell::memory_buffer::MemoryBuffer;
use inkwell::module::{Linkage, Module};
use inkwell::passes::{PassManager, PassManagerBuilder};
use inkwell::passes::PassManager;
use inkwell::types::{
AnyType, BasicMetadataTypeEnum, BasicType, BasicTypeEnum, FloatMathType, FunctionType,
IntMathType, IntType, PointerMathType, StructType,
@ -370,7 +370,7 @@ impl<'ctx> BuilderExt<'ctx> for Builder<'ctx> {
T: BasicType<'ctx>,
V: BasicValue<'ctx>,
{
self.build_bitcast(val, ty, name).unwrap()
self.build_bit_cast(val, ty, name).unwrap()
}
fn new_build_pointer_cast<T: PointerMathValue<'ctx>>(
@ -1083,7 +1083,7 @@ pub fn module_from_builtins<'ctx>(
// Note, running DCE here is faster then waiting until full app DCE.
let mpm = PassManager::create(());
mpm.add_global_dce_pass();
// mpm.add_global_dce_pass();
mpm.run_on(&module);
// Now that the unused compiler-rt functions have been removed,
@ -1109,32 +1109,32 @@ pub fn construct_optimization_passes<'a>(
let fpm = PassManager::create(module);
// remove unused global values (e.g. those defined by zig, but unused in user code)
mpm.add_global_dce_pass();
// mpm.add_global_dce_pass();
mpm.add_always_inliner_pass();
// mpm.add_always_inliner_pass();
// tail-call elimination is always on
fpm.add_instruction_combining_pass();
fpm.add_tail_call_elimination_pass();
// fpm.add_instruction_combining_pass();
// fpm.add_tail_call_elimination_pass();
let pmb = PassManagerBuilder::create();
// let pmb = PassManagerBuilder::create();
match opt_level {
OptLevel::Development | OptLevel::Normal => {
pmb.set_optimization_level(OptimizationLevel::None);
// pmb.set_optimization_level(OptimizationLevel::None);
}
OptLevel::Size => {
pmb.set_optimization_level(OptimizationLevel::Default);
// pmb.set_optimization_level(OptimizationLevel::Default);
// 2 is equivalent to `-Oz`.
pmb.set_size_level(2);
// pmb.set_size_level(2);
// TODO: For some usecase, like embedded, it is useful to expose this and tune it.
// This really depends on if inlining causes enough simplifications to reduce code size.
pmb.set_inliner_with_threshold(50);
// pmb.set_inliner_with_threshold(50);
}
OptLevel::Optimize => {
pmb.set_optimization_level(OptimizationLevel::Aggressive);
// pmb.set_optimization_level(OptimizationLevel::Aggressive);
// this threshold seems to do what we want
pmb.set_inliner_with_threshold(750);
// pmb.set_inliner_with_threshold(750);
}
}
@ -1145,15 +1145,15 @@ pub fn construct_optimization_passes<'a>(
// function passes
fpm.add_cfg_simplification_pass();
mpm.add_cfg_simplification_pass();
// fpm.add_cfg_simplification_pass();
// mpm.add_cfg_simplification_pass();
fpm.add_jump_threading_pass();
mpm.add_jump_threading_pass();
// fpm.add_jump_threading_pass();
// mpm.add_jump_threading_pass();
fpm.add_memcpy_optimize_pass(); // this one is very important
// fpm.add_memcpy_optimize_pass(); // this one is very important
fpm.add_licm_pass();
// fpm.add_licm_pass();
// turn invoke into call
// TODO: is this pass needed. It theoretically prunes unused exception handling info.
@ -1161,13 +1161,13 @@ pub fn construct_optimization_passes<'a>(
// mpm.add_prune_eh_pass();
// remove unused global values (often the `_wrapper` can be removed)
mpm.add_global_dce_pass();
// mpm.add_global_dce_pass();
mpm.add_function_inlining_pass();
// mpm.add_function_inlining_pass();
}
pmb.populate_module_pass_manager(&mpm);
pmb.populate_function_pass_manager(&fpm);
// pmb.populate_module_pass_manager(&mpm);
// pmb.populate_function_pass_manager(&fpm);
fpm.initialize();

View file

@ -12,12 +12,22 @@ pub fn opaque_ptr_type<'ctx>(env: &Env<'_, 'ctx, '_>) -> PointerType<'ctx> {
}
fn refcounter_type<'ctx>(env: &Env<'_, 'ctx, '_>) -> PointerType<'ctx> {
let return_void = env.context.void_type();
let arg_ty = opaque_ptr_type(env);
// let return_void = env.context.void_type();
// let arg_ty = opaque_ptr_type(env);
return_void
.fn_type(&[arg_ty.into()], false)
.ptr_type(AddressSpace::default())
// return_void
// .fn_type(&[arg_ty.into()], false)
// .ptr_type(AddressSpace::default())
// TODO -- is it this simple?
//
// This was the error message
// ```
// warning: use of deprecated method `inkwell::types::FunctionType::<'ctx>::ptr_type`:
// Starting from version 15.0, LLVM doesn't differentiate between pointer types.
// Use Context::ptr_type instead.
// ```
env.context.ptr_type(AddressSpace::default())
}
/// Erased is laid out like
@ -52,7 +62,7 @@ fn bitcast_to_opaque_ptr<'ctx>(
env.builder
.new_build_bitcast(
value,
env.context.i8_type().ptr_type(AddressSpace::default()),
env.context.ptr_type(AddressSpace::default()),
"to_opaque_ptr",
)
.into_pointer_value()