25 #if !defined (octave_jit_typeinfo_h)
26 #define octave_jit_typeinfo_h 1
48 inc (from.inc ()), nelem (from.nelem ())
53 return Range (base, limit, inc);
56 bool all_elements_are_ints ()
const;
67 template <
typename T,
typename U>
80 ref_count = array->jit_ref_count ();
81 slice_data = array->jit_slice_data () - 1;
82 slice_len = array->capacity ();
83 dimensions = array->jit_dimensions ();
138 jit_type (
const std::string& aname,
jit_type *aparent, llvm::Type *allvm_type,
139 bool askip_paren,
int aid);
142 const std::string&
name (
void)
const {
return mname; }
151 llvm::Type *
to_llvm (
void)
const {
return llvm_type; }
154 llvm::Type *to_llvm_arg (
void)
const;
156 size_t depth (
void)
const {
return mdepth; }
169 { msret[cc] =
true; }
177 { mpointer_arg[cc] =
true; }
190 { munpack[cc] = fn; }
194 {
return mpacked_type[cc]; }
197 { mpacked_type[cc] =
ty; }
231 const llvm::Twine& aname,
jit_type *aresult,
232 const std::vector<jit_type *>& aargs);
237 const std::vector<jit_type *>& aargs);
244 template <
typename T>
247 do_add_mapping (engine, reinterpret_cast<void *> (fn));
250 bool valid (
void)
const {
return llvm_function; }
252 std::string name (
void)
const;
254 llvm::BasicBlock *new_block (
const std::string& aname =
"body",
255 llvm::BasicBlock *insert_before = 0);
258 const std::vector<jit_value *>& in_args)
const;
261 const std::vector<llvm::Value *>& in_args
262 = std::vector<llvm::Value *> ())
const;
264 #define JIT_PARAM_ARGS llvm::IRBuilderD& builder,
265 #define JIT_PARAMS builder,
266 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, llvm::Value *, const, N)
276 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, jit_value *, const, N)
284 #undef JIT_PARAM_ARGS
291 llvm::Function *
to_llvm (
void)
const {
return llvm_function; }
294 bool sret (
void)
const {
return mresult && mresult->sret (call_conv); }
296 bool can_error (
void)
const {
return mcan_error; }
298 void mark_can_error (
void) { mcan_error =
true; }
300 jit_type *result (
void)
const {
return mresult; }
304 assert (idx < args.size ());
308 const std::vector<jit_type *>& arguments (
void)
const {
return args; }
310 void do_add_mapping (llvm::ExecutionEngine *engine,
void *fn);
312 llvm::Module *module;
313 llvm::Function *llvm_function;
315 std::vector<jit_type *> args;
340 const signature_vec& args);
342 const jit_function& overload (
const signature_vec& types)
const;
344 jit_type *result (
const signature_vec& types)
const
351 #define JIT_PARAM_ARGS
352 #define JIT_OVERLOAD(N) \
353 JIT_EXPAND (const jit_function&, overload, jit_type *, const, N) \
354 JIT_EXPAND (jit_type *, result, jit_type *, const, N)
361 #undef JIT_PARAM_ARGS
363 const std::string& name (
void)
const {
return mname; }
365 void stash_name (
const std::string& aname) { mname = aname; }
371 const jit_function& do_generate (
const signature_vec& types)
const;
375 bool operator() (
const signature_vec *lhs,
const signature_vec *rhs)
const;
378 typedef std::map<const signature_vec *, jit_function *, signature_cmp>
383 std::vector<Array<jit_function> > overloads;
394 void initialize (llvm::Module *amodule, llvm::ExecutionEngine *aengine)
401 virtual jit_function *generate (
const signature_vec& types)
const;
403 virtual jit_function *generate_matrix (
const signature_vec& types)
const = 0;
405 virtual void do_initialize (
void) = 0;
411 size_t end_idx)
const;
413 llvm::Module *module;
414 llvm::ExecutionEngine *engine;
421 virtual jit_function *generate_matrix (
const signature_vec& types)
const;
423 virtual void do_initialize (
void);
432 jit_function *generate_matrix (
const signature_vec& types)
const;
434 virtual void do_initialize (
void);
445 static void initialize (llvm::Module *m, llvm::ExecutionEngine *e);
449 return instance->do_join (lhs, rhs);
452 static jit_type *get_any (
void) {
return instance->any; }
454 static jit_type *get_matrix (
void) {
return instance->matrix; }
456 static jit_type *get_scalar (
void) {
return instance->scalar; }
458 static llvm::Type *get_scalar_llvm (
void)
461 static jit_type *get_scalar_ptr (
void) {
return instance->scalar_ptr; }
463 static jit_type *get_any_ptr (
void) {
return instance->any_ptr; }
465 static jit_type *get_range (
void) {
return instance->range; }
467 static jit_type *get_string (
void) {
return instance->string; }
469 static jit_type *get_bool (
void) {
return instance->boolean; }
471 static jit_type *get_index (
void) {
return instance->index; }
473 static llvm::Type *get_index_llvm (
void)
474 {
return instance->index->
to_llvm (); }
476 static jit_type *get_complex (
void) {
return instance->complex; }
481 return instance->do_type_of (ov);
486 return instance->do_binary_op (op);
491 return instance->do_unary_op (op);
494 static const jit_operation& grab (
void) {
return instance->grab_fn; }
498 return instance->grab_fn.overload (type);
503 return instance->release_fn;
508 return instance->release_fn.overload (type);
513 return instance->destroy_fn;
518 return instance->print_fn;
523 return instance->for_init_fn;
528 return instance->for_check_fn;
533 return instance->for_index_fn;
538 return instance->make_range_fn;
543 return instance->paren_subsref_fn;
548 return instance->paren_subsasgn_fn;
553 return instance->logically_true_fn;
558 return instance->do_cast (result);
563 return instance->do_cast (to, from);
568 return instance->do_insert_error_check (bld);
573 return instance->do_insert_interrupt_check (bld);
578 return instance->end_fn;
584 return instance->do_end (value, index, count);
589 return instance->create_undef_fn;
592 static llvm::Value *create_complex (llvm::Value *
real, llvm::Value *
imag)
594 return instance->complex_new (real, imag);
597 jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e);
641 assert (static_cast<size_t>(op) < binary_ops.size ());
642 return binary_ops[op];
647 assert (static_cast<size_t> (op) < unary_ops.size ());
648 return unary_ops[op];
655 return null_function;
658 if (
id >= casts.size ())
659 return null_function;
665 return do_cast (to).overload (from);
672 llvm::Type *llvm_type,
bool skip_paren =
false);
677 void add_binary_op (
jit_type *ty,
int op,
int llvm_op);
679 void add_binary_icmp (
jit_type *ty,
int op,
int llvm_op);
681 void add_binary_fcmp (
jit_type *ty,
int op,
int llvm_op);
685 template <
typename T>
686 jit_function create_external (llvm::ExecutionEngine *ee, T fn,
687 const llvm::Twine& name,
jit_type *ret,
688 const std::vector<jit_type *>& args
689 = std::vector<jit_type *> ())
697 #define JIT_PARAM_ARGS llvm::ExecutionEngine *ee, T fn, \
698 const llvm::Twine& name, jit_type *ret,
699 #define JIT_PARAMS ee, fn, name, ret,
700 #define CREATE_FUNCTION(N) JIT_EXPAND(template <typename T> jit_function, \
709 #undef JIT_PARAM_ARGS
711 #undef CREATE_FUNCTION
715 const llvm::Twine& name,
jit_type *ret,
716 const std::vector<jit_type *>& args
717 = std::vector<jit_type *> ());
721 const std::vector<jit_type *>& args
722 = std::vector<jit_type *> ())
727 #define JIT_PARAM_ARGS const llvm::Twine& name, jit_type *ret,
728 #define JIT_PARAMS name, ret,
729 #define CREATE_FUNCTION(N) JIT_EXPAND(jit_function, create_internal, \
737 #undef JIT_PARAM_ARGS
739 #undef CREATE_FUNCTION
747 void add_builtin (
const std::string& name);
749 void register_intrinsic (
const std::string& name,
size_t id,
752 std::vector<jit_type *> args (1, arg0);
753 register_intrinsic (name,
id, result, args);
756 void register_intrinsic (
const std::string& name,
size_t id,
jit_type *result,
757 const std::vector<jit_type *>& args);
759 void register_generic (
const std::string& name,
jit_type *result,
762 std::vector<jit_type *> args (1, arg0);
763 register_generic (name, result, args);
766 void register_generic (
const std::string& name,
jit_type *result,
767 const std::vector<jit_type *>& args);
773 llvm::Function *wrap_complex (llvm::Function *wrap);
779 llvm::Value *result);
781 llvm::Value *complex_real (llvm::Value *cx);
783 llvm::Value *complex_real (llvm::Value *cx, llvm::Value *real);
785 llvm::Value *complex_imag (llvm::Value *cx);
787 llvm::Value *complex_imag (llvm::Value *cx, llvm::Value *imag);
789 llvm::Value *complex_new (llvm::Value *real, llvm::Value *imag);
791 void create_int (
size_t nbits);
797 llvm::Module *module;
798 llvm::ExecutionEngine *engine;
801 llvm::GlobalVariable *lerror_state;
802 llvm::GlobalVariable *loctave_interrupt_state;
804 llvm::Type *sig_atomic_type;
806 std::vector<jit_type*> id_to_type;
818 std::map<size_t, jit_type *> ints;
819 std::map<std::string, jit_type *> builtins;
821 llvm::StructType *complex_ret;
823 std::vector<jit_operation> binary_ops;
824 std::vector<jit_operation> unary_ops;
843 std::vector<jit_operation> casts;
846 std::vector<jit_function> identities;
jit_type * result(void) const
octave_idx_type slice_len
#define CREATE_FUNCTION(N)
const std::string & name(void) const
llvm::Type * to_llvm(void) const
bool sret(jit_convention::type cc) const
llvm::Value * to_llvm(void) const
octave_value do_unary_op(octave_value::unary_op op, const octave_value &v)
jit_range(const Range &from)
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
void set_packed_type(jit_convention::type cc, llvm::Type *ty)
void mark_sret(jit_convention::type cc)
std::vector< jit_type * > signature_vec
convert_fn pack(jit_convention::type cc)
static llvm::IRBuilder builder(llvm::getGlobalContext())
jit_type * parent(void) const
void mark_pointer_arg(jit_convention::type cc)
void add_mapping(llvm::ExecutionEngine *engine, T fn)
bool pointer_arg(jit_convention::type cc) const
std::map< const signature_vec *, jit_function *, signature_cmp > generated_map
octave_idx_type * dimensions
convert_fn unpack(jit_convention::type cc)
void set_pack(jit_convention::type cc, convert_fn fn)
ColumnVector imag(const ComplexColumnVector &a)
std::ostream & jit_print(std::ostream &os, jit_type *atype)
bool skip_paren(void) const
std::ostream & operator<<(std::ostream &os, const jit_range &rng)
ColumnVector real(const ComplexColumnVector &a)
static void initialize(void)
jit_array< NDArray, double > jit_matrix
llvm::Type * packed_type(jit_convention::type cc)
void set_unpack(jit_convention::type cc, convert_fn fn)
const std::vector< jit_type * > & arguments(void) const
static bool scalar(const dim_vector &dims)
octave_value do_binary_op(octave_value::binary_op op, const octave_value &v1, const octave_value &v2)