Skip to content

Commit

Permalink
aot: Compile separate versions for runtime trampolines
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Jan 4, 2025
1 parent 82cb604 commit f6ad682
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
7 changes: 4 additions & 3 deletions dora-runtime/src/compiler/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dora_bytecode::{
BytecodeTypeArray, ConstPoolEntry, FunctionId, FunctionKind, PackageId,
};

use crate::compiler::codegen::{ensure_runtime_entry_trampoline, CompilerInvocation};
use crate::compiler::codegen::{compile_runtime_entry_trampoline, CompilerInvocation};
use crate::compiler::{compile_fct_aot, trait_object_thunk, NativeFct, NativeFctKind};
use crate::gc::{formatted_size, Address};
use crate::os;
Expand Down Expand Up @@ -472,12 +472,13 @@ fn compile_function(
desc: NativeFctKind::RuntimeEntryTrampoline(fct_id),
};

let fctptr_wrapper = ensure_runtime_entry_trampoline(vm, Some(fct_id), internal_fct);
let code = compile_runtime_entry_trampoline(vm, Some(fct_id), internal_fct);

let existing = ctc
.function_addresses
.insert((fct_id, type_params), fctptr_wrapper);
.insert((fct_id, type_params), code.instruction_start());
assert!(existing.is_none());
ctc.code_objects.push(code);
} else if let Some(_) = fct.bytecode {
let (_code_id, code) = compile_fct_aot(vm, fct_id, &type_params, compiler);
ctc.counter += 1;
Expand Down
37 changes: 23 additions & 14 deletions dora-runtime/src/compiler/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,26 +401,35 @@ pub fn ensure_runtime_entry_trampoline(
if let Some(instruction_start) = native_stubs.find_fct(ptr) {
instruction_start
} else {
let dbg = if let Some(fct_id) = fct_id {
should_emit_debug(vm, fct_id, Compiler::Cannon)
} else {
false
};

let code = runtime_entry_trampoline::generate(vm, native_fct, dbg);

if let Some(fct_id) = fct_id {
if should_emit_asm(vm, fct_id, Compiler::Cannon) {
disassembler::disassemble(vm, fct_id, &BytecodeTypeArray::empty(), &code);
}
}

let code = compile_runtime_entry_trampoline(vm, fct_id, native_fct);
native_stubs.insert_fct(ptr, code.instruction_start());
code.instruction_start()
}
})
}

pub fn compile_runtime_entry_trampoline(
vm: &VM,
fct_id: Option<FunctionId>,
native_fct: NativeFct,
) -> Arc<Code> {
let dbg = if let Some(fct_id) = fct_id {
should_emit_debug(vm, fct_id, Compiler::Cannon)
} else {
false
};

let code = runtime_entry_trampoline::generate(vm, native_fct, dbg);

if let Some(fct_id) = fct_id {
if should_emit_asm(vm, fct_id, Compiler::Cannon) {
disassembler::disassemble(vm, fct_id, &BytecodeTypeArray::empty(), &code);
}
}

code
}

pub struct CompilationData<'a> {
pub bytecode_fct: &'a BytecodeFunction,
pub params: BytecodeTypeArray,
Expand Down

0 comments on commit f6ad682

Please sign in to comment.