Skip to content

Commit

Permalink
Float prims, Inline interface cleanup
Browse files Browse the repository at this point in the history
* Inlining code doesn't manipulate the operand stack, it requires
  the caller of the inliner to properly make user of the inliners
  exported value.
  • Loading branch information
Evan Phoenix committed Aug 19, 2009
1 parent abe8386 commit a44e405
Show file tree
Hide file tree
Showing 16 changed files with 616 additions and 223 deletions.
6 changes: 5 additions & 1 deletion rakelib/jit.rake
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ namespace :jit do
rubinius::InlineCacheHit
rubinius::BlockEnvironment
rubinius::BlockInvocation
rubinius::Numeric
rubinius::Float
jit_state!
require 'tempfile'

files = %w!vm/call_frame.hpp
vm/arguments.hpp
vm/dispatch.hpp
vm/inline_cache.hpp
vm/builtin/block_environment.hpp!
vm/builtin/block_environment.hpp
vm/builtin/integer.hpp
vm/builtin/float.hpp!
path = "llvm-type-temp.cpp"

File.open(path, "w+") do |f|
Expand Down
10 changes: 10 additions & 0 deletions vm/builtin/compiledmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ namespace rubinius {
}
}
}

for(IndirectLiterals::iterator i = vmm->indirect_literals().begin();
i != vmm->indirect_literals().end();
i++) {
Object** ptr = (*i);
if((tmp = mark.call(*ptr)) != NULL) {
*ptr = tmp;
mark.just_set(obj, tmp);
}
}
}

