Mercurial > octave-nkf
annotate src/jit-typeinfo.h @ 15068:f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
* src/jit-typeinfo.cc (make_indices, octave_jit_paren_scalar_subsasgn,
jit_typeinfo::gen_subsasgn): New function.
(octave_jit_paren_scalar): Use make_indices.
(jit_typeinfo::jit_typeinfo): Call gen_subsasgn.
* src/pt-jit.h (jit_typeinfo::gen_subsasgn): New declaration.
* src/pt-jit.cc (jit_convert::resolve): Add extra_arg argument.
(jit_convert::do_assign): Pass rhs to resolve.
* src/pt-jit.h (jit_convert::resolve): Change function signature.
author | Max Brister <max@2bass.com> |
---|---|
date | Tue, 31 Jul 2012 15:40:52 -0500 |
parents | df4538e3b50b |
children | fe4752f772e2 |
rev | line source |
---|---|
15016 | 1 /* |
2 | |
3 Copyright (C) 2012 Max Brister <max@2bass.com> | |
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 the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 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 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
23 #if !defined (octave_jit_typeinfo_h) | |
24 #define octave_jit_typeinfo_h 1 | |
25 | |
26 #ifdef HAVE_LLVM | |
27 | |
28 #include <map> | |
29 #include <vector> | |
30 | |
31 #include "Range.h" | |
32 #include "jit-util.h" | |
33 | |
34 // Defines the type system used by jit and a singleton class, jit_typeinfo, to | |
35 // manage the types. | |
36 // | |
37 // FIXME: | |
38 // Operations are defined and implemented in jit_typeinfo. Eventually they | |
39 // should be moved elsewhere. (just like with octave_typeinfo) | |
40 | |
41 // jit_range is compatable with the llvm range structure | |
42 struct | |
43 jit_range | |
44 { | |
45 jit_range (const Range& from) : base (from.base ()), limit (from.limit ()), | |
46 inc (from.inc ()), nelem (from.nelem ()) | |
47 {} | |
48 | |
49 operator Range () const | |
50 { | |
51 return Range (base, limit, inc); | |
52 } | |
53 | |
54 bool all_elements_are_ints () const; | |
55 | |
56 double base; | |
57 double limit; | |
58 double inc; | |
59 octave_idx_type nelem; | |
60 }; | |
61 | |
62 std::ostream& operator<< (std::ostream& os, const jit_range& rng); | |
63 | |
64 // jit_array is compatable with the llvm array/matrix structures | |
65 template <typename T, typename U> | |
66 struct | |
67 jit_array | |
68 { | |
69 jit_array (T& from) : array (new T (from)) | |
70 { | |
71 update (); | |
72 } | |
73 | |
74 void update (void) | |
75 { | |
76 ref_count = array->jit_ref_count (); | |
77 slice_data = array->jit_slice_data () - 1; | |
78 slice_len = array->capacity (); | |
79 dimensions = array->jit_dimensions (); | |
80 } | |
81 | |
82 void update (T *aarray) | |
83 { | |
84 array = aarray; | |
85 update (); | |
86 } | |
87 | |
88 operator T () const | |
89 { | |
90 return *array; | |
91 } | |
92 | |
93 int *ref_count; | |
94 | |
95 U *slice_data; | |
96 octave_idx_type slice_len; | |
97 octave_idx_type *dimensions; | |
98 | |
99 T *array; | |
100 }; | |
101 | |
102 typedef jit_array<NDArray, double> jit_matrix; | |
103 | |
104 std::ostream& operator<< (std::ostream& os, const jit_matrix& mat); | |
105 | |
106 // calling convention | |
107 namespace | |
108 jit_convention | |
109 { | |
110 enum | |
111 type | |
112 { | |
113 // internal to jit | |
114 internal, | |
115 | |
116 // an external C call | |
117 external, | |
118 | |
119 length | |
120 }; | |
121 } | |
122 | |
123 // Used to keep track of estimated (infered) types during JIT. This is a | |
124 // hierarchical type system which includes both concrete and abstract types. | |
125 // | |
126 // The types form a lattice. Currently we only allow for one parent type, but | |
127 // eventually we may allow for multiple predecessors. | |
128 class | |
129 jit_type | |
130 { | |
131 public: | |
132 typedef llvm::Value *(*convert_fn) (llvm::IRBuilderD&, llvm::Value *); | |
133 | |
134 jit_type (const std::string& aname, jit_type *aparent, llvm::Type *allvm_type, | |
135 int aid); | |
136 | |
137 // a user readable type name | |
138 const std::string& name (void) const { return mname; } | |
139 | |
140 // a unique id for the type | |
141 int type_id (void) const { return mid; } | |
142 | |
143 // An abstract base type, may be null | |
144 jit_type *parent (void) const { return mparent; } | |
145 | |
146 // convert to an llvm type | |
147 llvm::Type *to_llvm (void) const { return llvm_type; } | |
148 | |
149 // how this type gets passed as a function argument | |
150 llvm::Type *to_llvm_arg (void) const; | |
151 | |
152 size_t depth (void) const { return mdepth; } | |
153 | |
154 // -------------------- Calling Convention information -------------------- | |
155 | |
156 // A function declared like: mytype foo (int arg0, int arg1); | |
157 // Will be converted to: void foo (mytype *retval, int arg0, int arg1) | |
158 // if mytype is sret. The caller is responsible for allocating space for | |
159 // retval. (on the stack) | |
160 bool sret (jit_convention::type cc) const { return msret[cc]; } | |
161 | |
162 void mark_sret (jit_convention::type cc = jit_convention::external) | |
163 { msret[cc] = true; } | |
164 | |
165 // A function like: void foo (mytype arg0) | |
166 // Will be converted to: void foo (mytype *arg0) | |
167 // Basically just pass by reference. | |
168 bool pointer_arg (jit_convention::type cc) const { return mpointer_arg[cc]; } | |
169 | |
170 void mark_pointer_arg (jit_convention::type cc = jit_convention::external) | |
171 { mpointer_arg[cc] = true; } | |
172 | |
173 // Convert into an equivalent form before calling. For example, complex is | |
174 // represented as two values llvm vector, but we need to pass it as a two | |
175 // valued llvm structure to C functions. | |
176 convert_fn pack (jit_convention::type cc) { return mpack[cc]; } | |
177 | |
178 void set_pack (jit_convention::type cc, convert_fn fn) { mpack[cc] = fn; } | |
179 | |
180 // The inverse operation of pack. | |
181 convert_fn unpack (jit_convention::type cc) { return munpack[cc]; } | |
182 | |
183 void set_unpack (jit_convention::type cc, convert_fn fn) | |
184 { munpack[cc] = fn; } | |
185 | |
186 // The resulting type after pack is called. | |
187 llvm::Type *packed_type (jit_convention::type cc) | |
188 { return mpacked_type[cc]; } | |
189 | |
190 void set_packed_type (jit_convention::type cc, llvm::Type *ty) | |
191 { mpacked_type[cc] = ty; } | |
192 private: | |
193 std::string mname; | |
194 jit_type *mparent; | |
195 llvm::Type *llvm_type; | |
196 int mid; | |
197 size_t mdepth; | |
198 | |
199 bool msret[jit_convention::length]; | |
200 bool mpointer_arg[jit_convention::length]; | |
201 | |
202 convert_fn mpack[jit_convention::length]; | |
203 convert_fn munpack[jit_convention::length]; | |
204 | |
205 llvm::Type *mpacked_type[jit_convention::length]; | |
206 }; | |
207 | |
208 // seperate print function to allow easy printing if type is null | |
209 std::ostream& jit_print (std::ostream& os, jit_type *atype); | |
210 | |
211 class jit_value; | |
212 | |
213 // An abstraction for calling llvm functions with jit_values. Deals with calling | |
214 // convention details. | |
215 class | |
216 jit_function | |
217 { | |
218 friend std::ostream& operator<< (std::ostream& os, const jit_function& fn); | |
219 public: | |
220 // create a function in an invalid state | |
221 jit_function (); | |
222 | |
223 jit_function (llvm::Module *amodule, jit_convention::type acall_conv, | |
224 const llvm::Twine& aname, jit_type *aresult, | |
225 const std::vector<jit_type *>& aargs); | |
226 | |
227 // Use an existing function, but change the argument types. The new argument | |
228 // types must behave the same for the current calling convention. | |
229 jit_function (const jit_function& fn, jit_type *aresult, | |
230 const std::vector<jit_type *>& aargs); | |
231 | |
232 jit_function (const jit_function& fn); | |
233 | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
234 template <typename T> |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
235 void add_mapping (llvm::ExecutionEngine *engine, T fn) |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
236 { |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
237 do_add_mapping (engine, reinterpret_cast<void *> (fn)); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
238 } |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
239 |
15016 | 240 bool valid (void) const { return llvm_function; } |
241 | |
242 std::string name (void) const; | |
243 | |
244 llvm::BasicBlock *new_block (const std::string& aname = "body", | |
245 llvm::BasicBlock *insert_before = 0); | |
246 | |
247 llvm::Value *call (llvm::IRBuilderD& builder, | |
248 const std::vector<jit_value *>& in_args) const; | |
249 | |
250 llvm::Value *call (llvm::IRBuilderD& builder, | |
251 const std::vector<llvm::Value *>& in_args | |
252 = std::vector<llvm::Value *> ()) const; | |
253 | |
254 #define JIT_PARAM_ARGS llvm::IRBuilderD& builder, | |
255 #define JIT_PARAMS builder, | |
256 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, llvm::Value *, const, N) | |
257 | |
258 JIT_CALL (1) | |
259 JIT_CALL (2) | |
260 JIT_CALL (3) | |
261 JIT_CALL (4) | |
262 JIT_CALL (5) | |
263 | |
264 #undef JIT_CALL | |
265 | |
266 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, jit_value *, const, N) | |
267 | |
268 JIT_CALL (1); | |
269 JIT_CALL (2); | |
270 | |
271 #undef JIT_CALL | |
272 #undef JIT_PARAMS | |
273 #undef JIT_PARAM_ARGS | |
274 | |
275 llvm::Value *argument (llvm::IRBuilderD& builder, size_t idx) const; | |
276 | |
277 void do_return (llvm::IRBuilderD& builder, llvm::Value *rval = 0); | |
278 | |
279 llvm::Function *to_llvm (void) const { return llvm_function; } | |
280 | |
281 // If true, then the return value is passed as a pointer in the first argument | |
282 bool sret (void) const { return mresult && mresult->sret (call_conv); } | |
283 | |
284 bool can_error (void) const { return mcan_error; } | |
285 | |
286 void mark_can_error (void) { mcan_error = true; } | |
287 | |
288 jit_type *result (void) const { return mresult; } | |
289 | |
290 jit_type *argument_type (size_t idx) const | |
291 { | |
292 assert (idx < args.size ()); | |
293 return args[idx]; | |
294 } | |
295 | |
296 const std::vector<jit_type *>& arguments (void) const { return args; } | |
297 private: | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
298 void do_add_mapping (llvm::ExecutionEngine *engine, void *fn); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
299 |
15016 | 300 llvm::Module *module; |
301 llvm::Function *llvm_function; | |
302 jit_type *mresult; | |
303 std::vector<jit_type *> args; | |
304 jit_convention::type call_conv; | |
305 bool mcan_error; | |
306 }; | |
307 | |
308 std::ostream& operator<< (std::ostream& os, const jit_function& fn); | |
309 | |
310 | |
311 // Keeps track of information about how to implement operations (+, -, *, ect) | |
312 // and their resulting types. | |
313 class | |
314 jit_operation | |
315 { | |
316 public: | |
317 void add_overload (const jit_function& func) | |
318 { | |
319 add_overload (func, func.arguments ()); | |
320 } | |
321 | |
322 void add_overload (const jit_function& func, | |
323 const std::vector<jit_type*>& args); | |
324 | |
325 const jit_function& overload (const std::vector<jit_type *>& types) const; | |
326 | |
327 jit_type *result (const std::vector<jit_type *>& types) const | |
328 { | |
329 const jit_function& temp = overload (types); | |
330 return temp.result (); | |
331 } | |
332 | |
333 #define JIT_PARAMS | |
334 #define JIT_PARAM_ARGS | |
335 #define JIT_OVERLOAD(N) \ | |
336 JIT_EXPAND (const jit_function&, overload, jit_type *, const, N) \ | |
337 JIT_EXPAND (jit_type *, result, jit_type *, const, N) | |
338 | |
339 JIT_OVERLOAD (1); | |
340 JIT_OVERLOAD (2); | |
341 JIT_OVERLOAD (3); | |
342 | |
343 #undef JIT_PARAMS | |
344 #undef JIT_PARAM_ARGS | |
345 | |
346 const std::string& name (void) const { return mname; } | |
347 | |
348 void stash_name (const std::string& aname) { mname = aname; } | |
349 private: | |
350 Array<octave_idx_type> to_idx (const std::vector<jit_type*>& types) const; | |
351 | |
352 std::vector<Array<jit_function> > overloads; | |
353 | |
354 std::string mname; | |
355 }; | |
356 | |
357 // A singleton class which handles the construction of jit_types and | |
358 // jit_operations. | |
359 class | |
360 jit_typeinfo | |
361 { | |
362 public: | |
363 static void initialize (llvm::Module *m, llvm::ExecutionEngine *e); | |
364 | |
365 static jit_type *join (jit_type *lhs, jit_type *rhs) | |
366 { | |
367 return instance->do_join (lhs, rhs); | |
368 } | |
369 | |
370 static jit_type *get_any (void) { return instance->any; } | |
371 | |
372 static jit_type *get_matrix (void) { return instance->matrix; } | |
373 | |
374 static jit_type *get_scalar (void) { return instance->scalar; } | |
375 | |
376 static llvm::Type *get_scalar_llvm (void) | |
377 { return instance->scalar->to_llvm (); } | |
378 | |
379 static jit_type *get_range (void) { return instance->range; } | |
380 | |
381 static jit_type *get_string (void) { return instance->string; } | |
382 | |
383 static jit_type *get_bool (void) { return instance->boolean; } | |
384 | |
385 static jit_type *get_index (void) { return instance->index; } | |
386 | |
387 static llvm::Type *get_index_llvm (void) | |
388 { return instance->index->to_llvm (); } | |
389 | |
390 static jit_type *get_complex (void) { return instance->complex; } | |
391 | |
392 // Get the jit_type of an octave_value | |
393 static jit_type *type_of (const octave_value& ov) | |
394 { | |
395 return instance->do_type_of (ov); | |
396 } | |
397 | |
398 static const jit_operation& binary_op (int op) | |
399 { | |
400 return instance->do_binary_op (op); | |
401 } | |
402 | |
403 static const jit_operation& grab (void) { return instance->grab_fn; } | |
404 | |
405 static const jit_function& get_grab (jit_type *type) | |
406 { | |
407 return instance->grab_fn.overload (type); | |
408 } | |
409 | |
410 static const jit_operation& release (void) | |
411 { | |
412 return instance->release_fn; | |
413 } | |
414 | |
415 static const jit_function& get_release (jit_type *type) | |
416 { | |
417 return instance->release_fn.overload (type); | |
418 } | |
419 | |
420 static const jit_operation& print_value (void) | |
421 { | |
422 return instance->print_fn; | |
423 } | |
424 | |
425 static const jit_operation& for_init (void) | |
426 { | |
427 return instance->for_init_fn; | |
428 } | |
429 | |
430 static const jit_operation& for_check (void) | |
431 { | |
432 return instance->for_check_fn; | |
433 } | |
434 | |
435 static const jit_operation& for_index (void) | |
436 { | |
437 return instance->for_index_fn; | |
438 } | |
439 | |
440 static const jit_operation& make_range (void) | |
441 { | |
442 return instance->make_range_fn; | |
443 } | |
444 | |
445 static const jit_operation& paren_subsref (void) | |
446 { | |
447 return instance->paren_subsref_fn; | |
448 } | |
449 | |
450 static const jit_operation& paren_subsasgn (void) | |
451 { | |
452 return instance->paren_subsasgn_fn; | |
453 } | |
454 | |
455 static const jit_operation& logically_true (void) | |
456 { | |
457 return instance->logically_true_fn; | |
458 } | |
459 | |
460 static const jit_operation& cast (jit_type *result) | |
461 { | |
462 return instance->do_cast (result); | |
463 } | |
464 | |
465 static const jit_function& cast (jit_type *to, jit_type *from) | |
466 { | |
467 return instance->do_cast (to, from); | |
468 } | |
469 | |
470 static llvm::Value *insert_error_check (llvm::IRBuilderD& bld) | |
471 { | |
472 return instance->do_insert_error_check (bld); | |
473 } | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
474 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
475 static const jit_operation& end (void) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
476 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
477 return instance->end_fn; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
478 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
479 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
480 static const jit_function& end (jit_type *ty) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
481 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
482 return instance->end_fn.overload (ty); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
483 } |
15016 | 484 private: |
485 jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e); | |
486 | |
487 // FIXME: Do these methods really need to be in jit_typeinfo? | |
488 jit_type *do_join (jit_type *lhs, jit_type *rhs) | |
489 { | |
490 // empty case | |
491 if (! lhs) | |
492 return rhs; | |
493 | |
494 if (! rhs) | |
495 return lhs; | |
496 | |
497 // check for a shared parent | |
498 while (lhs != rhs) | |
499 { | |
500 if (lhs->depth () > rhs->depth ()) | |
501 lhs = lhs->parent (); | |
502 else if (lhs->depth () < rhs->depth ()) | |
503 rhs = rhs->parent (); | |
504 else | |
505 { | |
506 // we MUST have depth > 0 as any is the base type of everything | |
507 do | |
508 { | |
509 lhs = lhs->parent (); | |
510 rhs = rhs->parent (); | |
511 } | |
512 while (lhs != rhs); | |
513 } | |
514 } | |
515 | |
516 return lhs; | |
517 } | |
518 | |
519 jit_type *do_difference (jit_type *lhs, jit_type *) | |
520 { | |
521 // FIXME: Maybe we can do something smarter? | |
522 return lhs; | |
523 } | |
524 | |
525 jit_type *do_type_of (const octave_value &ov) const; | |
526 | |
527 const jit_operation& do_binary_op (int op) const | |
528 { | |
529 assert (static_cast<size_t>(op) < binary_ops.size ()); | |
530 return binary_ops[op]; | |
531 } | |
532 | |
533 const jit_operation& do_cast (jit_type *to) | |
534 { | |
535 static jit_operation null_function; | |
536 if (! to) | |
537 return null_function; | |
538 | |
539 size_t id = to->type_id (); | |
540 if (id >= casts.size ()) | |
541 return null_function; | |
542 return casts[id]; | |
543 } | |
544 | |
545 const jit_function& do_cast (jit_type *to, jit_type *from) | |
546 { | |
547 return do_cast (to).overload (from); | |
548 } | |
549 | |
550 jit_type *new_type (const std::string& name, jit_type *parent, | |
551 llvm::Type *llvm_type); | |
552 | |
553 | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
554 void add_print (jit_type *ty, void *fptr); |
15016 | 555 |
556 void add_binary_op (jit_type *ty, int op, int llvm_op); | |
557 | |
558 void add_binary_icmp (jit_type *ty, int op, int llvm_op); | |
559 | |
560 void add_binary_fcmp (jit_type *ty, int op, int llvm_op); | |
561 | |
562 jit_function create_function (jit_convention::type cc, | |
563 const llvm::Twine& name, jit_type *ret, | |
564 const std::vector<jit_type *>& args | |
565 = std::vector<jit_type *> ()); | |
566 | |
567 #define JIT_PARAM_ARGS jit_convention::type cc, const llvm::Twine& name, \ | |
568 jit_type *ret, | |
569 #define JIT_PARAMS cc, name, ret, | |
570 #define CREATE_FUNCTION(N) JIT_EXPAND(jit_function, create_function, \ | |
571 jit_type *, /* empty */, N) | |
572 | |
573 CREATE_FUNCTION(1); | |
574 CREATE_FUNCTION(2); | |
575 CREATE_FUNCTION(3); | |
576 CREATE_FUNCTION(4); | |
577 | |
578 #undef JIT_PARAM_ARGS | |
579 #undef JIT_PARAMS | |
580 #undef CREATE_FUNCTION | |
581 | |
582 jit_function create_identity (jit_type *type); | |
583 | |
584 llvm::Value *do_insert_error_check (llvm::IRBuilderD& bld); | |
585 | |
586 void add_builtin (const std::string& name); | |
587 | |
588 void register_intrinsic (const std::string& name, size_t id, | |
589 jit_type *result, jit_type *arg0) | |
590 { | |
591 std::vector<jit_type *> args (1, arg0); | |
592 register_intrinsic (name, id, result, args); | |
593 } | |
594 | |
595 void register_intrinsic (const std::string& name, size_t id, jit_type *result, | |
596 const std::vector<jit_type *>& args); | |
597 | |
598 void register_generic (const std::string& name, jit_type *result, | |
599 jit_type *arg0) | |
600 { | |
601 std::vector<jit_type *> args (1, arg0); | |
602 register_generic (name, result, args); | |
603 } | |
604 | |
605 void register_generic (const std::string& name, jit_type *result, | |
606 const std::vector<jit_type *>& args); | |
607 | |
608 octave_builtin *find_builtin (const std::string& name); | |
609 | |
610 jit_function mirror_binary (const jit_function& fn); | |
611 | |
612 llvm::Function *wrap_complex (llvm::Function *wrap); | |
613 | |
614 static llvm::Value *pack_complex (llvm::IRBuilderD& bld, | |
615 llvm::Value *cplx); | |
616 | |
617 static llvm::Value *unpack_complex (llvm::IRBuilderD& bld, | |
618 llvm::Value *result); | |
619 | |
620 llvm::Value *complex_real (llvm::Value *cx); | |
621 | |
622 llvm::Value *complex_real (llvm::Value *cx, llvm::Value *real); | |
623 | |
624 llvm::Value *complex_imag (llvm::Value *cx); | |
625 | |
626 llvm::Value *complex_imag (llvm::Value *cx, llvm::Value *imag); | |
627 | |
628 llvm::Value *complex_new (llvm::Value *real, llvm::Value *imag); | |
629 | |
630 void create_int (size_t nbits); | |
631 | |
632 jit_type *intN (size_t nbits) const; | |
633 | |
15067 | 634 void gen_subsref (const jit_function& paren_scalar, size_t n); |
635 | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
636 void gen_subsasgn (const jit_function& paren_scalar, size_t n); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
637 |
15016 | 638 static jit_typeinfo *instance; |
639 | |
640 llvm::Module *module; | |
641 llvm::ExecutionEngine *engine; | |
642 int next_id; | |
643 | |
644 llvm::GlobalVariable *lerror_state; | |
645 | |
646 std::vector<jit_type*> id_to_type; | |
647 jit_type *any; | |
648 jit_type *matrix; | |
649 jit_type *scalar; | |
650 jit_type *range; | |
651 jit_type *string; | |
652 jit_type *boolean; | |
653 jit_type *index; | |
654 jit_type *complex; | |
655 jit_type *unknown_function; | |
656 std::map<size_t, jit_type *> ints; | |
657 std::map<std::string, jit_type *> builtins; | |
658 | |
659 llvm::StructType *complex_ret; | |
660 | |
661 std::vector<jit_operation> binary_ops; | |
662 jit_operation grab_fn; | |
663 jit_operation release_fn; | |
664 jit_operation print_fn; | |
665 jit_operation for_init_fn; | |
666 jit_operation for_check_fn; | |
667 jit_operation for_index_fn; | |
668 jit_operation logically_true_fn; | |
669 jit_operation make_range_fn; | |
670 jit_operation paren_subsref_fn; | |
671 jit_operation paren_subsasgn_fn; | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
672 jit_operation end_fn; |
15016 | 673 |
674 // type id -> cast function TO that type | |
675 std::vector<jit_operation> casts; | |
676 | |
677 // type id -> identity function | |
678 std::vector<jit_function> identities; | |
679 | |
680 llvm::IRBuilderD& builder; | |
681 }; | |
682 | |
683 #endif | |
684 #endif |