From 0d88e83daa1c7443b9d8966d2afc254584ab695d Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 2 Feb 2014 14:41:57 -0800 Subject: [PATCH] Avoiding function lookup for compiled functions. Still need caching. --- src/alloy/backend/ivm/ivm_intcode.cc | 6 ++++-- src/alloy/backend/x64/lowering/lowering_sequences.cc | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/alloy/backend/ivm/ivm_intcode.cc b/src/alloy/backend/ivm/ivm_intcode.cc index 6aa87ac8e..cae092909 100644 --- a/src/alloy/backend/ivm/ivm_intcode.cc +++ b/src/alloy/backend/ivm/ivm_intcode.cc @@ -576,8 +576,10 @@ int Translate_TRAP_TRUE(TranslationContext& ctx, Instr* i) { uint32_t IntCode_CALL_XX(IntCodeState& ics, const IntCode* i, uint32_t reg) { FunctionInfo* symbol_info = (FunctionInfo*)ics.rf[reg].u64; - Function* fn = NULL; - ics.thread_state->runtime()->ResolveFunction(symbol_info->address(), &fn); + Function* fn = symbol_info->function(); + if (!fn) { + ics.thread_state->runtime()->ResolveFunction(symbol_info->address(), &fn); + } XEASSERTNOTNULL(fn); // TODO(benvanik): proper tail call support, somehow. uint64_t return_address = diff --git a/src/alloy/backend/x64/lowering/lowering_sequences.cc b/src/alloy/backend/x64/lowering/lowering_sequences.cc index 2cc0cfd53..bb59ca222 100644 --- a/src/alloy/backend/x64/lowering/lowering_sequences.cc +++ b/src/alloy/backend/x64/lowering/lowering_sequences.cc @@ -233,11 +233,15 @@ void TransitionToHost(X64Emitter& e) { e.call(e.rax); } void IssueCall(X64Emitter& e, FunctionInfo* symbol_info, uint32_t flags) { - auto fn = symbol_info->function(); + auto fn = (X64Function*)symbol_info->function(); // Resolve address to the function to call and store in rax. // TODO(benvanik): caching/etc. For now this makes debugging easier. - e.mov(e.rdx, (uint64_t)symbol_info); - CallNative(e, ResolveFunctionSymbol); + if (fn) { + e.mov(e.rax, (uint64_t)fn->machine_code()); + } else { + e.mov(e.rdx, (uint64_t)symbol_info); + CallNative(e, ResolveFunctionSymbol); + } // Actually jump/call to rax. if (flags & CALL_TAIL) {