Skip to content

Commit

Permalink
Merge pull request #206 from rwy0717/jit-cleanup
Browse files Browse the repository at this point in the history
Clean up function call generation and trampolines
  • Loading branch information
youngar authored Jul 16, 2018
2 parents a456cec + 4d0efae commit 2812d9a
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 192 deletions.
13 changes: 1 addition & 12 deletions b9/include/b9/VirtualMachine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ class VirtualMachine {
std::vector<JitFunction> compiledFunctions_;
};

typedef StackElement (*Interpret)(ExecutionContext *context,
const std::size_t functionIndex);

} // namespace b9

// define C callable Interpret API for each arg call
Expand All @@ -128,16 +125,8 @@ extern "C" {

using namespace b9;

Om::RawValue interpret_0(ExecutionContext *context,
Om::RawValue interpret(ExecutionContext *context,
const std::size_t functionIndex);
Om::RawValue interpret_1(ExecutionContext *context,
const std::size_t functionIndex, Om::RawValue p1);
Om::RawValue interpret_2(ExecutionContext *context,
const std::size_t functionIndex, Om::RawValue p1,
Om::RawValue p2);
Om::RawValue interpret_3(ExecutionContext *context,
const std::size_t functionIndex, Om::RawValue p1,
Om::RawValue p2, Om::RawValue p3);

void primitive_call(ExecutionContext *context, Immediate value);
}
Expand Down
1 change: 1 addition & 0 deletions b9/include/b9/compiler/GlobalTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class GlobalTypes {
public:
GlobalTypes(TR::TypeDictionary &td);

TR::IlType *size;
TR::IlType *addressPtr;
TR::IlType *int64Ptr;
TR::IlType *int32Ptr;
Expand Down
8 changes: 8 additions & 0 deletions b9/include/b9/compiler/MethodBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,16 @@ class MethodBuilder : public TR::MethodBuilder {
void storeParamIndex(TR::IlBuilder *builder, int paramIndex,
TR::IlValue *value);

void interpreterCall(TR::BytecodeBuilder* builder, std::size_t target);

void directCall(TR::BytecodeBuilder *builder, std::size_t target);

void passParamCall(TR::BytecodeBuilder* builder, std::size_t target);

// Bytecode Handlers

void handle_bc_function_call(TR::BytecodeBuilder *builder, TR::BytecodeBuilder *nextBuilder, std::size_t target);

void handle_bc_push_constant(TR::BytecodeBuilder *builder,
TR::BytecodeBuilder *nextBuilder);
void handle_bc_push_string(TR::BytecodeBuilder *builder,
Expand Down
5 changes: 3 additions & 2 deletions b9/src/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace b9 {
GlobalTypes::GlobalTypes(TR::TypeDictionary &td) {
// Core Integer Types

size = td.toIlType<std::size_t>();
addressPtr = td.PointerTo(TR::Address);
int64Ptr = td.PointerTo(TR::Int64);
int32Ptr = td.PointerTo(TR::Int32);
Expand Down Expand Up @@ -67,7 +68,7 @@ JitFunction Compiler::generateCode(const std::size_t functionIndex) {
const FunctionDef *function = virtualMachine_.getFunction(functionIndex);
MethodBuilder methodBuilder(virtualMachine_, functionIndex);

if (cfg_.debug)
if (cfg_.verbose)
std::cout << "MethodBuilder for function: " << function->name
<< " is constructed" << std::endl;

Expand All @@ -80,7 +81,7 @@ JitFunction Compiler::generateCode(const std::size_t functionIndex) {
throw b9::CompilationException{"IL generation failed"};
}

if (cfg_.debug)
if (cfg_.verbose)
std::cout << "Compilation completed with return code: " << rc
<< ", code address: " << static_cast<void *>(result) << std::endl;

Expand Down
17 changes: 13 additions & 4 deletions b9/src/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ void ExecutionContext::reset() {

Om::Value ExecutionContext::callJitFunction(JitFunction jitFunction,
std::size_t nparams) {
if (cfg_->verbose) {
std::cout << "Int: transition to jit: " << jitFunction << std::endl;
}

Om::RawValue result = 0;

if (cfg_->passParam) {
if (cfg_->verbose) {
std::cout << "Int: transition to Jit(PP): " << (void *)jitFunction
<< std::endl;
}
switch (nparams) {
case 0: {
result = jitFunction(this);
Expand All @@ -69,6 +69,10 @@ Om::Value ExecutionContext::callJitFunction(JitFunction jitFunction,
break;
}
} else {
if (cfg_->verbose) {
std::cout << "Int: transition to Jit: " << (void *)jitFunction
<< std::endl;
}
result = jitFunction(this);
}

Expand All @@ -81,6 +85,11 @@ StackElement ExecutionContext::interpret(const std::size_t functionIndex) {
auto localsCount = function->nlocals;
auto jitFunction = virtualMachine_->getJitAddress(functionIndex);

if (cfg_->debug) {
std::cerr << "intepret: " << function->name
<< " nparams: " << function->nparams << std::endl;
}

if (jitFunction) {
return callJitFunction(jitFunction, paramsCount);
}
Expand Down
Loading

0 comments on commit 2812d9a

Please sign in to comment.