Skip to content

Commit

Permalink
Removed most rubinius:bug calls from JIT.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Nov 18, 2014
1 parent 6098b87 commit 2b12035
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 14 deletions.
11 changes: 11 additions & 0 deletions vm/llvm/control_flow.hpp
Expand Up @@ -13,10 +13,12 @@ namespace rubinius {
MachineCode* machine_code_;
uint8_t* seen_;
SectionList work_list_;
bool valid_;

public:
ControlFlowWalker(MachineCode* mcode)
: machine_code_(mcode)
, valid_(true)
{
seen_ = new uint8_t[mcode->total];
memset(seen_, 0, mcode->total);
Expand All @@ -31,6 +33,10 @@ namespace rubinius {
work_list_.push_back(ip);
}

bool valid_p() {
return valid_;
}

template <class EI>
void run(EI& each) {
work_list_.push_back(0);
Expand Down Expand Up @@ -60,6 +66,11 @@ namespace rubinius {
break;
}

if(!iter.valid_p()) {
valid_ = false;
break;
}

if(iter.terminator_p()) break;

if(!iter.next_p()) break;
Expand Down
12 changes: 8 additions & 4 deletions vm/llvm/inline.cpp
Expand Up @@ -637,7 +637,8 @@ namespace rubinius {
BasicBlock* entry = work.setup_inline(recv(), blk, args);

if(!work.generate_body()) {
rubinius::bug("LLVM failed to compile a function");
ctx_->set_failure();
return;
}

// Branch to the inlined method!
Expand Down Expand Up @@ -689,7 +690,8 @@ namespace rubinius {
ops_.constant(cNil, ops_.context()->ptr_type("Module")), args);

if(!work.generate_body()) {
rubinius::bug("LLVM failed to compile a function");
ctx_->set_failure();
return;
}

// Branch to the inlined block!
Expand Down Expand Up @@ -922,7 +924,8 @@ namespace rubinius {
}

default:
rubinius::bug("Unknown FFI type in JIT FFI inliner");
ctx_->set_failure();
return false;
}
}

Expand Down Expand Up @@ -1043,7 +1046,8 @@ namespace rubinius {

default:
result = 0;
rubinius::bug("Invalid FFI type in JIT");
ctx_->set_failure();
return false;
}

exception_safe();
Expand Down
27 changes: 23 additions & 4 deletions vm/llvm/inline_primitive.cpp
Expand Up @@ -25,6 +25,7 @@ namespace rubinius {
CompiledCode* compiled_code;
Class* klass;
ClassData data;
bool valid_;

InlinePrimitive(JITOperations& _ops, Inliner& _i, CompiledCode* _code,
Class* _klass, ClassData _data)
Expand All @@ -33,8 +34,13 @@ namespace rubinius {
, compiled_code(_code)
, klass(_klass)
, data(_data)
, valid_(true)
{}

bool valid_p() {
return valid_;
}

void log(const char* name) {
if(ops.llvm_state()->config().jit_inline_debug) {
std::string klass_name = ops.llvm_state()->symbol_debug_str(klass->module_name());
Expand Down Expand Up @@ -884,7 +890,8 @@ namespace rubinius {
performed = ops.b().CreateICmpSGE(lint, rint, "fixnum.ge");
break;
default:
rubinius::bug("Unknown fixnum operation in JIT");
valid_ = false;
return;
}

Value* le = ops.b().CreateSelect(
Expand Down Expand Up @@ -1076,7 +1083,8 @@ namespace rubinius {
performed = ops.b().CreateFRem(lhs, rhs, "float.mod");
break;
default:
rubinius::bug("Unknown float operation in JIT");
valid_ = false;
return;
}

Signature sig(ops.context(), ops.context()->ptr_type("Float"));
Expand Down Expand Up @@ -1251,7 +1259,8 @@ namespace rubinius {
performed = ops.b().CreateFCmpUGE(lhs, rhs, "float.ge");
break;
default:
rubinius::bug("Unknown float operation in JIT");
valid_ = false;
return;
}

Value* imm_value = ops.b().CreateSelect(performed,
Expand Down Expand Up @@ -1826,6 +1835,11 @@ namespace rubinius {
}
}

if(!ip.valid_p()) {
ctx_->set_failure();
return false;
}

return true;
}

Expand All @@ -1847,7 +1861,12 @@ namespace rubinius {
ip.tuple_swap();
break;
default:
rubinius::bug("Unknown inline intrinsic in JIT");
ctx_->set_failure();
return;
}

if(!ip.valid_p()) {
ctx_->set_failure();
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions vm/llvm/jit_builder.cpp
Expand Up @@ -488,15 +488,26 @@ namespace jit {
JITVisit& v_;
BlockMap& map_;
Builder& builder_;
bool valid_;

public:
Walker(JITVisit& v, BlockMap& map, Builder& builder)
: v_(v)
, map_(map)
, builder_(builder)
, valid_(true)
{}

bool valid_p() {
return valid_;
}

void call(OpcodeIterator& iter) {
if(!iter.valid_p()) {
valid_ = false;
return;
}

builder_.set_current_location(iter.ip());
v_.dispatch(iter.ip());

Expand Down Expand Up @@ -536,7 +547,12 @@ namespace jit {

try {
walker.run<Walker>(cb);
if(!walker.valid_p()) {
ctx_->set_failure();
return false;
}
} catch(JITVisit::Unsupported &e) {
ctx_->set_failure();
return false;
}

Expand Down
1 change: 1 addition & 0 deletions vm/llvm/jit_compiler.cpp
Expand Up @@ -293,6 +293,7 @@ namespace jit {
function_ = info.function();

if(!work.generate_body()) {
ctx_->set_failure();
function_ = NULL;
// This is too noisy to report
// llvm::outs() << "not supported yet.\n";
Expand Down
1 change: 1 addition & 0 deletions vm/llvm/jit_context.cpp
Expand Up @@ -36,6 +36,7 @@ namespace rubinius {
Context::Context(LLVMState* ls)
: ls_(ls)
, root_info_(0)
, success_(true)
, inlined_block_(false)
, inline_depth_(0)
, rds_(new jit::RuntimeDataHolder)
Expand Down
9 changes: 9 additions & 0 deletions vm/llvm/jit_context.hpp
Expand Up @@ -41,6 +41,7 @@ namespace rubinius {
class Context {
LLVMState* ls_;
JITMethodInfo* root_info_;
bool success_;
bool inlined_block_;
int inline_depth_;

Expand Down Expand Up @@ -93,6 +94,14 @@ namespace rubinius {
return ctx_;
}

bool success_p() {
return success_;
}

void set_failure() {
success_ = false;
}

llvm::FunctionPassManager* passes() {
return passes_;
}
Expand Down
8 changes: 6 additions & 2 deletions vm/llvm/jit_visit.hpp
Expand Up @@ -448,7 +448,8 @@ namespace rubinius {
addr = llvm_state()->shared().globals.mirror.object_address();
break;
default:
rubinius::bug("invalid system object");
ctx_->set_failure();
return;
}

Value* l_addr = constant(addr, ObjArrayTy);
Expand Down Expand Up @@ -1770,7 +1771,10 @@ namespace rubinius {
nfo = nfo->creator_info();
}

if(mis.size() == 0) rubinius::bug("no method info in inlined block");
if(mis.size() == 0) {
ctx_->set_failure();
return;
}

call_args.push_back(cint(mis.size()));

Expand Down
9 changes: 8 additions & 1 deletion vm/llvm/opcode_iter.hpp
Expand Up @@ -2,6 +2,8 @@ namespace rubinius {
class OpcodeIterator {
MachineCode* machine_code_;

bool valid_;

opcode ip_;
int width_;

Expand Down Expand Up @@ -34,7 +36,7 @@ namespace rubinius {
#undef HANDLE_INST2

default:
rubinius::bug("Unknown opcode");
valid_ = false;
}
}

Expand All @@ -44,6 +46,7 @@ namespace rubinius {
public:
OpcodeIterator(MachineCode* mcode, int ip=0)
: machine_code_(mcode)
, valid_(true)
, ip_(ip)
, width_(0)
{
Expand All @@ -54,6 +57,10 @@ namespace rubinius {
return machine_code_->opcodes;
}

bool valid_p() {
return valid_;
}

opcode ip() {
return ip_;
}
Expand Down
6 changes: 3 additions & 3 deletions vm/llvm/state.cpp
Expand Up @@ -342,7 +342,7 @@ namespace rubinius {

// We were unable to compile this function, likely
// because it's got something we don't support.
if(!func) {
if(!func || !ctx.success_p()) {
if(config().jit_show_compiling) {
CompiledCode* code = compile_request->method();
llvm::outs() << "[[[ JIT error background compiling "
Expand Down Expand Up @@ -564,8 +564,8 @@ namespace rubinius {

int depth = config().jit_limit_search;

if(!start) rubinius::bug("null start");
if(!call_frame) rubinius::bug("null call_frame");
if(!start) return NULL;
if(!call_frame) return NULL;

// if(!start) {
// start = call_frame->compiled_code;
Expand Down

0 comments on commit 2b12035

Please sign in to comment.