25 #if ! defined (octave_jit_typeinfo_h)
26 #define octave_jit_typeinfo_h 1
28 #include "octave-config.h"
30 #if defined (HAVE_LLVM)
50 inc (from.inc ()), nelem (from.
numel ())
55 return Range (base, limit, inc);
58 bool all_elements_are_ints ()
const;
69 template <
typename T,
typename U>
82 ref_count =
array->jit_ref_count ();
83 slice_data =
array->jit_slice_data () - 1;
84 slice_len =
array->numel ();
85 dimensions =
array->jit_dimensions ();
140 bool askip_paren,
int aid);
152 llvm::Type *
to_llvm (
void)
const {
return llvm_type; }
155 llvm::Type *to_llvm_arg (
void)
const;
157 size_t depth (
void)
const {
return mdepth; }
170 { msret[cc] =
true; }
178 { mpointer_arg[cc] =
true; }
191 { munpack[cc] = fn; }
195 {
return mpacked_type[cc]; }
198 { mpacked_type[cc] = ty; }
232 const llvm::Twine& aname,
jit_type *aresult,
233 const std::vector<jit_type *>& aargs);
238 const std::vector<jit_type *>& aargs);
245 template <
typename T>
248 do_add_mapping (engine, reinterpret_cast<void *> (fn));
251 bool valid (
void)
const {
return llvm_function; }
255 llvm::BasicBlock *new_block (
const std::string& aname =
"body",
256 llvm::BasicBlock *insert_before = 0);
259 const std::vector<jit_value *>& in_args)
const;
262 const std::vector<llvm::Value *>& in_args
263 = std::vector<llvm::Value *> ())
const;
265 #define JIT_PARAM_ARGS llvm::IRBuilderD& builder,
266 #define JIT_PARAMS builder,
267 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, llvm::Value *, const, N)
277 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, jit_value *, const, N)
285 #undef JIT_PARAM_ARGS
292 llvm::Function *
to_llvm (
void)
const {
return llvm_function; }
295 bool sret (
void)
const {
return mresult && mresult->sret (call_conv); }
297 bool can_error (
void)
const {
return mcan_error; }
299 void mark_can_error (
void) { mcan_error =
true; }
305 assert (idx <
args.size ());
311 void do_add_mapping (llvm::ExecutionEngine *engine,
void *fn);
313 llvm::Module *module;
314 llvm::Function *llvm_function;
316 std::vector<jit_type *>
args;
340 const signature_vec&
args);
342 const jit_function& overload (
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
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);
676 void add_binary_op (
jit_type *ty,
int op,
int llvm_op);
678 void add_binary_icmp (
jit_type *ty,
int op,
int llvm_op);
680 void add_binary_fcmp (
jit_type *ty,
int op,
int llvm_op);
684 template <
typename T>
685 jit_function create_external (llvm::ExecutionEngine *ee, T fn,
687 const std::vector<jit_type *>&
args
688 = std::vector<jit_type *> ())
696 #define JIT_PARAM_ARGS llvm::ExecutionEngine *ee, T fn, \
697 const llvm::Twine& name, jit_type *ret,
698 #define JIT_PARAMS ee, fn, name, ret,
699 #define CREATE_FUNCTION(N) JIT_EXPAND(template <typename T> jit_function, \
708 #undef JIT_PARAM_ARGS
710 #undef CREATE_FUNCTION
714 const llvm::Twine& name,
jit_type *ret,
715 const std::vector<jit_type *>&
args
716 = std::vector<jit_type *> ());
720 const std::vector<jit_type *>&
args
721 = std::vector<jit_type *> ())
726 #define JIT_PARAM_ARGS const llvm::Twine& name, jit_type *ret,
727 #define JIT_PARAMS name, ret,
728 #define CREATE_FUNCTION(N) JIT_EXPAND(jit_function, create_internal, \
736 #undef JIT_PARAM_ARGS
738 #undef CREATE_FUNCTION
748 void register_intrinsic (
const std::string& name,
size_t id,
751 std::vector<jit_type *>
args (1, arg0);
752 register_intrinsic (name,
id, result,
args);
756 const std::vector<jit_type *>&
args);
761 std::vector<jit_type *>
args (1, arg0);
762 register_generic (name, result,
args);
766 const std::vector<jit_type *>&
args);
772 llvm::Function *wrap_complex (llvm::Function *wrap);
780 llvm::Value *complex_real (llvm::Value *cx);
782 llvm::Value *complex_real (llvm::Value *cx, llvm::Value *real);
784 llvm::Value *complex_imag (llvm::Value *cx);
786 llvm::Value *complex_imag (llvm::Value *cx, llvm::Value *imag);
788 llvm::Value *complex_new (llvm::Value *real, llvm::Value *imag);
790 void create_int (
size_t nbits);
796 llvm::Module *module;
797 llvm::ExecutionEngine *engine;
800 llvm::GlobalVariable *lerror_state;
801 llvm::GlobalVariable *loctave_interrupt_state;
803 llvm::Type *sig_atomic_type;
805 std::vector<jit_type*> id_to_type;
817 std::map<size_t, jit_type *> ints;
818 std::map<std::string, jit_type *> builtins;
820 llvm::StructType *complex_ret;
822 std::vector<jit_operation> binary_ops;
823 std::vector<jit_operation> unary_ops;
842 std::vector<jit_operation> casts;
845 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
nd group nd example oindent but is performed more efficiently If only and it is a scalar
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)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the then the first element defines the pivoting tolerance for the unsymmetric the values defined such that for full matrix
jit_range(const Range &from)
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
nd deftypefn *octave_map m
then the function must return scalars which will be concatenated into the return array(s).If code
returns the type of the matrix and caches it for future use Called with more than one argument
octave_idx_type * dimensions
may be zero for pure relative error test tem the relative tolerance must be greater than or equal to
With real return the complex result
convert_fn unpack(jit_convention::type cc)
T::size_type numel(const T &str)
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
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)
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
bool skip_paren(void) const
std::ostream & operator<<(std::ostream &os, const jit_range &rng)
ColumnVector real(const ComplexColumnVector &a)
static void initialize(void)
the second is matched to the second specifier and placed in the second column and so forth If there are more words than specifiers then the process is repeated until all words have been processed or the limit imposed by any(non-whitespace) text in the format that is not one of these specifiers is considered a literal.If there is a literal between two format specifiers then that same literal must appear in the input stream between the matching words.The following specifiers are valid
jit_array< NDArray, double > jit_matrix
llvm::Type * packed_type(jit_convention::type cc)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
void set_unpack(jit_convention::type cc, convert_fn fn)
OCTAVE_EXPORT octave_value_list or cell arrays Arguments are concatenated vertically The returned values are padded with blanks as needed to make each row of the string array have the same length Empty input strings are significant and will concatenated in the output For numerical each element is converted to the corresponding ASCII character A range error results if an input is outside the ASCII range(0-255).For cell arrays
const std::vector< jit_type * > & arguments(void) const
octave_value do_binary_op(octave_value::binary_op op, const octave_value &v1, const octave_value &v2)