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 ();
86 void update (T *aarray)
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>
245 void add_mapping (llvm::ExecutionEngine *engine, T fn)
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); }
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);
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; }
367 virtual jit_function *generate (
const signature_vec& types)
const;
371 const jit_function& do_generate (
const signature_vec& types)
const;
375 bool operator() (
const signature_vec *lhs,
const signature_vec *rhs);
378 typedef std::map<const signature_vec *, jit_function *, signature_cmp>
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;
423 virtual void do_initialize (
void);
434 virtual void do_initialize (
void);
445 static void initialize (llvm::Module *m, llvm::ExecutionEngine *e);
449 return instance->do_join (lhs, rhs);
458 static llvm::Type *get_scalar_llvm (
void)
459 {
return instance->scalar->
to_llvm (); }
473 static llvm::Type *get_index_llvm (
void)
474 {
return instance->index->
to_llvm (); }
481 return instance->do_type_of (ov);
486 return instance->do_binary_op (op);
491 return instance->do_unary_op (op);
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>
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);
793 jit_type *intN (
size_t nbits)
const;
818 std::map<size_t, jit_type *>
ints;