Skip to content

Commit

Permalink
Merge branch 'stw' into codedb-ffi-io
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Mar 23, 2016
2 parents 31d4300 + f51631d commit 13d677b
Show file tree
Hide file tree
Showing 18 changed files with 246 additions and 380 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -39,7 +39,6 @@ notifications:
on_start: always
env:
global:
- RBXOPT=-Xint
- LANG="en_US.UTF-8"
- secure: olbok/GN6rOYvPnHBYWGz7giCoCdLFpT/7WSBHukYO3E0uNeqAUOOgW2BFOwCVWdSEJ/iTvJXZQ4qVZHX+6jRfvILZeGv+D2P93VdD8UFQRoTOfFC7esAo525s9fuKm9ehUGWZxlzGOBHHckky1jn6pEf8mlXAVM5e76dlH0fck=
- secure: aqG9eB/PrzQ7XJQN6YX/00sNVvwSB77saxXQzguL2WFjAXB74h6168Hzq+awHtNX/vfOb6ta7fpWLHrA0D+gmZnvTR29VlP6nd0vs1tkdX1/jWbiBHjamRffp+NWVdKbJKYn5iLOGXcuUMOzY/opLKOdvxKZfkxGMxR2tTNLZUE=
Expand Down
4 changes: 2 additions & 2 deletions library/rubinius/configuration.rb
Expand Up @@ -94,9 +94,9 @@
"The JIT will emit code to be sure JITd methods can be profiled"

s.section "inline" do |i|
i.vm_variable "generic", true, "Have the JIT inline generic methods"
i.vm_variable "generic", false, "Have the JIT inline generic methods"

i.vm_variable "blocks", true,
i.vm_variable "blocks", false,
"Have the JIT try to inline methods and their literal blocks"