void CompiledMethod::Info::visit(Object* obj, ObjectVisitor& visit) {
Expand Down
3 changes: 2 additions & 1 deletion vm/builtin/compiledmethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "builtin/executable.hpp"
#include "vm.hpp"

#include <list>

namespace rubinius {

class InstructionSequence;
Expand Down Expand Up @@ -38,7 +40,6 @@ namespace rubinius {

VMMethod* backend_method_;


attr_accessor(name, Symbol);
attr_accessor(iseq, InstructionSequence);
attr_accessor(stack_size, Fixnum);
Expand Down
86 changes: 26 additions & 60 deletions vm/llvm/inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ namespace rubinius {
void Inliner::inline_trivial_method(Class* klass, CompiledMethod* cm) {
VMMethod* vmm = cm->backend_method_;

Value* self = ops_.stack_top();
Value* self = recv();

BasicBlock* use_send = ops_.new_block("use_send");
ops_.check_class(self, klass, use_send);
ops_.check_class(self, klass, failure());

Value* val = 0;
/////
Expand Down Expand Up @@ -214,12 +213,9 @@ namespace rubinius {
/////

assert(val);
ops_.stack_set_top(val);

ops_.create_branch(after_);
ops_.set_block(use_send);

after_->moveAfter(use_send);
exception_safe();
set_result(val);
}

void Inliner::inline_ivar_write(Class* klass, AccessVariable* acc) {
Expand All @@ -238,11 +234,10 @@ namespace rubinius {

ops_.state()->add_accessor_inlined();

Value* val = ops_.stack_top();
Value* self = ops_.stack_back(1);
Value* val = arg(0);
Value* self = recv();

BasicBlock* use_send = ops_.new_block("use_send");
ops_.check_reference_class(self, klass->class_id(), use_send);
ops_.check_reference_class(self, klass->class_id(), failure());

// Figure out if we should use the table ivar lookup or
// the slot ivar lookup.
Expand Down Expand Up @@ -271,14 +266,8 @@ namespace rubinius {
ops_.b());
}

ops_.stack_remove(1);
ops_.stack_set_top(val);

ops_.create_branch(after_);
ops_.set_block(use_send);

after_->moveAfter(use_send);

exception_safe();
set_result(val);
}

void Inliner::inline_ivar_access(Class* klass, AccessVariable* acc) {
Expand All @@ -297,10 +286,9 @@ namespace rubinius {

ops_.state()->add_accessor_inlined();

Value* self = ops_.stack_top();
Value* self = recv();

BasicBlock* use_send = ops_.new_block("use_send");
ops_.check_reference_class(self, klass->class_id(), use_send);
ops_.check_reference_class(self, klass->class_id(), failure());

// Figure out if we should use the table ivar lookup or
// the slot ivar lookup.
Expand Down Expand Up @@ -329,22 +317,17 @@ namespace rubinius {
ops_.b());
}

ops_.stack_set_top(ivar);

ops_.create_branch(after_);
ops_.set_block(use_send);

after_->moveAfter(use_send);
exception_safe();
set_result(ivar);
}

void Inliner::inline_generic_method(Class* klass, VMMethod* vmm) {
LLVMWorkHorse work(ops_.state(), vmm);
work.valid_flag = ops_.valid_flag();

Value* self = ops_.stack_back(count_);
Value* self = recv();

BasicBlock* use_send = ops_.new_block("use_send");
ops_.check_class(self, klass, use_send);
ops_.check_class(self, klass, failure());

std::vector<Value*> args;
for(int i = count_ - 1; i >= 0; i--) {
Expand All @@ -366,22 +349,14 @@ namespace rubinius {
assert(work.generate_body(info));

on_return->moveAfter(info.fin_block);
use_send->moveBefore(entry);

ops_.create_branch(entry);

ops_.set_block(on_return);

ops_.b().Insert(cast<Instruction>(info.return_value));
ops_.stack_remove(count_ + 1);
ops_.check_for_exception(info.return_value);
ops_.stack_push(info.return_value);

ops_.create_branch(after_);

ops_.set_block(use_send);

use_send->moveAfter(entry);
set_result(info.return_value);
}

const Type* find_type(size_t type) {
Expand Down Expand Up @@ -427,10 +402,9 @@ namespace rubinius {
}

bool Inliner::inline_ffi(Class* klass, NativeFunction* nf) {
Value* self = ops_.stack_back(count_);
Value* self = recv();

BasicBlock* use_send = ops_.new_block("use_send");
ops_.check_class(self, klass, use_send);
ops_.check_class(self, klass, failure());

///

Expand All @@ -441,8 +415,6 @@ namespace rubinius {
struct_types.push_back(Type::Int32Ty);
struct_types.push_back(Type::Int1Ty);

BasicBlock* failure = ops_.new_block("ffi_type_failure");

for(size_t i = 0; i < nf->arg_count; i++) {
Value* current_arg = arg(i);
Value* call_args[] = { ops_.vm(), current_arg, ops_.valid_flag() };
Expand Down Expand Up @@ -476,7 +448,7 @@ namespace rubinius {
Value* valid = ops_.create_load(ops_.valid_flag());

BasicBlock* cont = ops_.new_block("ffi_continue");
ops_.create_conditional_branch(cont, failure, valid);
ops_.create_conditional_branch(cont, failure(), valid);

ops_.set_block(cont);
break;
Expand All @@ -497,7 +469,7 @@ namespace rubinius {
Value* valid = ops_.create_load(ops_.valid_flag());

BasicBlock* cont = ops_.new_block("ffi_continue");
ops_.create_conditional_branch(cont, failure, valid);
ops_.create_conditional_branch(cont, failure(), valid);

ops_.set_block(cont);
break;
Expand All @@ -518,7 +490,7 @@ namespace rubinius {
Value* valid = ops_.create_load(ops_.valid_flag());

BasicBlock* cont = ops_.new_block("ffi_continue");
ops_.create_conditional_branch(cont, failure, valid);
ops_.create_conditional_branch(cont, failure(), valid);

ops_.set_block(cont);
}
Expand All @@ -539,7 +511,7 @@ namespace rubinius {
Value* valid = ops_.create_load(ops_.valid_flag());

BasicBlock* cont = ops_.new_block("ffi_continue");
ops_.create_conditional_branch(cont, failure, valid);
ops_.create_conditional_branch(cont, failure(), valid);

ops_.set_block(cont);
}
Expand Down Expand Up @@ -571,7 +543,7 @@ namespace rubinius {
Value* valid = ops_.create_load(ops_.valid_flag());

BasicBlock* cont = ops_.new_block("ffi_continue");
ops_.create_conditional_branch(cont, failure, valid);
ops_.create_conditional_branch(cont, failure(), valid);

ops_.set_block(cont);
break;
Expand All @@ -594,7 +566,7 @@ namespace rubinius {
Value* valid = ops_.create_load(ops_.valid_flag());

BasicBlock* cont = ops_.new_block("ffi_continue");
ops_.create_conditional_branch(cont, failure, valid);
ops_.create_conditional_branch(cont, failure(), valid);

ops_.set_block(cont);
break;
Expand Down Expand Up @@ -709,14 +681,8 @@ namespace rubinius {

}

ops_.stack_remove(count_);
ops_.stack_set_top(result);
ops_.create_branch(after_);

ops_.set_block(failure);
ops_.propagate_exception();

ops_.set_block(use_send);
exception_safe();
set_result(result);

return true;
}
Expand Down
30 changes: 25 additions & 5 deletions vm/llvm/inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ namespace rubinius {
JITOperations& ops_;
InlineCache* cache_;
int count_;
BasicBlock* after_;
BasicBlock* failure_;
Value* result_;
bool check_for_exception_;

public:

Inliner(JITOperations& ops, InlineCache* cache, int count, BasicBlock* after)
Inliner(JITOperations& ops, InlineCache* cache, int count, BasicBlock* failure)
: ops_(ops)
, cache_(cache)
, count_(count)
, after_(after)
, failure_(failure)
, result_(0)
, check_for_exception_(true)
{}

Value* recv() {
Expand All @@ -33,8 +37,24 @@ namespace rubinius {
return ops_.stack_back(count_ - (which + 1));
}

BasicBlock* after() {
return after_;
BasicBlock* failure() {
return failure_;
}

Value* result() {
return result_;
}

void set_result(Value* val) {
result_ = val;
}

void exception_safe() {
check_for_exception_ = false;
}

bool check_for_exception() {
return check_for_exception_;
}

bool consider();
Expand Down
Loading

0 comments on commit a44e405

Please sign in to comment.