Mercurial > hg > octave-lojdl
changeset 14959:12fd4a62d633
Fix whitespace issues and update documentation
* src/pt-jit.h: Update TODO list and fix whitespace issues.
* src/pt-jit.cc: Fix whitespace issues.
author | Max Brister <max@2bass.com> |
---|---|
date | Tue, 19 Jun 2012 12:27:55 -0500 |
parents | 4b98b3f66e46 |
children | c959136f8c3e |
files | src/pt-jit.cc src/pt-jit.h |
diffstat | 2 files changed, 95 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/src/pt-jit.cc +++ b/src/pt-jit.cc @@ -210,7 +210,7 @@ { try { - gripe_invalid_index (); + gripe_invalid_index (); } catch (const octave_execution_exception&) { @@ -357,7 +357,8 @@ llvm::Type *bool_t = llvm::Type::getInt1Ty (context); llvm::Type *string_t = llvm::Type::getInt8Ty (context); string_t = string_t->getPointerTo (); - llvm::Type *index_t = llvm::Type::getIntNTy (context, sizeof(octave_idx_type) * 8); + llvm::Type *index_t = llvm::Type::getIntNTy (context, + sizeof(octave_idx_type) * 8); llvm::StructType *range_t = llvm::StructType::create (context, "range"); std::vector<llvm::Type *> range_contents (4, scalar_t); @@ -392,15 +393,16 @@ lerror_state = new llvm::GlobalVariable (*module, bool_t, false, llvm::GlobalValue::ExternalLinkage, 0, "error_state"); - engine->addGlobalMapping (lerror_state, reinterpret_cast<void *> (&error_state)); + engine->addGlobalMapping (lerror_state, + reinterpret_cast<void *> (&error_state)); // any with anything is an any op llvm::Function *fn; llvm::Type *binary_op_type = llvm::Type::getIntNTy (context, sizeof (octave_value::binary_op)); llvm::Function *any_binary = create_function ("octave_jit_binary_any_any", - any->to_llvm (), binary_op_type, - any->to_llvm (), any->to_llvm ()); + any_t, binary_op_type, + any_t, any_t); engine->addGlobalMapping (any_binary, reinterpret_cast<void*>(&octave_jit_binary_any_any)); @@ -434,7 +436,6 @@ // grab any fn = create_function ("octave_jit_grab_any", any, any); - engine->addGlobalMapping (fn, reinterpret_cast<void*>(&octave_jit_grab_any)); grab_fn.add_overload (fn, false, any, any); grab_fn.stash_name ("grab"); @@ -443,7 +444,8 @@ llvm::Function *print_matrix = create_function ("octave_jit_print_matrix", void_t, matrix_t->getPointerTo ()); - engine->addGlobalMapping (print_matrix, reinterpret_cast<void*>(&octave_jit_print_matrix)); + engine->addGlobalMapping (print_matrix, + reinterpret_cast<void*>(&octave_jit_print_matrix)); fn = create_function ("octave_jit_grab_matrix", matrix, matrix); llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); @@ -470,13 +472,14 @@ // release any fn = create_function ("octave_jit_release_any", void_t, any_t); - engine->addGlobalMapping (fn, reinterpret_cast<void*>(&octave_jit_release_any)); + engine->addGlobalMapping (fn, + reinterpret_cast<void*>(&octave_jit_release_any)); release_fn.add_overload (fn, false, 0, any); release_fn.stash_name ("release"); // release matrix - llvm::Function *delete_mat = create_function ("octave_jit_delete_matrix", void_t, - matrix_t); + llvm::Function *delete_mat = create_function ("octave_jit_delete_matrix", + void_t, matrix_t); engine->addGlobalMapping (delete_mat, reinterpret_cast<void*> (&octave_jit_delete_matrix)); @@ -539,8 +542,10 @@ body = llvm::BasicBlock::Create (context, "body", fn); builder.SetInsertPoint (body); { - llvm::BasicBlock *warn_block = llvm::BasicBlock::Create (context, "warn", fn); - llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, "normal", fn); + llvm::BasicBlock *warn_block = llvm::BasicBlock::Create (context, "warn", + fn); + llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, + "normal", fn); llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); llvm::Value *check = builder.CreateFCmpUEQ (zero, ++fn->arg_begin ()); @@ -551,7 +556,8 @@ builder.CreateBr (normal_block); builder.SetInsertPoint (normal_block); - llvm::Value *ret = builder.CreateFDiv (fn->arg_begin (), ++fn->arg_begin ()); + llvm::Value *ret = builder.CreateFDiv (fn->arg_begin (), + ++fn->arg_begin ()); builder.CreateRet (ret); jit_function::overload ol (fn, true, scalar, scalar, scalar); @@ -562,7 +568,8 @@ // ldiv is the same as div with the operators reversed llvm::Function *div = fn; - fn = create_function ("octave_jit_ldiv_scalar_scalar", scalar, scalar, scalar); + fn = create_function ("octave_jit_ldiv_scalar_scalar", scalar, scalar, + scalar); body = llvm::BasicBlock::Create (context, "body", fn); builder.SetInsertPoint (body); { @@ -636,18 +643,21 @@ // logically true logically_true_fn.stash_name ("logically_true"); - llvm::Function *gripe_nantl = create_function ("octave_jit_gripe_nan_to_logical_conversion", void_t); + llvm::Function *gripe_nantl + = create_function ("octave_jit_gripe_nan_to_logical_conversion", void_t); engine->addGlobalMapping (gripe_nantl, reinterpret_cast<void *> (&octave_jit_gripe_nan_to_logical_conversion)); - fn = create_function ("octave_jit_logically_true_scalar", boolean, scalar); body = llvm::BasicBlock::Create (context, "body", fn); builder.SetInsertPoint (body); { - llvm::BasicBlock *error_block = llvm::BasicBlock::Create (context, "error", fn); - llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, "normal", fn); - - llvm::Value *check = builder.CreateFCmpUNE (fn->arg_begin (), fn->arg_begin ()); + llvm::BasicBlock *error_block = llvm::BasicBlock::Create (context, "error", + fn); + llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, + "normal", fn); + + llvm::Value *check = builder.CreateFCmpUNE (fn->arg_begin (), + fn->arg_begin ()); builder.CreateCondBr (check, error_block, normal_block); builder.SetInsertPoint (error_block); @@ -673,7 +683,8 @@ // FIXME: May be benificial to implement all in LLVM make_range_fn.stash_name ("make_range"); llvm::Function *compute_nelem - = create_function ("octave_jit_compute_nelem", index, scalar, scalar, scalar); + = create_function ("octave_jit_compute_nelem", index, scalar, scalar, + scalar); engine->addGlobalMapping (compute_nelem, reinterpret_cast<void*> (&octave_jit_compute_nelem)); @@ -701,7 +712,8 @@ make_range_fn.add_overload (fn, false, range, scalar, scalar, scalar); // paren_subsref - llvm::Function *ginvalid_index = create_function ("gipe_invalid_index", void_t); + llvm::Function *ginvalid_index = create_function ("gipe_invalid_index", + void_t); engine->addGlobalMapping (ginvalid_index, reinterpret_cast<void*> (&octave_jit_ginvalid_index)); @@ -721,7 +733,6 @@ ione = one; else ione = llvm::ConstantInt::get (int_t, 1); - llvm::Value *szero = llvm::ConstantFP::get (scalar_t, 0); @@ -1387,7 +1398,7 @@ if (inc->branch_alive (p)) infered = jit_typeinfo::join (infered, argument_type (i)); } - + if (infered != type ()) { stash_type (infered); @@ -1508,9 +1519,8 @@ block->append (create<jit_branch> (final_block)); add_block (final_block); - + for (vmap_t::iterator iter = vmap.begin (); iter != vmap.end (); ++iter) - { jit_variable *var = iter->second; const std::string& name = var->name (); @@ -1556,7 +1566,8 @@ // more interesting for (jit_block::iterator iter = entry_block->begin (); iter != entry_block->end (); ++iter) - if (jit_extract_argument *extract = dynamic_cast<jit_extract_argument *> (*iter)) + if (jit_extract_argument *extract + = dynamic_cast<jit_extract_argument *> (*iter)) arguments.push_back (std::make_pair (extract->name (), true)); convert_llvm to_llvm (*this); @@ -1636,7 +1647,6 @@ result = block->append (create<jit_call> (jit_typeinfo::make_range, base, limit, increment)); - } void @@ -1708,7 +1718,7 @@ jit_call *init_iter = create<jit_call> (jit_typeinfo::for_init, control); block->append (init_iter); block->append (create<jit_assign> (iterator, init_iter)); - + jit_value *check = block->append (create<jit_call> (jit_typeinfo::for_check, control, iterator)); block->append (create<jit_cond_branch> (check, body, tail)); @@ -1718,7 +1728,7 @@ jit_call *idx_rhs = create<jit_call> (jit_typeinfo::for_index, control, iterator); block->append (idx_rhs); do_assign (lhs_name, idx_rhs, false); - + // do loop tree_statement_list *pt_body = cmd.body (); pt_body->accept (*this); @@ -1859,7 +1869,8 @@ { tree_expression *expr = tic->condition (); jit_value *cond = visit (expr); - jit_call *check = create<jit_call> (&jit_typeinfo::logically_true, cond); + jit_call *check = create<jit_call> (&jit_typeinfo::logically_true, + cond); block->append (check); jit_block *next = create<jit_block> (block->name ()); @@ -1867,7 +1878,8 @@ block->append (create<jit_check_error> (check, next, final_block)); block = next; - jit_block *body = create<jit_block> (i == 0 ? "if_body" : "ifelse_body"); + jit_block *body = create<jit_block> (i == 0 ? "if_body" + : "ifelse_body"); add_block (body); jit_instruction *br = create<jit_cond_branch> (check, body, @@ -1923,7 +1935,8 @@ tree_expression *arg0 = arg_list->front (); jit_value *index = visit (arg0); - jit_call *call = create<jit_call> (jit_typeinfo::paren_subsref, object, index); + jit_call *call = create<jit_call> (jit_typeinfo::paren_subsref, object, + index); block->append (call); jit_block *normal = create<jit_block> (block->name ()); @@ -2231,7 +2244,8 @@ jit_block::df_set visited, added_phi; std::list<jit_block *> ssa_worklist; iter->second->use_blocks (visited); - ssa_worklist.insert (ssa_worklist.begin (), visited.begin (), visited.end ()); + ssa_worklist.insert (ssa_worklist.begin (), visited.begin (), + visited.end ()); while (ssa_worklist.size ()) { @@ -2446,7 +2460,8 @@ for (biter = blocks.begin (); biter != blocks.end (); ++biter) { jit_block *jblock = *biter; - llvm::BasicBlock *block = llvm::BasicBlock::Create (context, jblock->name (), + llvm::BasicBlock *block = llvm::BasicBlock::Create (context, + jblock->name (), function); jblock->stash_llvm (block); } @@ -2615,7 +2630,8 @@ { llvm::Value *cond = cb.cond_llvm (); llvm::Value *br; - br = builder.CreateCondBr (cond, cb.successor_llvm (0), cb.successor_llvm (1)); + br = builder.CreateCondBr (cond, cb.successor_llvm (0), + cb.successor_llvm (1)); cb.stash_llvm (br); } @@ -2852,7 +2868,8 @@ std::cout << std::endl; #endif - function = reinterpret_cast<jited_function>(engine->getPointerToFunction (llvm_function)); + void *void_fn = engine->getPointerToFunction (llvm_function); + function = reinterpret_cast<jited_function> (void_fn); } jit_info::~jit_info (void)
--- a/src/pt-jit.h +++ b/src/pt-jit.h @@ -62,16 +62,16 @@ // // // TODO: -// 1. Support error cases -// 2. Support some simple matrix case (and cleanup Octave low level IR) -// 3. Fix memory leaks in JIT -// 4. Cleanup/documentation -// 5. ... +// 1. Support some simple matrix case (and cleanup Octave low level IR) +// 2. Function calls +// 3. Cleanup/documentation +// 4. ... // --------------------------------------------------------- -// we don't want to include llvm headers here, as they require __STDC_LIMIT_MACROS -// and __STDC_CONSTANT_MACROS be defined in the entire compilation unit +// we don't want to include llvm headers here, as they require +// __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS be defined in the entire +// compilation unit namespace llvm { class Value; @@ -152,7 +152,7 @@ } else ilist->use_head = sthis; - + ilist->use_tail = sthis; ++ilist->muse_count; } @@ -172,7 +172,7 @@ else // we are the use_head ilist->use_head = mnext; - + if (mnext) mnext->mprev = mprev; else @@ -203,8 +203,8 @@ jit_range { jit_range (const Range& from) : base (from.base ()), limit (from.limit ()), - inc (from.inc ()), nelem (from.nelem ()) - {} + inc (from.inc ()), nelem (from.nelem ()) + {} operator Range () const { @@ -425,7 +425,8 @@ static jit_type *get_scalar (void) { return instance->scalar; } - static llvm::Type *get_scalar_llvm (void) { return instance->scalar->to_llvm (); } + static llvm::Type *get_scalar_llvm (void) + { return instance->scalar->to_llvm (); } static jit_type *get_range (void) { return instance->range; } @@ -435,7 +436,8 @@ static jit_type *get_index (void) { return instance->index; } - static llvm::Type *get_index_llvm (void) { return instance->index->to_llvm (); } + static llvm::Type *get_index_llvm (void) + { return instance->index->to_llvm (); } static jit_type *type_of (const octave_value& ov) { @@ -550,7 +552,7 @@ } jit_type *do_type_of (const octave_value &ov) const; - + const jit_function& do_binary_op (int op) const { assert (static_cast<size_t>(op) < binary_ops.size ()); @@ -573,10 +575,10 @@ { return do_cast (to).get_overload (from); } - + jit_type *new_type (const std::string& name, jit_type *parent, llvm::Type *llvm_type); - + void add_print (jit_type *ty, void *call); @@ -740,8 +742,8 @@ typedef jit_const<double, jit_typeinfo::get_scalar> jit_const_scalar; typedef jit_const<octave_idx_type, jit_typeinfo::get_index> jit_const_index; -typedef jit_const<std::string, jit_typeinfo::get_string, const std::string&, true> -jit_const_string; +typedef jit_const<std::string, jit_typeinfo::get_string, const std::string&, + true> jit_const_string; typedef jit_const<jit_range, jit_typeinfo::get_range, const jit_range&> jit_const_range; @@ -753,10 +755,10 @@ { public: jit_value (void) : llvm_value (0), ty (0), mlast_use (0), - min_worklist (false) {} + min_worklist (false) {} virtual ~jit_value (void); - + bool in_worklist (void) const { return min_worklist; @@ -892,14 +894,14 @@ } jit_instruction (jit_value *arg0) - : already_infered (1, reinterpret_cast<jit_type *>(0)), marguments (1), + : already_infered (1, reinterpret_cast<jit_type *>(0)), marguments (1), mid (next_id ()), mparent (0) { stash_argument (0, arg0); } jit_instruction (jit_value *arg0, jit_value *arg1) - : already_infered (2, reinterpret_cast<jit_type *>(0)), marguments (2), + : already_infered (2, reinterpret_cast<jit_type *>(0)), marguments (2), mid (next_id ()), mparent (0) { stash_argument (0, arg0); @@ -907,7 +909,7 @@ } jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2) - : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (3), + : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (3), mid (next_id ()), mparent (0) { stash_argument (0, arg0); @@ -917,7 +919,7 @@ jit_instruction (jit_value *arg0, jit_value *arg1, jit_value *arg2, jit_value *arg3) - : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (4), + : already_infered (3, reinterpret_cast<jit_type *>(0)), marguments (4), mid (next_id ()), mparent (0) { stash_argument (0, arg0); @@ -956,7 +958,7 @@ std::ostream& print_argument (std::ostream& os, size_t i) const { if (argument (i)) - return argument (i)->short_print (os); + return argument (i)->short_print (os); else return os << "NULL"; } @@ -1100,7 +1102,8 @@ class jit_phi_incomming; class -jit_block : public jit_value, public jit_internal_list<jit_block, jit_phi_incomming> +jit_block : public jit_value, public jit_internal_list<jit_block, + jit_phi_incomming> { typedef jit_internal_list<jit_block, jit_phi_incomming> ILIST_T; public: @@ -1111,8 +1114,8 @@ typedef std::set<jit_block *> df_set; typedef df_set::const_iterator df_iterator; - jit_block (const std::string& aname) : mvisit_count (0), mid (NO_ID), idom (0), - mname (aname), malive (false) + jit_block (const std::string& aname) : mvisit_count (0), mid (NO_ID), + idom (0), mname (aname), malive (false) {} virtual void replace_with (jit_value *value); @@ -1305,7 +1308,8 @@ jit_block *idom_intersect (jit_block *b); template <typename func_type0, typename func_type1> - void do_visit_dom (size_t visit_count, func_type0 inorder, func_type1 postorder); + void do_visit_dom (size_t visit_count, func_type0 inorder, + func_type1 postorder); static const size_t NO_ID = static_cast<size_t> (-1); size_t mvisit_count; @@ -1371,7 +1375,8 @@ template <typename func_type0, typename func_type1> void -jit_block::do_visit_dom (size_t visit_count, func_type0 inorder, func_type1 postorder) +jit_block::do_visit_dom (size_t visit_count, func_type0 inorder, + func_type1 postorder) { if (mvisit_count > visit_count) return; @@ -1717,7 +1722,8 @@ {} jit_call (const jit_function& (*afunction) (void), - jit_value *arg0) : jit_instruction (arg0), mfunction (afunction ()) {} + jit_value *arg0) : jit_instruction (arg0), + mfunction (afunction ()) {} jit_call (const jit_function& afunction, jit_value *arg0, jit_value *arg1) : jit_instruction (arg0, arg1), @@ -1734,7 +1740,7 @@ jit_call (const jit_function& (*afunction) (void), jit_value *arg0, jit_value *arg1, jit_value *arg2, jit_value *arg3) : jit_instruction (arg0, arg1, arg2, arg3), mfunction (afunction ()) {} - + const jit_function& function (void) const { return mfunction; } @@ -2095,7 +2101,7 @@ jit_variable *get_variable (const std::string& vname); jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print); - + jit_value *visit (tree *tee) { return visit (*tee); } @@ -2105,8 +2111,8 @@ { if (! instr->in_worklist ()) { - instr->stash_in_worklist (true); - worklist.push_back (instr); + instr->stash_in_worklist (true); + worklist.push_back (instr); } }