GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
jit-typeinfo.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2018 Max Brister
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Author: Max Brister <max@2bass.com>
24 
25 #if ! defined (octave_jit_typeinfo_h)
26 #define octave_jit_typeinfo_h 1
27 
28 #include "octave-config.h"
29 
30 #if defined (HAVE_LLVM)
31 
32 #include <map>
33 #include <vector>
34 
35 #include "Range.h"
36 #include "jit-util.h"
37 
38 namespace octave
39 {
40  class jit_typeinfo;
41  class jit_module;
42 
43  // Defines the type system used by jit and a singleton class, jit_typeinfo, to
44  // manage the types.
45  //
46  // FIXME:
47  // Operations are defined and implemented in jit_typeinfo. Eventually they
48  // should be moved elsewhere. (just like with octave_typeinfo)
49 
50  // jit_range is compatible with the llvm range structure
51  struct
52  jit_range
53  {
54  jit_range (const Range& from)
55  : m_base (from.base ()), m_limit (from.limit ()), m_inc (from.inc ()),
56  m_nelem (from.numel ())
57  { }
58 
59  operator Range () const
60  {
61  return Range (m_base, m_limit, m_inc);
62  }
63 
64  bool all_elements_are_ints (void) const;
65 
66  double m_base;
67  double m_limit;
68  double m_inc;
70  };
71 
72  std::ostream& operator << (std::ostream& os, const jit_range& rng);
73 
74  // jit_array is compatible with the llvm array/matrix structures
75  template <typename T, typename U>
76  struct
77  jit_array
78  {
79  jit_array (void) : m_array (0) { }
80 
81  jit_array (T& from) : m_array (new T (from))
82  {
83  update ();
84  }
85 
86  void update (void)
87  {
88  m_ref_count = m_array->jit_ref_count ();
89  m_slice_data = m_array->jit_slice_data () - 1;
90  m_slice_len = m_array->numel ();
91  m_dimensions = m_array->jit_dimensions ();
92  }
93 
94  void update (T *aarray)
95  {
96  m_array = aarray;
97  update ();
98  }
99 
100  operator T () const
101  {
102  return *m_array;
103  }
104 
106 
110 
112  };
113 
115 
116  std::ostream& operator << (std::ostream& os, const jit_matrix& mat);
117 
118  // calling convention
119  namespace jit_convention
120  {
121  enum
122  type
123  {
124  // internal to jit
125  internal,
126 
127  // an external C call
129 
131  };
132  }
133 
134  // Used to keep track of estimated (infered) types during JIT. This is a
135  // hierarchical type system which includes both concrete and abstract types.
136  //
137  // The types form a lattice. Currently we only allow for one parent type, but
138  // eventually we may allow for multiple predecessors.
139  class
140  jit_type
141  {
142  public:
143 
144  typedef llvm::Value *(*convert_fn) (llvm::IRBuilderD&, llvm::Value *);
145 
146  jit_type (const std::string& aname, jit_type *aparent, llvm::Type *allvm_type,
147  bool askip_paren, int aid);
148 
149  // a user readable type name
150  const std::string& name (void) const { return m_name; }
151 
152  // a unique id for the type
153  int type_id (void) const { return m_id; }
154 
155  // An abstract base type, may be null
156  jit_type * parent (void) const { return m_parent; }
157 
158  // convert to an llvm type
159  llvm::Type * to_llvm (void) const { return m_llvm_type; }
160 
161  // how this type gets passed as a function argument
162  llvm::Type * to_llvm_arg (void) const;
163 
164  size_t depth (void) const { return m_depth; }
165 
166  bool skip_paren (void) const { return m_skip_paren; }
167 
168  // -------------------- Calling Convention information --------------------
169 
170  // A function declared like: mytype foo (int arg0, int arg1);
171  // Will be converted to: void foo (mytype *retval, int arg0, int arg1)
172  // if mytype is sret. The caller is responsible for allocating space for
173  // retval. (on the stack)
174  bool sret (jit_convention::type cc) const { return m_sret[cc]; }
175 
177  { m_sret[cc] = true; }
178 
179  // A function like: void foo (mytype arg0)
180  // Will be converted to: void foo (mytype *arg0)
181  // Basically just pass by reference.
182  bool pointer_arg (jit_convention::type cc) const { return m_pointer_arg[cc]; }
183 
185  { m_pointer_arg[cc] = true; }
186 
187  // Convert into an equivalent form before calling. For example, complex is
188  // represented as two values llvm vector, but we need to pass it as a two
189  // valued llvm structure to C functions.
190  convert_fn pack (jit_convention::type cc) { return m_pack[cc]; }
191 
192  void set_pack (jit_convention::type cc, convert_fn fn) { m_pack[cc] = fn; }
193 
194  // The inverse operation of pack.
195  convert_fn unpack (jit_convention::type cc) { return m_unpack[cc]; }
196 
197  void set_unpack (jit_convention::type cc, convert_fn fn)
198  { m_unpack[cc] = fn; }
199 
200  // The resulting type after pack is called.
202  { return m_packed_type[cc]; }
203 
204  void set_packed_type (jit_convention::type cc, llvm::Type *ty)
205  { m_packed_type[cc] = ty; }
206 
207  private:
208 
211  llvm::Type *m_llvm_type;
212  int m_id;
213  size_t m_depth;
215 
217  bool m_pointer_arg[jit_convention::length];
218 
219  convert_fn m_pack[jit_convention::length];
220  convert_fn m_unpack[jit_convention::length];
221 
222  llvm::Type *m_packed_type[jit_convention::length];
223  };
224 
225  // seperate print function to allow easy printing if type is null
226  std::ostream& jit_print (std::ostream& os, jit_type *atype);
227 
228  // Find common type
229  jit_type* jit_type_join (jit_type *lhs, jit_type *rhs);
230 
231 
232 
233  class jit_value;
234 
235  // An abstraction for calling llvm functions with jit_values. Deals with
236  // calling convention details.
237  class
239  {
240  friend std::ostream& operator << (std::ostream& os, const jit_function& fn);
241 
242  public:
243 
244  // create a function in an invalid state
245  jit_function (void);
246 
247  jit_function (const jit_module *amodule, jit_convention::type acall_conv,
248  const llvm::Twine& aname, jit_type *aresult,
249  const std::vector<jit_type *>& aargs);
250 
251  // Use an existing function, but change the argument types. The new argument
252  // types must behave the same for the current calling convention.
253  jit_function (const jit_function& fn, jit_type *aresult,
254  const std::vector<jit_type *>& aargs);
255 
256  jit_function (const jit_function& fn);
257 
258  // erase the interal LLVM function (if it exists). Will become invalid.
259  void erase (void);
260 
261  bool valid (void) const { return m_llvm_function; }
262 
263  std::string name (void) const;
264 
265  llvm::BasicBlock * new_block (const std::string& aname = "body",
266  llvm::BasicBlock *insert_before = nullptr);
267 
268  typedef std::vector<llvm::Value *> arg_vec;
269 
270  llvm::Value * call (llvm::IRBuilderD& builder,
271  const arg_vec& in_args = arg_vec ()) const;
272 
273  llvm::Value * call (llvm::IRBuilderD& builder,
274  const std::vector<jit_value *>& in_args) const;
275 
276  template <typename ...Args>
277  llvm::Value * call (llvm::IRBuilderD& builder, arg_vec& in_args,
278  llvm::Value * arg1, Args... other_args) const
279  {
280  in_args.push_back (arg1);
281  return call (builder, in_args, other_args...);
282  }
283 
284  template <typename T, typename ...Args>
285  llvm::Value * call (llvm::IRBuilderD& builder, arg_vec& in_args,
286  T * arg1, Args... other_args) const
287  {
288  in_args.push_back (arg1->to_llvm ());
289  return call (builder, in_args, other_args...);
290  }
291 
292  template <typename ...Args>
293  llvm::Value * call (llvm::IRBuilderD& builder, llvm::Value * arg1,
294  Args... other_args) const
295  {
296  arg_vec in_args;
297  in_args.reserve (1 + sizeof... (other_args));
298  in_args.push_back (arg1);
299  return call (builder, in_args, other_args...);
300  }
301 
302  template <typename T, typename ...Args>
303  llvm::Value * call (llvm::IRBuilderD& builder, T * arg1,
304  Args... other_args) const
305  {
306  arg_vec in_args;
307  in_args.reserve (1 + sizeof... (other_args));
308  in_args.push_back (arg1->to_llvm ());
309  return call (builder, in_args, other_args...);
310  }
311 
312  llvm::Value * argument (llvm::IRBuilderD& builder, size_t idx) const;
313 
314  void do_return (llvm::IRBuilderD& builder, llvm::Value *rval = nullptr,
315  bool verify = true);
316 
317  llvm::Function * to_llvm (void) const { return m_llvm_function; }
318 
319  // If true, then the return value is passed as a pointer in the first argument
320  bool sret (void) const { return m_result && m_result->sret (m_call_conv); }
321 
322  bool can_error (void) const { return m_can_error; }
323 
324  void mark_can_error (void) { m_can_error = true; }
325 
326  jit_type * result (void) const { return m_result; }
327 
328  jit_type * argument_type (size_t idx) const
329  {
330  assert (idx < m_args.size ());
331  return m_args[idx];
332  }
333 
334  const std::vector<jit_type *>& arguments (void) const { return m_args; }
335 
336  private:
337 
339  llvm::Function *m_llvm_function;
341  std::vector<jit_type *> m_args;
344  };
345 
346  std::ostream& operator << (std::ostream& os, const jit_function& fn);
347 
348  // Keeps track of information about how to implement operations (+, -, *, ect)
349  // and their resulting types.
350  class
352  {
353  public:
354 
355  jit_operation (const std::string& aname) { m_name = aname; }
356 
357  // type signature vector
358  typedef std::vector<jit_type *> signature_vec;
359 
360  virtual ~jit_operation (void);
361 
362  void add_overload (const jit_function& func)
363  {
364  add_overload (func, func.arguments ());
365  }
366 
367  void add_overload (const jit_function& func,
368  const signature_vec& args);
369 
370  const jit_function& overload (const signature_vec& types) const;
371 
372  template <typename ...Args>
374  Args... other_args) const
375  {
376  args.push_back (arg1);
377  return overload (args, other_args...);
378  }
379 
380  template <typename ...Args>
381  const jit_function& overload (jit_type * arg1, Args... other_args) const
382  {
383  signature_vec args;
384  args.reserve (1 + sizeof... (other_args));
385  args.push_back (arg1);
386  return overload (args, other_args...);
387  }
388 
389  jit_type * result (const signature_vec& types) const
390  {
391  const jit_function& temp = overload (types);
392  return temp.result ();
393  }
394 
395  template <typename ...Args>
397  Args... other_args) const
398  {
399  args.push_back (arg1);
400  return overload (args, other_args...);
401  }
402 
403  template <typename ...Args>
404  jit_type * result (jit_type * arg1, Args... other_args) const
405  {
406  signature_vec args;
407  args.reserve (1 + sizeof... (other_args));
408  args.push_back (arg1);
409  return overload (args, other_args...);
410  }
411 
412  const std::string& name (void) const { return m_name; }
413 
414  void stash_name (const std::string& aname) { m_name = aname; }
415 
416  protected:
417 
418  virtual jit_function * generate (const signature_vec& types) const;
419 
420  private:
421 
422  Array<octave_idx_type> to_idx (const signature_vec& types) const;
423 
424  const jit_function& do_generate (const signature_vec& types) const;
425 
427  {
428  bool operator () (const signature_vec *lhs, const signature_vec *rhs) const;
429  };
430 
431  typedef std::map<const signature_vec *, jit_function *, signature_cmp>
433 
435 
436  std::vector<Array<jit_function>> m_overloads;
437 
439  };
440 
441 
442  class
444  {
445  public:
446 
448  : jit_operation (name), m_typeinfo (ti) { }
449 
450  protected:
451 
452  virtual jit_function * generate (const signature_vec& types) const;
453 
454  virtual jit_function * generate_matrix (const signature_vec& types) const = 0;
455 
456  // helper functions
457  // [start_idx, end_idx).
458  llvm::Value * create_arg_array (llvm::IRBuilderD& builder,
459  const jit_function& fn, size_t start_idx,
460  size_t end_idx) const;
461 
463  };
464 
465  class
467  {
468  public:
469 
470  // FIXME: Avoid creating object in an invalid state?
471  jit_paren_subsref (const jit_typeinfo& ti);
472  ~jit_paren_subsref (void);
473  void init_paren_scalar (void);
474 
475  protected:
476 
477  virtual jit_function * generate_matrix (const signature_vec& types) const;
478 
479  private:
480 
482  };
483 
484  class
486  {
487  public:
488 
489  // FIXME: Avoid creating object in an invalid state?
490  jit_paren_subsasgn (const jit_typeinfo& ti);
491  ~jit_paren_subsasgn (void);
492  void init_paren_scalar (void);
493 
494  protected:
495 
496  jit_function * generate_matrix (const signature_vec& types) const;
497 
498  private:
499 
501  };
502 
503 
504  // A singleton class which handles the construction of jit_types
505  class
507  {
508  // ----- Constructor/destructor (singleton pattern) -----
509 
510  public:
511 
512  ~jit_typeinfo (void);
513 
514  private:
515 
516  static jit_typeinfo& instance (void);
517  jit_typeinfo (void);
518  static bool s_in_construction;
519 
520  // ----- Registering types -----
521 
522  public:
523 
525  llvm::Type *llvm_type, bool skip_paren = false)
526  {
527  return instance ().do_register_new_type (name, parent, llvm_type, skip_paren);
528  }
529 
530  private:
531 
532  // List of all registered types
533  std::vector<jit_type*> m_id_to_type;
534 
535  // Register a new type
536  jit_type *do_register_new_type (const std::string& name, jit_type *parent,
537  llvm::Type *llvm_type, bool skip_paren = false);
538 
539  // ----- Base types -----
540 
541  public:
542 
543  static jit_type *get_any (void) { return instance ().m_any; }
544 
545  static jit_type *get_matrix (void) { return instance ().m_matrix; }
546 
547  static jit_type *get_scalar (void) { return instance ().m_scalar; }
548 
549  static jit_type *get_scalar_ptr (void) { return instance ().m_scalar_ptr; }
550 
551  static jit_type *get_any_ptr (void) { return instance ().m_any_ptr; }
552 
553  static jit_type *get_range (void) { return instance ().m_range; }
554 
555  static jit_type *get_string (void) { return instance ().m_string; }
556 
557  static jit_type *get_bool (void) { return instance ().m_boolean; }
558 
559  static jit_type *get_index (void) { return instance ().m_index; }
560 
561  static jit_type *get_complex (void) { return instance ().m_complex; }
562 
563  static jit_type *intN (size_t nbits) { return instance ().do_get_intN (nbits); }
564 
565  // FIXME: do we really need these two ?
566  static llvm::Type *get_scalar_llvm (void) { return instance ().m_scalar->to_llvm (); } // this one is weird
567 
568  static llvm::Type *get_index_llvm (void) { return instance ().m_index->to_llvm (); } // this one is weird too
569 
570  private:
571 
572  // Base types as LLVM types
573 
574  llvm::Type *m_any_t;
575  llvm::Type *m_bool_t; // FIXME: should be "boolean_t", for consistency
576  llvm::Type *m_complex_t;
577  llvm::Type *m_index_t;
578  llvm::Type *m_scalar_t;
579  llvm::Type *m_string_t;
580 
581  llvm::StructType *m_range_t;
582  llvm::StructType *m_matrix_t;
583 
584  // Base types as jit_type objects)
585 
592 
595 
596  jit_type *m_scalar_ptr; // a fake type for interfacing with C++
597  jit_type *m_any_ptr; // a fake type for interfacing with C++ (bis)
599 
600  // complex_ret is what is passed to C functions
601  // in order to get calling convention right
602  llvm::StructType *m_complex_ret;
603 
604  // Get integer type from number of bits
605  jit_type *do_get_intN (size_t nbits) const;
606 
607  // map container for integer types: int8, int16, etc.
608  // (note that they are also stored in id_to_types)
609  std::map<size_t, jit_type *> m_ints;
610 
611  // ----- parenthesis subsref/subsasgn -----
612 
615 
616  public:
617 
618  static const jit_operation& paren_subsref (void) { return instance ().paren_subsref_fn; }
619  static const jit_operation& paren_subsasgn (void) { return instance ().paren_subsasgn_fn; }
620 
621  private:
622 
625 
626  // ----- Miscellaneous (FIXME: needs to be organized) -----
627 
628  public:
629 
630  // Get the jit_type of an octave_value
631  static jit_type *type_of (const octave_value &ov)
632  {
633  return instance ().do_type_of (ov);
634  };
635 
636  // Get a unary or binary operation from its integer id
637  static const jit_operation& binary_op (int op)
638  {
639  return instance ().do_binary_op (op);
640  }
641 
642  static const jit_operation& unary_op (int op)
643  {
644  return instance ().do_unary_op (op);
645  }
646 
647  static const jit_operation& grab (void)
648  {
649  return instance ().m_grab_fn;
650  }
651 
653  {
654  return instance ().m_grab_fn.overload (type);
655  }
656 
657  static const jit_operation& release (void)
658  {
659  return instance ().m_release_fn;
660  }
661 
663  {
664  return instance ().m_release_fn.overload (type);
665  }
666 
667  static const jit_operation& destroy (void)
668  {
669  return instance ().m_destroy_fn;
670  }
671 
672  static const jit_operation& print_value (void)
673  {
674  return instance ().m_print_fn;
675  }
676 
677  static const jit_operation& for_init (void)
678  {
679  return instance ().m_for_init_fn;
680  }
681 
682  static const jit_operation& for_check (void)
683  {
684  return instance ().m_for_check_fn;
685  }
686 
687  static const jit_operation& for_index (void)
688  {
689  return instance ().m_for_index_fn;
690  }
691 
692  static const jit_operation& make_range (void)
693  {
694  return instance ().m_make_range_fn;
695  }
696 
697  static const jit_operation& logically_true (void)
698  {
699  return instance ().m_logically_true_fn;
700  }
701 
703  {
704  return instance ().do_cast (result);
705  }
706 
707  static const jit_function& cast (jit_type *to, jit_type *from)
708  {
709  return instance ().do_cast (to, from);
710  }
711 
712  static llvm::Value *insert_error_check (llvm::IRBuilderD& bld)
713  {
714  return instance ().do_insert_error_check (bld);
715  }
716 
717  static llvm::Value *insert_interrupt_check (llvm::IRBuilderD& bld)
718  {
719  return instance ().do_insert_interrupt_check (bld);
720  }
721 
722  static const jit_operation& end (void)
723  {
724  return instance ().m_end_fn;
725  }
726 
727  static const jit_function& end (jit_value *value, jit_value *idx,
728  jit_value *count)
729  {
730  return instance ().do_end (value, idx, count);
731  }
732 
733  static const jit_operation& create_undef (void)
734  {
735  return instance ().m_create_undef_fn;
736  }
737 
738  static llvm::Value *create_complex (llvm::Value *real, llvm::Value *imag)
739  {
740  return instance ().complex_new (real, imag);
741  }
742 
743  static llvm::Value *pack_complex (llvm::IRBuilderD& bld, llvm::Value *cplx)
744  {
745  return instance ().do_pack_complex (bld, cplx);
746  }
747 
748  static llvm::Value *unpack_complex (llvm::IRBuilderD& bld,
749  llvm::Value *result);
750 
751  private:
752 
753  jit_type * do_type_of (const octave_value& ov) const;
754 
755  const jit_operation& do_binary_op (int op) const
756  {
757  assert (static_cast<size_t>(op) < m_binary_ops.size ());
758  return m_binary_ops[op];
759  }
760 
761  const jit_operation& do_unary_op (int op) const
762  {
763  assert (static_cast<size_t> (op) < m_unary_ops.size ());
764  return m_unary_ops[op];
765  }
766 
768  {
769  static jit_operation null_function ("null_function");
770  if (! to)
771  return null_function;
772 
773  size_t id = to->type_id ();
774  if (id >= m_casts.size ())
775  return null_function;
776  return m_casts[id];
777  }
778 
779  const jit_function& do_cast (jit_type *to, jit_type *from)
780  {
781  return do_cast (to).overload (from);
782  }
783 
784  const jit_function& do_end (jit_value *value, jit_value *index,
785  jit_value *count);
786 
787  void add_print (jit_type *ty, void *fptr);
788 
789  void add_binary_op (jit_type *ty, int op, int llvm_op);
790 
791  void add_binary_icmp (jit_type *ty, int op, int llvm_op);
792 
793  void add_binary_fcmp (jit_type *ty, int op, int llvm_op);
794 
795  // type signature vector
796  typedef std::vector<jit_type *> signature_vec;
797 
798  // create a function with an external calling convention
799  // forces the function pointer to be specified
800  template <typename T>
801  jit_function create_external (T fn, const llvm::Twine& name,
802  jit_type * ret, const signature_vec& args
803  = signature_vec ()) const;
804 
805  template <typename T, typename ...Args>
806  jit_function create_external (T fn, const llvm::Twine& name,
807  jit_type * ret, signature_vec& args,
808  jit_type * arg1, Args... other_args) const
809  {
810  args.push_back (arg1);
811  return create_external (fn, name, ret, args, other_args...);
812  }
813 
814  template <typename T, typename ...Args>
815  jit_function create_external (T fn, const llvm::Twine& name, jit_type *ret,
816  jit_type * arg1, Args... other_args) const
817  {
818  signature_vec args;
819  args.reserve (1 + sizeof... (other_args));
820  args.push_back (arg1);
821  return create_external (fn, name, ret, args, other_args...);
822  }
823 
824  // create an internal calling convention (a function defined in llvm)
825  jit_function create_internal (const llvm::Twine& name, jit_type *ret,
826  const signature_vec& args
827  = signature_vec ()) const
828  {
829  return jit_function (m_base_jit_module, jit_convention::internal,
830  name, ret, args);
831  }
832 
833  template <typename ...Args>
834  jit_function create_internal (const llvm::Twine& name, jit_type *ret,
835  signature_vec& args,
836  jit_type * arg1, Args... other_args) const
837  {
838  args.push_back (arg1);
839  return create_internal (name, ret, args, other_args...);
840  }
841 
842  template <typename ...Args>
843  jit_function create_internal (const llvm::Twine& name, jit_type *ret,
844  jit_type * arg1, Args... other_args) const
845  {
846  signature_vec args;
847  args.reserve (1 + sizeof... (other_args));
848  args.push_back (arg1);
849  return create_internal (name, ret, args, other_args...);
850  }
851 
852  jit_function create_identity (jit_type *type);
853 
854  llvm::Value * do_insert_error_check (llvm::IRBuilderD& bld);
855 
856  llvm::Value * do_insert_interrupt_check (llvm::IRBuilderD& bld);
857 
858  void add_builtin (const std::string& name);
859 
860  void register_intrinsic (const std::string& name, size_t id,
861  jit_type *result, jit_type *arg0)
862  {
863  std::vector<jit_type *> args (1, arg0);
864  register_intrinsic (name, id, result, args);
865  }
866 
867  void register_intrinsic (const std::string& name, size_t id, jit_type *result,
868  const std::vector<jit_type *>& args);
869 
871  jit_type *arg0)
872  {
873  std::vector<jit_type *> args (1, arg0);
874  register_generic (name, result, args);
875  }
876 
877  void register_generic (const std::string& name, jit_type *result,
878  const std::vector<jit_type *>& args);
879 
880  octave_builtin * find_builtin (const std::string& name);
881 
882  jit_function mirror_binary (const jit_function& fn);
883 
884  llvm::Function * wrap_complex (llvm::Function *wrap);
885 
886  llvm::Value * complex_real (llvm::Value *cx);
887 
888  llvm::Value * complex_real (llvm::Value *cx, llvm::Value *real);
889 
890  llvm::Value * complex_imag (llvm::Value *cx);
891 
892  llvm::Value * complex_imag (llvm::Value *cx, llvm::Value *imag);
893 
894  llvm::Value * complex_new (llvm::Value *real, llvm::Value *imag);
895 
896  llvm::Value *do_pack_complex (llvm::IRBuilderD& bld, llvm::Value *cplx) const;
897 
899 
900  llvm::GlobalVariable *m_lerror_state;
901  llvm::GlobalVariable *m_loctave_interrupt_state;
902 
903  llvm::Type *m_sig_atomic_type;
904 
905  std::map<std::string, jit_type *> m_builtins;
906 
907  std::vector<jit_operation> m_binary_ops;
908  std::vector<jit_operation> m_unary_ops;
921 
923 
924  // type id -> cast function TO that type
925  std::vector<jit_operation> m_casts;
926 
927  // type id -> identity function
928  std::vector<jit_function> m_identities;
929 
931 
934  };
935 }
936 
937 #endif
938 #endif
uint32_t id
Definition: graphics.cc:12193
jit_type * result(const signature_vec &types) const
Definition: jit-typeinfo.h:389
static const jit_operation & destroy(void)
Definition: jit-typeinfo.h:667
static const jit_operation & for_init(void)
Definition: jit-typeinfo.h:677
jit_operation m_release_fn
Definition: jit-typeinfo.h:910
static jit_type * get_index(void)
Definition: jit-typeinfo.h:559
const std::string & name(void) const
Definition: jit-typeinfo.h:412
jit_operation m_end1_fn
Definition: jit-typeinfo.h:918
const jit_operation & do_binary_op(int op) const
Definition: jit-typeinfo.h:755
llvm::Type * to_llvm(void) const
Definition: jit-typeinfo.h:159
const std::vector< jit_type * > & arguments(void) const
Definition: jit-typeinfo.h:334
jit_type * result(signature_vec &args, jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:396
static const jit_function & cast(jit_type *to, jit_type *from)
Definition: jit-typeinfo.h:707
llvm::Function * to_llvm(void) const
Definition: jit-typeinfo.h:317
static jit_type * intN(size_t nbits)
Definition: jit-typeinfo.h:563
jit_operation(const std::string &aname)
Definition: jit-typeinfo.h:355
static llvm::Type * get_index_llvm(void)
Definition: jit-typeinfo.h:568
jit_operation m_destroy_fn
Definition: jit-typeinfo.h:911
jit_function * m_paren_scalar
Definition: jit-typeinfo.h:481
std::vector< jit_type * > m_args
Definition: jit-typeinfo.h:341
llvm::StructType * m_range_t
Definition: jit-typeinfo.h:581
llvm::Value * call(llvm::IRBuilderD &builder, arg_vec &in_args, T *arg1, Args... other_args) const
Definition: jit-typeinfo.h:285
llvm::Type * m_llvm_type
Definition: jit-typeinfo.h:211
static const jit_operation & paren_subsasgn(void)
Definition: jit-typeinfo.h:619
const jit_function & do_end(jit_value *value, jit_value *index, jit_value *count)
static const jit_operation & cast(jit_type *result)
Definition: jit-typeinfo.h:702
jit_convention::type m_call_conv
Definition: jit-typeinfo.h:342
std::map< size_t, jit_type * > m_ints
Definition: jit-typeinfo.h:609
jit_array< NDArray, double > jit_matrix
Definition: jit-typeinfo.h:114
generated_map m_generated
Definition: jit-typeinfo.h:434
static const jit_operation & binary_op(int op)
Definition: jit-typeinfo.h:637
bool sret(void) const
Definition: jit-typeinfo.h:320
size_t depth(void) const
Definition: jit-typeinfo.h:164
jit_type * jit_type_join(jit_type *lhs, jit_type *rhs)
jit_function create_internal(const llvm::Twine &name, jit_type *ret, jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:843
static jit_type * get_matrix(void)
Definition: jit-typeinfo.h:545
jit_function * m_paren_scalar
Definition: jit-typeinfo.h:500
static jit_type * get_any_ptr(void)
Definition: jit-typeinfo.h:551
Definition: Range.h:33
static jit_type * get_scalar_ptr(void)
Definition: jit-typeinfo.h:549
static llvm::Value * insert_interrupt_check(llvm::IRBuilderD &bld)
Definition: jit-typeinfo.h:717
llvm::Type * m_string_t
Definition: jit-typeinfo.h:579
llvm::Value * do_insert_error_check(llvm::IRBuilderD &bld)
static llvm::Type * get_scalar_llvm(void)
Definition: jit-typeinfo.h:566
static const jit_operation & for_index(void)
Definition: jit-typeinfo.h:687
jit_type * do_type_of(const octave_value &ov) const
llvm::Type * m_any_t
Definition: jit-typeinfo.h:574
jit_type * argument_type(size_t idx) const
Definition: jit-typeinfo.h:328
jit_function create_internal(const llvm::Twine &name, jit_type *ret, signature_vec &args, jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:834
static const jit_operation & print_value(void)
Definition: jit-typeinfo.h:672
llvm::Value * do_insert_interrupt_check(llvm::IRBuilderD &bld)
const jit_operation & do_unary_op(int op) const
Definition: jit-typeinfo.h:761
llvm::Value * call(llvm::IRBuilderD &builder, llvm::Value *arg1, Args... other_args) const
Definition: jit-typeinfo.h:293
static llvm::Value * create_complex(llvm::Value *real, llvm::Value *imag)
Definition: jit-typeinfo.h:738
jit_operation m_print_fn
Definition: jit-typeinfo.h:912
static llvm::IRBuilder builder(llvm::getGlobalContext())
llvm::Type * m_sig_atomic_type
Definition: jit-typeinfo.h:903
void mark_can_error(void)
Definition: jit-typeinfo.h:324
const jit_function & do_cast(jit_type *to, jit_type *from)
Definition: jit-typeinfo.h:779
std::ostream & jit_print(std::ostream &os, jit_value *avalue)
Definition: jit-ir.cc:198
void set_unpack(jit_convention::type cc, convert_fn fn)
Definition: jit-typeinfo.h:197
jit_type * m_unknown_function
Definition: jit-typeinfo.h:598
bool sret(jit_convention::type cc) const
Definition: jit-typeinfo.h:174
void register_generic(const std::string &name, jit_type *result, jit_type *arg0)
Definition: jit-typeinfo.h:870
static jit_type * get_range(void)
Definition: jit-typeinfo.h:553
llvm::IRBuilderD & m_builder
Definition: jit-typeinfo.h:933
octave_idx_type m_nelem
Definition: jit-typeinfo.h:69
std::map< const signature_vec *, jit_function *, signature_cmp > generated_map
Definition: jit-typeinfo.h:432
int type_id(void) const
Definition: jit-typeinfo.h:153
const jit_operation & do_cast(jit_type *to)
Definition: jit-typeinfo.h:767
const jit_function & overload(signature_vec &args, jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:373
bool valid(void) const
Definition: jit-typeinfo.h:261
llvm::Type * packed_type(jit_convention::type cc)
Definition: jit-typeinfo.h:201
jit_function m_any_call
Definition: jit-typeinfo.h:922
std::map< std::string, jit_type * > m_builtins
Definition: jit-typeinfo.h:905
void register_intrinsic(const std::string &name, size_t id, jit_type *result, jit_type *arg0)
Definition: jit-typeinfo.h:860
jit_operation m_logically_true_fn
Definition: jit-typeinfo.h:916
nd deftypefn *std::string name
Definition: sysdep.cc:647
static const jit_operation & release(void)
Definition: jit-typeinfo.h:657
static const jit_operation & paren_subsref(void)
Definition: jit-typeinfo.h:618
std::ostream & operator<<(std::ostream &os, const jit_block_list &blocks)
Definition: jit-ir.cc:133
convert_fn unpack(jit_convention::type cc)
Definition: jit-typeinfo.h:195
octave_idx_type m_slice_len
Definition: jit-typeinfo.h:108
jit_type * parent(void) const
Definition: jit-typeinfo.h:156
static jit_type * type_of(const octave_value &ov)
Definition: jit-typeinfo.h:631
static const jit_operation & grab(void)
Definition: jit-typeinfo.h:647
void add_overload(const jit_function &func)
Definition: jit-typeinfo.h:362
jit_operation m_for_index_fn
Definition: jit-typeinfo.h:915
llvm::StructType * m_complex_ret
Definition: jit-typeinfo.h:602
jit_operation m_for_check_fn
Definition: jit-typeinfo.h:914
llvm::Type * m_scalar_t
Definition: jit-typeinfo.h:578
const jit_function & overload(jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:381
returns the type of the matrix and caches it for future use Called with more than one argument
Definition: matrix_type.cc:120
static const jit_operation & logically_true(void)
Definition: jit-typeinfo.h:697
convert_fn pack(jit_convention::type cc)
Definition: jit-typeinfo.h:190
llvm::Value * do_pack_complex(llvm::IRBuilderD &bld, llvm::Value *cplx) const
static const jit_function & end(jit_value *value, jit_value *idx, jit_value *count)
Definition: jit-typeinfo.h:727
static jit_type * register_new_type(const std::string &name, jit_type *parent, llvm::Type *llvm_type, bool skip_paren=false)
Definition: jit-typeinfo.h:524
static const jit_operation & for_check(void)
Definition: jit-typeinfo.h:682
void update(void)
Definition: jit-typeinfo.h:86
std::vector< jit_operation > m_casts
Definition: jit-typeinfo.h:925
std::vector< jit_type * > signature_vec
Definition: jit-typeinfo.h:796
std::vector< jit_operation > m_unary_ops
Definition: jit-typeinfo.h:908
jit_module * m_base_jit_module
Definition: jit-typeinfo.h:930
jit_function create_external(T fn, const llvm::Twine &name, jit_type *ret, signature_vec &args, jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:806
void set_pack(jit_convention::type cc, convert_fn fn)
Definition: jit-typeinfo.h:192
idx type
Definition: ov.cc:3114
void set_packed_type(jit_convention::type cc, llvm::Type *ty)
Definition: jit-typeinfo.h:204
static jit_type * get_scalar(void)
Definition: jit-typeinfo.h:547
llvm::Type * m_bool_t
Definition: jit-typeinfo.h:575
jit_paren_subsasgn paren_subsasgn_fn
Definition: jit-typeinfo.h:624
static const jit_function & get_release(jit_type *type)
Definition: jit-typeinfo.h:662
void stash_name(const std::string &aname)
Definition: jit-typeinfo.h:414
static const jit_function & get_grab(jit_type *type)
Definition: jit-typeinfo.h:652
static const jit_operation & end(void)
Definition: jit-typeinfo.h:722
std::vector< jit_type * > m_id_to_type
Definition: jit-typeinfo.h:533
With real return the complex result
Definition: data.cc:3260
std::vector< jit_type * > signature_vec
Definition: jit-typeinfo.h:358
llvm::Function * m_llvm_function
Definition: jit-typeinfo.h:339
llvm::IRBuilderD * m_builder_ptr
Definition: jit-typeinfo.h:932
std::vector< llvm::Value * > arg_vec
Definition: jit-typeinfo.h:268
llvm::Value * complex_new(llvm::Value *real, llvm::Value *imag)
jit_type * result(void) const
Definition: jit-typeinfo.h:326
static jit_type * get_string(void)
Definition: jit-typeinfo.h:555
static jit_type * get_any(void)
Definition: jit-typeinfo.h:543
jit_operation m_make_range_fn
Definition: jit-typeinfo.h:917
T::size_type numel(const T &str)
Definition: oct-string.cc:61
static const jit_operation & unary_op(int op)
Definition: jit-typeinfo.h:642
static llvm::Value * insert_error_check(llvm::IRBuilderD &bld)
Definition: jit-typeinfo.h:712
jit_paren_subsref paren_subsref_fn
Definition: jit-typeinfo.h:623
llvm::Value * call(llvm::IRBuilderD &builder, T *arg1, Args... other_args) const
Definition: jit-typeinfo.h:303
static jit_type * get_bool(void)
Definition: jit-typeinfo.h:557
jit_function create_external(T fn, const llvm::Twine &name, jit_type *ret, jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:815
jit_operation m_create_undef_fn
Definition: jit-typeinfo.h:920
bool skip_paren(void) const
Definition: jit-typeinfo.h:166
bool pointer_arg(jit_convention::type cc) const
Definition: jit-typeinfo.h:182
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Definition: lo-specfun.cc:1129
jit_type * do_register_new_type(const std::string &name, jit_type *parent, llvm::Type *llvm_type, bool skip_paren=false)
const jit_function & overload(const signature_vec &types) const
jit_type * result(jit_type *arg1, Args... other_args) const
Definition: jit-typeinfo.h:404
void mark_sret(jit_convention::type cc)
Definition: jit-typeinfo.h:176
static const jit_operation & make_range(void)
Definition: jit-typeinfo.h:692
llvm::Value * call(llvm::IRBuilderD &builder, arg_vec &in_args, llvm::Value *arg1, Args... other_args) const
Definition: jit-typeinfo.h:277
jit_function create_internal(const llvm::Twine &name, jit_type *ret, const signature_vec &args=signature_vec()) const
Definition: jit-typeinfo.h:825
bool can_error(void) const
Definition: jit-typeinfo.h:322
void update(T *aarray)
Definition: jit-typeinfo.h:94
std::vector< jit_function > m_identities
Definition: jit-typeinfo.h:928
jit_type * m_scalar_ptr
Definition: jit-typeinfo.h:596
static jit_type * get_complex(void)
Definition: jit-typeinfo.h:561
llvm::StructType * m_matrix_t
Definition: jit-typeinfo.h:582
octave_idx_type * m_dimensions
Definition: jit-typeinfo.h:109
static bool s_in_construction
Definition: jit-typeinfo.h:518
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:141
jit_type * m_parent
Definition: jit-typeinfo.h:210
llvm::Type * m_index_t
Definition: jit-typeinfo.h:577
llvm::GlobalVariable * m_lerror_state
Definition: jit-typeinfo.h:900
static llvm::Value * pack_complex(llvm::IRBuilderD &bld, llvm::Value *cplx)
Definition: jit-typeinfo.h:743
jit_range(const Range &from)
Definition: jit-typeinfo.h:54
llvm::Type * m_complex_t
Definition: jit-typeinfo.h:576
ColumnVector real(const ComplexColumnVector &a)
Definition: dColVector.cc:135
jit_operation m_for_init_fn
Definition: jit-typeinfo.h:913
std::vector< Array< jit_function > > m_overloads
Definition: jit-typeinfo.h:436
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
Definition: utils.cc:888
nd group nd example For each display the value
Definition: sysdep.cc:866
jit_index_operation(const jit_typeinfo &ti, const std::string &name)
Definition: jit-typeinfo.h:447
std::string m_name
Definition: jit-typeinfo.h:209
jit_operation m_grab_fn
Definition: jit-typeinfo.h:909
jit_operation m_end_fn
Definition: jit-typeinfo.h:919
octave::stream os
Definition: file-io.cc:627
void mark_pointer_arg(jit_convention::type cc)
Definition: jit-typeinfo.h:184
const std::string & name(void) const
Definition: jit-typeinfo.h:150
llvm::GlobalVariable * m_loctave_interrupt_state
Definition: jit-typeinfo.h:901
jit_type * do_get_intN(size_t nbits) const
static const jit_operation & create_undef(void)
Definition: jit-typeinfo.h:733
const jit_typeinfo & m_typeinfo
Definition: jit-typeinfo.h:462
jit_array(T &from)
Definition: jit-typeinfo.h:81
const jit_module * m_module
Definition: jit-typeinfo.h:338
std::vector< jit_operation > m_binary_ops
Definition: jit-typeinfo.h:907