Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Feb 16, 2024
1 parent 4dabaf0 commit ebfb0ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions lib/edlang_codegen_llvm/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -94,6 +95,7 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result<PathBuf, Box<
)
.unwrap();
machine.set_asm_verbosity(true);

info!("compiling for: {:?}", target.get_description());

let filename = session.file_path.file_name().unwrap().to_string_lossy();
Expand Down Expand Up @@ -142,6 +144,18 @@ pub fn compile(session: &Session, program: &ProgramBody) -> Result<PathBuf, Box<
module_ctx.di_builder.finalize();
module_ctx.module.verify()?;

let opt = match session.optlevel {
edlang_session::OptLevel::None => "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<O{}>", opt), &machine, passopt)?;

if session.output_llvm {
module_ctx
.module
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion programs/factorial.ed
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ebfb0ef

Please sign in to comment.