26 #if ! defined (octave_jit_typeinfo_h)
27 #define octave_jit_typeinfo_h 1
29 #include "octave-config.h"
31 #if defined (HAVE_LLVM)
56 : m_base (from.base ()), m_limit (from.limit ()), m_inc (from.inc ()),
57 m_nelem (from.
numel ())
62 return Range (m_base, m_limit, m_inc);
65 bool all_elements_are_ints (
void)
const;
76 template <
typename T,
typename U>
89 m_ref_count = m_array->jit_ref_count ();
90 m_slice_data = m_array->jit_slice_data () - 1;
91 m_slice_len = m_array->numel ();
92 m_dimensions = m_array->jit_dimensions ();
120 namespace jit_convention
147 jit_type (
const std::string& aname,
jit_type *aparent, llvm::Type *allvm_type,
148 bool askip_paren,
int aid);
151 const std::string&
name (
void)
const {
return m_name; }
160 llvm::Type *
to_llvm (
void)
const {
return m_llvm_type; }
163 llvm::Type * to_llvm_arg (
void)
const;
165 size_t depth (
void)
const {
return m_depth; }
178 { m_sret[cc] =
true; }
186 { m_pointer_arg[cc] =
true; }
199 { m_unpack[cc] = fn; }
203 {
return m_packed_type[cc]; }
206 { m_packed_type[cc] = ty; }
249 const llvm::Twine& aname,
jit_type *aresult,
250 const std::vector<jit_type *>& aargs);
255 const std::vector<jit_type *>& aargs);
262 bool valid (
void)
const {
return m_llvm_function; }
264 std::string
name (
void)
const;
266 llvm::BasicBlock * new_block (
const std::string& aname =
"body",
267 llvm::BasicBlock *insert_before =
nullptr);
275 const std::vector<jit_value *>& in_args)
const;
277 template <
typename ...Args>
279 llvm::Value * arg1, Args... other_args)
const
281 in_args.push_back (arg1);
282 return call (
builder, in_args, other_args...);
285 template <
typename T,
typename ...Args>
287 T * arg1, Args... other_args)
const
289 in_args.push_back (arg1->to_llvm ());
290 return call (
builder, in_args, other_args...);
293 template <
typename ...Args>
295 Args... other_args)
const
298 in_args.reserve (1 +
sizeof... (other_args));
299 in_args.push_back (arg1);
300 return call (
builder, in_args, other_args...);
303 template <
typename T,
typename ...Args>
305 Args... other_args)
const
308 in_args.reserve (1 +
sizeof... (other_args));
309 in_args.push_back (arg1->to_llvm ());
310 return call (
builder, in_args, other_args...);
318 llvm::Function *
to_llvm (
void)
const {
return m_llvm_function; }
321 bool sret (
void)
const {
return m_result && m_result->sret (m_call_conv); }
331 assert (idx < m_args.size ());
335 const std::vector<jit_type *>&
arguments (
void)
const {
return m_args; }
373 template <
typename ...Args>
375 Args... other_args)
const
377 args.push_back (arg1);
378 return overload (args, other_args...);
381 template <
typename ...Args>
385 args.reserve (1 +
sizeof... (other_args));
386 args.push_back (arg1);
387 return overload (args, other_args...);
396 template <
typename ...Args>
398 Args... other_args)
const
400 args.push_back (arg1);
401 return overload (args, other_args...);
404 template <
typename ...Args>
408 args.reserve (1 +
sizeof... (other_args));
409 args.push_back (arg1);
410 return overload (args, other_args...);
413 const std::string&
name (
void)
const {
return m_name; }
415 void stash_name (
const std::string& aname) { m_name = aname; }
419 virtual jit_function * generate (
const signature_vec& types)
const;
425 const jit_function& do_generate (
const signature_vec& types)
const;
432 typedef std::map<const signature_vec *, jit_function *, signature_cmp>
453 virtual jit_function * generate (
const signature_vec& types)
const;
461 size_t end_idx)
const;
474 void init_paren_scalar (
void);
493 void init_paren_scalar (
void);
526 llvm::Type *llvm_type,
bool skip_paren =
false)
538 llvm::Type *llvm_type,
bool skip_paren =
false);
606 jit_type *do_get_intN (
size_t nbits)
const;
705 return instance ().
do_cast (result);
710 return instance ().
do_cast (to, from);
731 return instance ().
do_end (value, idx, count);
750 llvm::Value *result);
758 assert (
static_cast<size_t> (op) < m_binary_ops.size ());
759 return m_binary_ops[op];
764 assert (
static_cast<size_t> (op) < m_unary_ops.size ());
765 return m_unary_ops[op];
772 return null_function;
775 if (
id >= m_casts.size ())
776 return null_function;
782 return do_cast (to).overload (from);
790 void add_binary_op (
jit_type *ty,
int op,
int llvm_op);
792 void add_binary_icmp (
jit_type *ty,
int op,
int llvm_op);
794 void add_binary_fcmp (
jit_type *ty,
int op,
int llvm_op);
801 template <
typename T>
806 template <
typename T,
typename ...Args>
809 jit_type * arg1, Args... other_args)
const
811 args.push_back (arg1);
812 return create_external (fn,
name, ret, args, other_args...);
815 template <
typename T,
typename ...Args>
817 jit_type * arg1, Args... other_args)
const
820 args.reserve (1 +
sizeof... (other_args));
821 args.push_back (arg1);
822 return create_external (fn,
name, ret, args, other_args...);
834 template <
typename ...Args>
837 jit_type * arg1, Args... other_args)
const
839 args.push_back (arg1);
840 return create_internal (
name, ret, args, other_args...);
843 template <
typename ...Args>
845 jit_type * arg1, Args... other_args)
const
848 args.reserve (1 +
sizeof... (other_args));
849 args.push_back (arg1);
850 return create_internal (
name, ret, args, other_args...);
859 void add_builtin (
const std::string&
name);
864 std::vector<jit_type *> args (1, arg0);
865 register_intrinsic (
name,
id, result, args);
868 void register_intrinsic (
const std::string&
name,
size_t id,
jit_type *result,
869 const std::vector<jit_type *>& args);
874 std::vector<jit_type *> args (1, arg0);
875 register_generic (
name, result, args);
878 void register_generic (
const std::string&
name,
jit_type *result,
879 const std::vector<jit_type *>& args);
887 llvm::Value * complex_real (llvm::Value *cx);
889 llvm::Value * complex_real (llvm::Value *cx, llvm::Value *
real);
891 llvm::Value * complex_imag (llvm::Value *cx);
893 llvm::Value * complex_imag (llvm::Value *cx, llvm::Value *
imag);
895 llvm::Value * complex_new (llvm::Value *
real, llvm::Value *
imag);
897 llvm::Value *do_pack_complex (
llvm::IRBuilderD& bld, llvm::Value *cplx)
const;
const std::vector< jit_type * > & arguments(void) const
llvm::Value * call(llvm::IRBuilderD &builder, const arg_vec &in_args=arg_vec()) const
llvm::Value * call(llvm::IRBuilderD &builder, arg_vec &in_args, llvm::Value *arg1, Args... other_args) const
std::vector< llvm::Value * > arg_vec
jit_type * argument_type(size_t idx) const
bool can_error(void) const
jit_convention::type m_call_conv
jit_type * result(void) const
llvm::Value * call(llvm::IRBuilderD &builder, llvm::Value *arg1, Args... other_args) const
llvm::Value * call(llvm::IRBuilderD &builder, T *arg1, Args... other_args) const
std::vector< jit_type * > m_args
void mark_can_error(void)
const jit_module * m_module
llvm::Function * m_llvm_function
llvm::Function * to_llvm(void) const
llvm::Value * call(llvm::IRBuilderD &builder, arg_vec &in_args, T *arg1, Args... other_args) const
jit_index_operation(const jit_typeinfo &ti, const std::string &name)
virtual jit_function * generate_matrix(const signature_vec &types) const =0
const jit_typeinfo & m_typeinfo
void add_overload(const jit_function &func, const signature_vec &args)
jit_type * result(jit_type *arg1, Args... other_args) const
std::vector< jit_type * > signature_vec
jit_type * result(signature_vec &args, jit_type *arg1, Args... other_args) const
generated_map m_generated
void stash_name(const std::string &aname)
const jit_function & overload(signature_vec &args, jit_type *arg1, Args... other_args) const
const std::string & name(void) const
jit_type * result(const signature_vec &types) const
std::map< const signature_vec *, jit_function *, signature_cmp > generated_map
std::vector< Array< jit_function > > m_overloads
jit_operation(const std::string &aname)
void add_overload(const jit_function &func)
const jit_function & overload(const signature_vec &types) const
const jit_function & overload(jit_type *arg1, Args... other_args) const
jit_function * m_paren_scalar
jit_function * m_paren_scalar
llvm::Type * to_llvm(void) const
bool pointer_arg(jit_convention::type cc) const
bool sret(jit_convention::type cc) const
convert_fn pack(jit_convention::type cc)
llvm::Type * packed_type(jit_convention::type cc)
void set_unpack(jit_convention::type cc, convert_fn fn)
jit_type * parent(void) const
void set_pack(jit_convention::type cc, convert_fn fn)
void mark_pointer_arg(jit_convention::type cc)
void set_packed_type(jit_convention::type cc, llvm::Type *ty)
convert_fn unpack(jit_convention::type cc)
void mark_sret(jit_convention::type cc)
bool skip_paren(void) const
const std::string & name(void) const
static const jit_operation & paren_subsasgn(void)
jit_operation m_logically_true_fn
static llvm::Value * insert_interrupt_check(llvm::IRBuilderD &bld)
static llvm::Type * get_scalar_llvm(void)
llvm::Function * wrap_complex(llvm::Function *wrap)
static llvm::Value * insert_error_check(llvm::IRBuilderD &bld)
std::map< std::string, jit_type * > m_builtins
static llvm::Value * create_complex(llvm::Value *real, llvm::Value *imag)
llvm::Type * m_sig_atomic_type
static bool s_in_construction
static jit_type * get_scalar_ptr(void)
static const jit_function & end(jit_value *value, jit_value *idx, jit_value *count)
llvm::StructType * m_complex_ret
static llvm::Value * pack_complex(llvm::IRBuilderD &bld, llvm::Value *cplx)
static jit_type * get_scalar(void)
jit_type * do_get_intN(size_t nbits) const
static const jit_function & get_release(jit_type *type)
static const jit_operation & destroy(void)
static llvm::Type * get_index_llvm(void)
const jit_operation & do_binary_op(int op) const
llvm::IRBuilderD * m_builder_ptr
jit_operation m_for_index_fn
static const jit_operation & end(void)
llvm::Value * do_insert_error_check(llvm::IRBuilderD &bld)
jit_type * m_unknown_function
static const jit_operation & cast(jit_type *result)
llvm::Value * complex_new(llvm::Value *real, llvm::Value *imag)
std::vector< jit_operation > m_unary_ops
static jit_type * get_any_ptr(void)
jit_type * do_type_of(const octave_value &ov) const
jit_operation m_for_init_fn
void register_intrinsic(const std::string &name, size_t id, jit_type *result, jit_type *arg0)
const jit_function & do_end(jit_value *value, jit_value *index, jit_value *count)
jit_function create_internal(const llvm::Twine &name, jit_type *ret, const signature_vec &args=signature_vec()) const
jit_operation m_for_check_fn
static jit_type * get_any(void)
static const jit_operation & logically_true(void)
static jit_type * get_matrix(void)
jit_operation m_release_fn
static jit_type * get_complex(void)
jit_function create_external(T fn, const llvm::Twine &name, jit_type *ret, jit_type *arg1, Args... other_args) const
static jit_type * get_bool(void)
llvm::Value * do_insert_interrupt_check(llvm::IRBuilderD &bld)
static const jit_operation & for_check(void)
static jit_type * get_range(void)
static const jit_operation & unary_op(int op)
llvm::GlobalVariable * m_loctave_interrupt_state
llvm::StructType * m_range_t
jit_function create_external(T fn, const llvm::Twine &name, jit_type *ret, const signature_vec &args=signature_vec()) const
static const jit_operation & for_index(void)
static const jit_function & get_grab(jit_type *type)
const jit_operation & do_cast(jit_type *to)
jit_function create_external(T fn, const llvm::Twine &name, jit_type *ret, signature_vec &args, jit_type *arg1, Args... other_args) const
llvm::Value * do_pack_complex(llvm::IRBuilderD &bld, llvm::Value *cplx) const
static jit_type * type_of(const octave_value &ov)
void register_generic(const std::string &name, jit_type *result, jit_type *arg0)
friend jit_paren_subsasgn
static jit_type * intN(size_t nbits)
const jit_operation & do_unary_op(int op) const
jit_module * m_base_jit_module
static const jit_operation & release(void)
std::vector< jit_operation > m_casts
static const jit_operation & grab(void)
static const jit_function & cast(jit_type *to, jit_type *from)
jit_function create_internal(const llvm::Twine &name, jit_type *ret, jit_type *arg1, Args... other_args) const
jit_function create_internal(const llvm::Twine &name, jit_type *ret, signature_vec &args, jit_type *arg1, Args... other_args) const
std::vector< jit_function > m_identities
static const jit_operation & for_init(void)
static const jit_operation & paren_subsref(void)
std::map< size_t, jit_type * > m_ints
llvm::IRBuilderD & m_builder
jit_paren_subsref paren_subsref_fn
llvm::GlobalVariable * m_lerror_state
jit_operation m_create_undef_fn
jit_paren_subsasgn paren_subsasgn_fn
static const jit_operation & binary_op(int op)
jit_operation m_destroy_fn
std::vector< jit_type * > signature_vec
static jit_type * get_string(void)
static jit_type * register_new_type(const std::string &name, jit_type *parent, llvm::Type *llvm_type, bool skip_paren=false)
llvm::StructType * m_matrix_t
std::vector< jit_type * > m_id_to_type
jit_operation m_make_range_fn
jit_type * do_register_new_type(const std::string &name, jit_type *parent, llvm::Type *llvm_type, bool skip_paren=false)
static const jit_operation & make_range(void)
static const jit_operation & create_undef(void)
std::vector< jit_operation > m_binary_ops
static jit_type * get_index(void)
static const jit_operation & print_value(void)
const jit_function & do_cast(jit_type *to, jit_type *from)
ColumnVector real(const ComplexColumnVector &a)
ColumnVector imag(const ComplexColumnVector &a)
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
std::ostream & operator<<(std::ostream &os, const jit_block_list &blocks)
jit_type * jit_type_join(jit_type *lhs, jit_type *rhs)
std::ostream & jit_print(std::ostream &os, jit_value *avalue)
jit_array< NDArray, double > jit_matrix
static llvm::IRBuilder builder(tree_jit::llvm_context)
T::size_type numel(const T &str)
octave_idx_type * m_dimensions
octave_idx_type m_slice_len
jit_range(const Range &from)