From ebfb0ef34c3a8b8c7823aee38b18456c0cba5271 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Fri, 16 Feb 2024 12:49:12 +0100 Subject: [PATCH] optimize --- lib/edlang_codegen_llvm/src/codegen.rs | 22 +++++++++++++++++----- programs/factorial.ed | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/edlang_codegen_llvm/src/codegen.rs b/lib/edlang_codegen_llvm/src/codegen.rs index 0f90fa172..c01dedf88 100644 --- a/lib/edlang_codegen_llvm/src/codegen.rs +++ b/lib/edlang_codegen_llvm/src/codegen.rs @@ -11,6 +11,7 @@ use inkwell::{ AsDIScope, DICompileUnit, DIFlagsConstants, DILocation, DIScope, DIType, DebugInfoBuilder, }, module::Module, + passes::PassBuilderOptions, targets::{InitializationConfig, Target, TargetData, TargetMachine}, types::{AnyType, BasicMetadataTypeEnum, BasicType}, values::{BasicValue, BasicValueEnum, PointerValue}, @@ -94,6 +95,7 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result Result "0", + edlang_session::OptLevel::Less => "1", + edlang_session::OptLevel::Default => "2", + edlang_session::OptLevel::Aggressive => "3", + }; + + let passopt = PassBuilderOptions::create(); + module_ctx + .module + .run_passes(&format!("default", opt), &machine, passopt)?; + if session.output_llvm { module_ctx .module @@ -233,6 +247,7 @@ fn compile_fn_signature(ctx: &ModuleCompileCtx<'_, '_>, fn_id: DefId) { preallocated sret align 0 allockind(\"\") allocsize(0,0) dereferenceable(0) dereferenceable_or_null(0 */ + /* // nounwind fn_value.add_attribute( inkwell::attributes::AttributeLoc::Function, @@ -250,12 +265,9 @@ fn compile_fn_signature(ctx: &ModuleCompileCtx<'_, '_>, fn_id: DefId) { inkwell::attributes::AttributeLoc::Function, ctx.ctx.context.create_enum_attribute(66, 0), ); + */ - if body.name == "main" { - fn_value.set_call_conventions(0); - } else { - fn_value.set_call_conventions(1); - } + fn_value.set_call_conventions(0); let (_, line, _col) = ctx .ctx diff --git a/programs/factorial.ed b/programs/factorial.ed index 7123369fb..be4a0bf37 100644 --- a/programs/factorial.ed +++ b/programs/factorial.ed @@ -4,7 +4,7 @@ mod Main { return b; } - fn factorial(n: i32) -> i32 { + pub fn factorial(n: i32) -> i32 { if n == 1 { return n; } else {