i.vm_variable "debug", false,
Expand Down
34 changes: 15 additions & 19 deletions machine/builtin/block_environment.cpp
Expand Up @@ -65,11 +65,6 @@ namespace rubinius {
MachineCode* mcode = env->compiled_code_->machine_code();

if(!mcode) {
OnStack<3> os(state, env, args.recv_location(), args.block_location());
OnStack<3> iv(state, invocation.self, invocation.constant_scope, invocation.module);
memory::VariableRootBuffer vrb(state->vm()->current_root_buffers(),
&args.arguments_location(), args.total());

mcode = env->machine_code(state);

if(!mcode) {
Expand Down Expand Up @@ -414,8 +409,8 @@ namespace rubinius {
if(!mod) mod = env->module();

Object* block = cNil;
if(VariableScope* scope = env->top_scope_) {
if(!scope->nil_p()) block = scope->block();
if(VariableScope* vs = env->top_scope_) {
if(!vs->nil_p()) block = vs->block();
}

scope->initialize(invocation.self, block, mod, mcode->number_of_locals);
Expand All @@ -433,24 +428,25 @@ namespace rubinius {
return NULL;
}

CallFrame* previous_frame = 0;
InterpreterCallFrame* frame = ALLOCA_CALL_FRAME(mcode->stack_size);
CallFrame* previous_frame = NULL;
CallFrame* call_frame = ALLOCA_CALL_FRAME(mcode->stack_size);

frame->prepare(mcode->stack_size);
call_frame->prepare(mcode->stack_size);

frame->constant_scope_ = invocation.constant_scope;
call_frame->constant_scope_ = invocation.constant_scope;

frame->arguments = &args;
frame->dispatch_data = env;
frame->compiled_code = env->compiled_code_;
frame->scope = scope;
frame->top_scope_ = env->top_scope_;
frame->flags = invocation.flags | CallFrame::cMultipleScopes
call_frame->arguments = &args;
call_frame->dispatch_data = env;
call_frame->compiled_code = env->compiled_code_;
call_frame->scope = scope;
call_frame->optional_jit_data = NULL;
call_frame->top_scope_ = env->top_scope_;
call_frame->flags = invocation.flags | CallFrame::cMultipleScopes
| CallFrame::cBlock;

state->vm()->push_call_frame(frame, previous_frame);
state->vm()->push_call_frame(call_frame, previous_frame);

Object* value = 0;
Object* value = NULL;

#ifdef RBX_PROFILER
if(unlikely(state->vm()->tooling())) {
Expand Down
31 changes: 13 additions & 18 deletions machine/call_frame.hpp
Expand Up @@ -208,6 +208,17 @@ namespace rubinius {
return ip_++;
}

/**
* Initialize frame for the given stack size.
*/
void prepare(int stack) {
ip_ = 0;

for(int i = 0; i < stack; i++) {
stk[i] = cNil;
}
}

VariableScope* promote_scope_full(STATE);

VariableScope* promote_scope(STATE) {
Expand All @@ -228,28 +239,12 @@ namespace rubinius {
Object* find_breakpoint(STATE);
};

class InterpreterCallFrame : public CallFrame {
public:
// Methods

/**
* Initialize frame for the given stack size.
*/
void prepare(int stack) {
ip_ = 0;

for(int i = 0; i < stack; i++) {
stk[i] = cNil;
}
}
};

#define THREAD_STACK_SIZE 4194304

#define ALLOCA_CALL_FRAME(stack_size) \
reinterpret_cast<InterpreterCallFrame*>(alloca(sizeof(InterpreterCallFrame) + (sizeof(Object*) * stack_size)))
reinterpret_cast<CallFrame*>(alloca(sizeof(CallFrame) + (sizeof(Object*) * stack_size)))
};

#define MAX_CALL_FRAMES (THREAD_STACK_SIZE / sizeof(InterpreterCallFrame))
#define MAX_CALL_FRAMES (THREAD_STACK_SIZE / sizeof(CallFrame))

#endif
1 change: 0 additions & 1 deletion machine/llvm/inline.cpp
Expand Up @@ -112,7 +112,6 @@ namespace rubinius {
Value* call_args[] = {
ops_.state(),
call_site_const,
ops_.call_frame(),
ops_.out_args()
};

Expand Down
145 changes: 34 additions & 111 deletions machine/llvm/jit_block.cpp
Expand Up @@ -49,19 +49,47 @@ namespace jit {

info_.set_state(state);
info_.set_args(args);
// TODO: CallFrame
// info_.set_previous(prev);
info_.set_entry(block);

alloc_frame("block_body");

check_arity();
// Push the new CallFrame
Signature sig(ctx_, ctx_->VoidTy);
sig << "State"
<< "CallFrame"
<< "StackVariables"
<< "BlockEnvironment"
<< "Arguments"
<< "BlockInvocation";

initialize_frame(machine_code_->stack_size);
Value* call_args[] = {
state,
call_frame,
info_.variables(),
block_env,
args,
block_inv
};

nil_stack(machine_code_->stack_size, constant(cNil, obj_type));
sig.call("rbx_block_frame_initialize", call_args, 6, "", b());

setup_block_scope();
// TODO: de-dup
{
b().SetInsertPoint(info_.return_pad());

Signature sig(ctx_, ctx_->VoidTy);
sig << "State";

Value* call_args[] = {
state
};

sig.call("rbx_pop_call_frame", call_args, 1, "", b());

b().SetInsertPoint(block);
}

check_arity();

import_args();

Expand Down Expand Up @@ -100,111 +128,6 @@ namespace jit {
b().SetInsertPoint(body_);
}

void BlockBuilder::setup_block_scope() {
b().CreateStore(ConstantExpr::getNullValue(llvm::PointerType::getUnqual(vars_type)),
get_field(vars, offset::StackVariables::on_heap));
Value* self = b().CreateLoad(
get_field(block_inv, offset::BlockInvocation::self),
"invocation.self");

b().CreateStore(self, get_field(vars, offset::StackVariables::self));

Value* inv_mod = b().CreateLoad(
get_field(block_inv, offset::BlockInvocation::module),
"invocation.module");

Value* creation_mod = b().CreateLoad(
get_field(block_env, offset::BlockEnvironment::module),
"env.module");

Value* mod = b().CreateSelect(
b().CreateICmpNE(inv_mod, ConstantExpr::getNullValue(inv_mod->getType())),
inv_mod,
creation_mod);

module_ = mod;

b().CreateStore(mod, get_field(vars, offset::StackVariables::module));

Value* blk = b().CreateLoad(get_field(top_scope, offset::VariableScope::block),
"args.block");
b().CreateStore(blk, get_field(vars, offset::StackVariables::block));


// We don't use top_scope here because of nested blocks. Parent MUST be
// the scope the block was created in, not the top scope for depth
// variables to work.
Value* be_scope = b().CreateLoad(
get_field(block_env, offset::BlockEnvironment::scope),
"env.scope");

b().CreateStore(be_scope, get_field(vars, offset::StackVariables::parent));
b().CreateStore(constant(cNil, obj_type), get_field(vars, offset::StackVariables::last_match));

nil_locals();
}

void BlockBuilder::initialize_frame(int stack_size) {
Value* code_gep = get_field(call_frame, offset::CallFrame::compiled_code);

method = b().CreateLoad(get_field(block_env, offset::BlockEnvironment::code),
"env.code");

// previous
b().CreateStore(info_.previous(), get_field(call_frame, offset::CallFrame::previous));

// constant_scope
Value* cs = b().CreateLoad(get_field(block_inv, offset::BlockInvocation::constant_scope),
"invocation.constant_scope");

b().CreateStore(cs, get_field(call_frame, offset::CallFrame::constant_scope));

// arguments
b().CreateStore(info_.args(), get_field(call_frame, offset::CallFrame::arguments));

// msg
b().CreateStore(Constant::getNullValue(ctx_->Int8PtrTy),
get_field(call_frame, offset::CallFrame::dispatch_data));

// compiled_code
b().CreateStore(method, code_gep);

// flags
inv_flags_ = b().CreateLoad(get_field(block_inv, offset::BlockInvocation::flags),
"invocation.flags");

int block_flags = CallFrame::cMultipleScopes |
CallFrame::cBlock |
CallFrame::cJITed;

if(!use_full_scope_) block_flags |= CallFrame::cClosedScope;

Value* flags = b().CreateOr(inv_flags_,
cint(block_flags), "flags");

b().CreateStore(flags, get_field(call_frame, offset::CallFrame::flags));

// ip
b().CreateStore(cint(0),
get_field(call_frame, offset::CallFrame::ip));

// scope
b().CreateStore(vars, get_field(call_frame, offset::CallFrame::scope));

// top_scope
top_scope = b().CreateLoad(
get_field(block_env, offset::BlockEnvironment::top_scope),
"env.top_scope");

b().CreateStore(top_scope, get_field(call_frame, offset::CallFrame::top_scope));

// jit_data
b().CreateStore(
constant(ctx_->runtime_data_holder(), ctx_->Int8PtrTy),
get_field(call_frame, offset::CallFrame::jit_data));

}

void BlockBuilder::check_arity() {
BasicBlock* destruct_check = info_.new_block("destruct_check");
BasicBlock* arg_error = info_.new_block("arg_error");
Expand Down
1 change: 0 additions & 1 deletion machine/llvm/jit_inline_block.cpp
Expand Up @@ -21,7 +21,6 @@ namespace jit {
b().SetInsertPoint(entry);

info_.set_args(args);
info_.set_previous(prev);
info_.set_entry(entry);

BasicBlock* body = BasicBlock::Create(ctx_->llvm_context(), "block_body", info_.function());
Expand Down
1 change: 0 additions & 1 deletion machine/llvm/jit_inline_method.cpp
Expand Up @@ -19,7 +19,6 @@ namespace jit {
b().SetInsertPoint(entry);

info_.set_args(args);
info_.set_previous(prev);
info_.set_entry(entry);

BasicBlock* body = BasicBlock::Create(ctx_->llvm_context(), "method_body", info_.function());
Expand Down

0 comments on commit 13d677b

Please sign in to comment.