Mercurial > octave-nkf
annotate libinterp/interp-core/jit-typeinfo.h @ 15893:1f076c40c133
Do not use vectorized llvm commands for complex numbers
* jit-typeinfo.cc (octave_jit_complex_mul): New function.
(jit_typeinfo::jit_typeinfo): Implement complex numbers using an llvm array and
use create_internal/create_external.
(jit_typeinfo::complex_real, jit_typeinfo::complex_imag,
jit_typeinfo::pack_complex, jit_typeinfo::unpack_complex): Implement complex
numbers using an llvm array.
(jit_typeinfo::add_binary_op, jit_typeinfo::add_binary_icmp,
jit_typeinfo::add_binary_fcmp, jit_typeinfo::create_identity,
jit_typeinfo::register_intrinsic, jit_typeinfo::register_generic,
jit_typeinfo::mirror_binary): Use create_internal/create_external.
(jit_typeinfo::type_of): Correctly determine complex type.
* jit-typeinfo.h (jit_typeinfo::create_complex,
jit_typeinfo::create_internal, jit_typeinfo::create_external): New function.
* pt-jit.cc (jit_convert_llvm::visit): Create an array for complex constants.
author | Max Brister <max@2bass.com> |
---|---|
date | Thu, 03 Jan 2013 12:35:10 -0700 |
parents | 44272909d926 |
children | e2de3c8882be |
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 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
69 jit_array () : array (0) {} |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
70 |
15016 | 71 jit_array (T& from) : array (new T (from)) |
72 { | |
73 update (); | |
74 } | |
75 | |
76 void update (void) | |
77 { | |
78 ref_count = array->jit_ref_count (); | |
79 slice_data = array->jit_slice_data () - 1; | |
80 slice_len = array->capacity (); | |
81 dimensions = array->jit_dimensions (); | |
82 } | |
83 | |
84 void update (T *aarray) | |
85 { | |
86 array = aarray; | |
87 update (); | |
88 } | |
89 | |
90 operator T () const | |
91 { | |
92 return *array; | |
93 } | |
94 | |
95 int *ref_count; | |
96 | |
97 U *slice_data; | |
98 octave_idx_type slice_len; | |
99 octave_idx_type *dimensions; | |
100 | |
101 T *array; | |
102 }; | |
103 | |
104 typedef jit_array<NDArray, double> jit_matrix; | |
105 | |
106 std::ostream& operator<< (std::ostream& os, const jit_matrix& mat); | |
107 | |
108 // calling convention | |
109 namespace | |
110 jit_convention | |
111 { | |
112 enum | |
113 type | |
114 { | |
115 // internal to jit | |
116 internal, | |
117 | |
118 // an external C call | |
119 external, | |
120 | |
121 length | |
122 }; | |
123 } | |
124 | |
125 // Used to keep track of estimated (infered) types during JIT. This is a | |
126 // hierarchical type system which includes both concrete and abstract types. | |
127 // | |
128 // The types form a lattice. Currently we only allow for one parent type, but | |
129 // eventually we may allow for multiple predecessors. | |
130 class | |
131 jit_type | |
132 { | |
133 public: | |
134 typedef llvm::Value *(*convert_fn) (llvm::IRBuilderD&, llvm::Value *); | |
135 | |
136 jit_type (const std::string& aname, jit_type *aparent, llvm::Type *allvm_type, | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
137 bool askip_paren, int aid); |
15016 | 138 |
139 // a user readable type name | |
140 const std::string& name (void) const { return mname; } | |
141 | |
142 // a unique id for the type | |
143 int type_id (void) const { return mid; } | |
144 | |
145 // An abstract base type, may be null | |
146 jit_type *parent (void) const { return mparent; } | |
147 | |
148 // convert to an llvm type | |
149 llvm::Type *to_llvm (void) const { return llvm_type; } | |
150 | |
151 // how this type gets passed as a function argument | |
152 llvm::Type *to_llvm_arg (void) const; | |
153 | |
154 size_t depth (void) const { return mdepth; } | |
155 | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
156 bool skip_paren (void) const { return mskip_paren; } |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
157 |
15016 | 158 // -------------------- Calling Convention information -------------------- |
159 | |
160 // A function declared like: mytype foo (int arg0, int arg1); | |
161 // Will be converted to: void foo (mytype *retval, int arg0, int arg1) | |
162 // if mytype is sret. The caller is responsible for allocating space for | |
163 // retval. (on the stack) | |
164 bool sret (jit_convention::type cc) const { return msret[cc]; } | |
165 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
166 void mark_sret (jit_convention::type cc) |
15016 | 167 { msret[cc] = true; } |
168 | |
169 // A function like: void foo (mytype arg0) | |
170 // Will be converted to: void foo (mytype *arg0) | |
171 // Basically just pass by reference. | |
172 bool pointer_arg (jit_convention::type cc) const { return mpointer_arg[cc]; } | |
173 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
174 void mark_pointer_arg (jit_convention::type cc) |
15016 | 175 { mpointer_arg[cc] = true; } |
176 | |
177 // Convert into an equivalent form before calling. For example, complex is | |
178 // represented as two values llvm vector, but we need to pass it as a two | |
179 // valued llvm structure to C functions. | |
180 convert_fn pack (jit_convention::type cc) { return mpack[cc]; } | |
181 | |
182 void set_pack (jit_convention::type cc, convert_fn fn) { mpack[cc] = fn; } | |
183 | |
184 // The inverse operation of pack. | |
185 convert_fn unpack (jit_convention::type cc) { return munpack[cc]; } | |
186 | |
187 void set_unpack (jit_convention::type cc, convert_fn fn) | |
188 { munpack[cc] = fn; } | |
189 | |
190 // The resulting type after pack is called. | |
191 llvm::Type *packed_type (jit_convention::type cc) | |
192 { return mpacked_type[cc]; } | |
193 | |
194 void set_packed_type (jit_convention::type cc, llvm::Type *ty) | |
195 { mpacked_type[cc] = ty; } | |
196 private: | |
197 std::string mname; | |
198 jit_type *mparent; | |
199 llvm::Type *llvm_type; | |
200 int mid; | |
201 size_t mdepth; | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
202 bool mskip_paren; |
15016 | 203 |
204 bool msret[jit_convention::length]; | |
205 bool mpointer_arg[jit_convention::length]; | |
206 | |
207 convert_fn mpack[jit_convention::length]; | |
208 convert_fn munpack[jit_convention::length]; | |
209 | |
210 llvm::Type *mpacked_type[jit_convention::length]; | |
211 }; | |
212 | |
213 // seperate print function to allow easy printing if type is null | |
214 std::ostream& jit_print (std::ostream& os, jit_type *atype); | |
215 | |
216 class jit_value; | |
217 | |
218 // An abstraction for calling llvm functions with jit_values. Deals with calling | |
219 // convention details. | |
220 class | |
221 jit_function | |
222 { | |
223 friend std::ostream& operator<< (std::ostream& os, const jit_function& fn); | |
224 public: | |
225 // create a function in an invalid state | |
226 jit_function (); | |
227 | |
228 jit_function (llvm::Module *amodule, jit_convention::type acall_conv, | |
229 const llvm::Twine& aname, jit_type *aresult, | |
230 const std::vector<jit_type *>& aargs); | |
231 | |
232 // Use an existing function, but change the argument types. The new argument | |
233 // types must behave the same for the current calling convention. | |
234 jit_function (const jit_function& fn, jit_type *aresult, | |
235 const std::vector<jit_type *>& aargs); | |
236 | |
237 jit_function (const jit_function& fn); | |
238 | |
15385
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
239 // erase the interal LLVM function (if it exists). Will become invalid. |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
240 void erase (void); |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
241 |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
242 template <typename T> |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
243 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
|
244 { |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
245 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
|
246 } |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
247 |
15016 | 248 bool valid (void) const { return llvm_function; } |
249 | |
250 std::string name (void) const; | |
251 | |
252 llvm::BasicBlock *new_block (const std::string& aname = "body", | |
253 llvm::BasicBlock *insert_before = 0); | |
254 | |
255 llvm::Value *call (llvm::IRBuilderD& builder, | |
256 const std::vector<jit_value *>& in_args) const; | |
257 | |
258 llvm::Value *call (llvm::IRBuilderD& builder, | |
259 const std::vector<llvm::Value *>& in_args | |
260 = std::vector<llvm::Value *> ()) const; | |
261 | |
262 #define JIT_PARAM_ARGS llvm::IRBuilderD& builder, | |
263 #define JIT_PARAMS builder, | |
264 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, llvm::Value *, const, N) | |
265 | |
266 JIT_CALL (1) | |
267 JIT_CALL (2) | |
268 JIT_CALL (3) | |
269 JIT_CALL (4) | |
270 JIT_CALL (5) | |
271 | |
272 #undef JIT_CALL | |
273 | |
274 #define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, jit_value *, const, N) | |
275 | |
276 JIT_CALL (1); | |
277 JIT_CALL (2); | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
278 JIT_CALL (3); |
15016 | 279 |
280 #undef JIT_CALL | |
281 #undef JIT_PARAMS | |
282 #undef JIT_PARAM_ARGS | |
283 | |
284 llvm::Value *argument (llvm::IRBuilderD& builder, size_t idx) const; | |
285 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
286 void do_return (llvm::IRBuilderD& builder, llvm::Value *rval = 0, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
287 bool verify = true); |
15016 | 288 |
289 llvm::Function *to_llvm (void) const { return llvm_function; } | |
290 | |
291 // If true, then the return value is passed as a pointer in the first argument | |
292 bool sret (void) const { return mresult && mresult->sret (call_conv); } | |
293 | |
294 bool can_error (void) const { return mcan_error; } | |
295 | |
296 void mark_can_error (void) { mcan_error = true; } | |
297 | |
298 jit_type *result (void) const { return mresult; } | |
299 | |
300 jit_type *argument_type (size_t idx) const | |
301 { | |
302 assert (idx < args.size ()); | |
303 return args[idx]; | |
304 } | |
305 | |
306 const std::vector<jit_type *>& arguments (void) const { return args; } | |
307 private: | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
308 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
|
309 |
15016 | 310 llvm::Module *module; |
311 llvm::Function *llvm_function; | |
312 jit_type *mresult; | |
313 std::vector<jit_type *> args; | |
314 jit_convention::type call_conv; | |
315 bool mcan_error; | |
316 }; | |
317 | |
318 std::ostream& operator<< (std::ostream& os, const jit_function& fn); | |
319 | |
320 | |
321 // Keeps track of information about how to implement operations (+, -, *, ect) | |
322 // and their resulting types. | |
323 class | |
324 jit_operation | |
325 { | |
326 public: | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
327 // type signature vector |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
328 typedef std::vector<jit_type *> signature_vec; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
329 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
330 virtual ~jit_operation (void); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
331 |
15016 | 332 void add_overload (const jit_function& func) |
333 { | |
334 add_overload (func, func.arguments ()); | |
335 } | |
336 | |
337 void add_overload (const jit_function& func, | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
338 const signature_vec& args); |
15016 | 339 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
340 const jit_function& overload (const signature_vec& types) const; |
15016 | 341 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
342 jit_type *result (const signature_vec& types) const |
15016 | 343 { |
344 const jit_function& temp = overload (types); | |
345 return temp.result (); | |
346 } | |
347 | |
348 #define JIT_PARAMS | |
349 #define JIT_PARAM_ARGS | |
350 #define JIT_OVERLOAD(N) \ | |
351 JIT_EXPAND (const jit_function&, overload, jit_type *, const, N) \ | |
352 JIT_EXPAND (jit_type *, result, jit_type *, const, N) | |
353 | |
354 JIT_OVERLOAD (1); | |
355 JIT_OVERLOAD (2); | |
356 JIT_OVERLOAD (3); | |
357 | |
358 #undef JIT_PARAMS | |
359 #undef JIT_PARAM_ARGS | |
360 | |
361 const std::string& name (void) const { return mname; } | |
362 | |
363 void stash_name (const std::string& aname) { mname = aname; } | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
364 protected: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
365 virtual jit_function *generate (const signature_vec& types) const; |
15016 | 366 private: |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
367 Array<octave_idx_type> to_idx (const signature_vec& types) const; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
368 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
369 const jit_function& do_generate (const signature_vec& types) const; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
370 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
371 struct signature_cmp |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
372 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
373 bool operator() (const signature_vec *lhs, const signature_vec *rhs); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
374 }; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
375 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
376 typedef std::map<const signature_vec *, jit_function *, signature_cmp> |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
377 generated_map; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
378 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
379 mutable generated_map generated; |
15016 | 380 |
381 std::vector<Array<jit_function> > overloads; | |
382 | |
383 std::string mname; | |
384 }; | |
385 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
386 class |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
387 jit_index_operation : public jit_operation |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
388 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
389 public: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
390 jit_index_operation (void) : module (0), engine (0) {} |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
391 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
392 void initialize (llvm::Module *amodule, llvm::ExecutionEngine *aengine) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
393 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
394 module = amodule; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
395 engine = aengine; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
396 do_initialize (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
397 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
398 protected: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
399 virtual jit_function *generate (const signature_vec& types) const; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
400 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
401 virtual jit_function *generate_matrix (const signature_vec& types) const = 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
402 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
403 virtual void do_initialize (void) = 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
404 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
405 // helper functions |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
406 // [start_idx, end_idx). |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
407 llvm::Value *create_arg_array (llvm::IRBuilderD& builder, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
408 const jit_function &fn, size_t start_idx, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
409 size_t end_idx) const; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
410 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
411 llvm::Module *module; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
412 llvm::ExecutionEngine *engine; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
413 }; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
414 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
415 class |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
416 jit_paren_subsref : public jit_index_operation |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
417 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
418 protected: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
419 virtual jit_function *generate_matrix (const signature_vec& types) const; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
420 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
421 virtual void do_initialize (void); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
422 private: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
423 jit_function paren_scalar; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
424 }; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
425 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
426 class |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
427 jit_paren_subsasgn : public jit_index_operation |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
428 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
429 protected: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
430 jit_function *generate_matrix (const signature_vec& types) const; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
431 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
432 virtual void do_initialize (void); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
433 private: |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
434 jit_function paren_scalar; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
435 }; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
436 |
15016 | 437 // A singleton class which handles the construction of jit_types and |
438 // jit_operations. | |
439 class | |
440 jit_typeinfo | |
441 { | |
442 public: | |
443 static void initialize (llvm::Module *m, llvm::ExecutionEngine *e); | |
444 | |
445 static jit_type *join (jit_type *lhs, jit_type *rhs) | |
446 { | |
447 return instance->do_join (lhs, rhs); | |
448 } | |
449 | |
450 static jit_type *get_any (void) { return instance->any; } | |
451 | |
452 static jit_type *get_matrix (void) { return instance->matrix; } | |
453 | |
454 static jit_type *get_scalar (void) { return instance->scalar; } | |
455 | |
456 static llvm::Type *get_scalar_llvm (void) | |
457 { return instance->scalar->to_llvm (); } | |
458 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
459 static jit_type *get_scalar_ptr (void) { return instance->scalar_ptr; } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
460 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
461 static jit_type *get_any_ptr (void) { return instance->any_ptr; } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
462 |
15016 | 463 static jit_type *get_range (void) { return instance->range; } |
464 | |
465 static jit_type *get_string (void) { return instance->string; } | |
466 | |
467 static jit_type *get_bool (void) { return instance->boolean; } | |
468 | |
469 static jit_type *get_index (void) { return instance->index; } | |
470 | |
471 static llvm::Type *get_index_llvm (void) | |
472 { return instance->index->to_llvm (); } | |
473 | |
474 static jit_type *get_complex (void) { return instance->complex; } | |
475 | |
476 // Get the jit_type of an octave_value | |
477 static jit_type *type_of (const octave_value& ov) | |
478 { | |
479 return instance->do_type_of (ov); | |
480 } | |
481 | |
482 static const jit_operation& binary_op (int op) | |
483 { | |
484 return instance->do_binary_op (op); | |
485 } | |
486 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
487 static const jit_operation& unary_op (int op) |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
488 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
489 return instance->do_unary_op (op); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
490 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
491 |
15016 | 492 static const jit_operation& grab (void) { return instance->grab_fn; } |
493 | |
494 static const jit_function& get_grab (jit_type *type) | |
495 { | |
496 return instance->grab_fn.overload (type); | |
497 } | |
498 | |
499 static const jit_operation& release (void) | |
500 { | |
501 return instance->release_fn; | |
502 } | |
503 | |
504 static const jit_function& get_release (jit_type *type) | |
505 { | |
506 return instance->release_fn.overload (type); | |
507 } | |
508 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
509 static const jit_operation& destroy (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
510 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
511 return instance->destroy_fn; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
512 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
513 |
15016 | 514 static const jit_operation& print_value (void) |
515 { | |
516 return instance->print_fn; | |
517 } | |
518 | |
519 static const jit_operation& for_init (void) | |
520 { | |
521 return instance->for_init_fn; | |
522 } | |
523 | |
524 static const jit_operation& for_check (void) | |
525 { | |
526 return instance->for_check_fn; | |
527 } | |
528 | |
529 static const jit_operation& for_index (void) | |
530 { | |
531 return instance->for_index_fn; | |
532 } | |
533 | |
534 static const jit_operation& make_range (void) | |
535 { | |
536 return instance->make_range_fn; | |
537 } | |
538 | |
539 static const jit_operation& paren_subsref (void) | |
540 { | |
541 return instance->paren_subsref_fn; | |
542 } | |
543 | |
544 static const jit_operation& paren_subsasgn (void) | |
545 { | |
546 return instance->paren_subsasgn_fn; | |
547 } | |
548 | |
549 static const jit_operation& logically_true (void) | |
550 { | |
551 return instance->logically_true_fn; | |
552 } | |
553 | |
554 static const jit_operation& cast (jit_type *result) | |
555 { | |
556 return instance->do_cast (result); | |
557 } | |
558 | |
559 static const jit_function& cast (jit_type *to, jit_type *from) | |
560 { | |
561 return instance->do_cast (to, from); | |
562 } | |
563 | |
564 static llvm::Value *insert_error_check (llvm::IRBuilderD& bld) | |
565 { | |
566 return instance->do_insert_error_check (bld); | |
567 } | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
568 |
15603 | 569 static llvm::Value *insert_interrupt_check (llvm::IRBuilderD& bld) |
570 { | |
571 return instance->do_insert_interrupt_check (bld); | |
572 } | |
573 | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
574 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
|
575 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
576 return instance->end_fn; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
577 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
578 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
579 static const jit_function& end (jit_value *value, jit_value *index, |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
580 jit_value *count) |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
581 { |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
582 return instance->do_end (value, index, count); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
583 } |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
584 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
585 static const jit_operation& create_undef (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
586 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
587 return instance->create_undef_fn; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
588 } |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
589 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
590 static llvm::Value *create_complex (llvm::Value *real, llvm::Value *imag) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
591 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
592 return instance->complex_new (real, imag); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
593 } |
15016 | 594 private: |
595 jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e); | |
596 | |
597 // FIXME: Do these methods really need to be in jit_typeinfo? | |
598 jit_type *do_join (jit_type *lhs, jit_type *rhs) | |
599 { | |
600 // empty case | |
601 if (! lhs) | |
602 return rhs; | |
603 | |
604 if (! rhs) | |
605 return lhs; | |
606 | |
607 // check for a shared parent | |
608 while (lhs != rhs) | |
609 { | |
610 if (lhs->depth () > rhs->depth ()) | |
611 lhs = lhs->parent (); | |
612 else if (lhs->depth () < rhs->depth ()) | |
613 rhs = rhs->parent (); | |
614 else | |
615 { | |
616 // we MUST have depth > 0 as any is the base type of everything | |
617 do | |
618 { | |
619 lhs = lhs->parent (); | |
620 rhs = rhs->parent (); | |
621 } | |
622 while (lhs != rhs); | |
623 } | |
624 } | |
625 | |
626 return lhs; | |
627 } | |
628 | |
629 jit_type *do_difference (jit_type *lhs, jit_type *) | |
630 { | |
631 // FIXME: Maybe we can do something smarter? | |
632 return lhs; | |
633 } | |
634 | |
635 jit_type *do_type_of (const octave_value &ov) const; | |
636 | |
637 const jit_operation& do_binary_op (int op) const | |
638 { | |
639 assert (static_cast<size_t>(op) < binary_ops.size ()); | |
640 return binary_ops[op]; | |
641 } | |
642 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
643 const jit_operation& do_unary_op (int op) const |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
644 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
645 assert (static_cast<size_t> (op) < unary_ops.size ()); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
646 return unary_ops[op]; |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
647 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
648 |
15016 | 649 const jit_operation& do_cast (jit_type *to) |
650 { | |
651 static jit_operation null_function; | |
652 if (! to) | |
653 return null_function; | |
654 | |
655 size_t id = to->type_id (); | |
656 if (id >= casts.size ()) | |
657 return null_function; | |
658 return casts[id]; | |
659 } | |
660 | |
661 const jit_function& do_cast (jit_type *to, jit_type *from) | |
662 { | |
663 return do_cast (to).overload (from); | |
664 } | |
665 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
666 const jit_function& do_end (jit_value *value, jit_value *index, |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
667 jit_value *count); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
668 |
15016 | 669 jit_type *new_type (const std::string& name, jit_type *parent, |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
670 llvm::Type *llvm_type, bool skip_paren = false); |
15016 | 671 |
672 | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
673 void add_print (jit_type *ty, void *fptr); |
15016 | 674 |
675 void add_binary_op (jit_type *ty, int op, int llvm_op); | |
676 | |
677 void add_binary_icmp (jit_type *ty, int op, int llvm_op); | |
678 | |
679 void add_binary_fcmp (jit_type *ty, int op, int llvm_op); | |
680 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
681 // create a function with an external calling convention |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
682 // forces the function pointer to be specified |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
683 template <typename T> |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
684 jit_function create_external (llvm::ExecutionEngine *ee, T fn, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
685 const llvm::Twine& name, jit_type *ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
686 const std::vector<jit_type *>& args |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
687 = std::vector<jit_type *> ()) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
688 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
689 jit_function retval = create_function (jit_convention::external, name, ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
690 args); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
691 retval.add_mapping (ee, fn); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
692 return retval; |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
693 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
694 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
695 #define JIT_PARAM_ARGS llvm::ExecutionEngine *ee, T fn, \ |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
696 const llvm::Twine& name, jit_type *ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
697 #define JIT_PARAMS ee, fn, name, ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
698 #define CREATE_FUNCTION(N) JIT_EXPAND(template <typename T> jit_function, \ |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
699 create_external, \ |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
700 jit_type *, /* empty */, N) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
701 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
702 CREATE_FUNCTION(1); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
703 CREATE_FUNCTION(2); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
704 CREATE_FUNCTION(3); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
705 CREATE_FUNCTION(4); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
706 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
707 #undef JIT_PARAM_ARGS |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
708 #undef JIT_PARAMS |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
709 #undef CREATE_FUNCTION |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
710 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
711 // use create_external or create_internal directly |
15016 | 712 jit_function create_function (jit_convention::type cc, |
713 const llvm::Twine& name, jit_type *ret, | |
714 const std::vector<jit_type *>& args | |
715 = std::vector<jit_type *> ()); | |
716 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
717 // create an internal calling convention (a function defined in llvm) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
718 jit_function create_internal (const llvm::Twine& name, jit_type *ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
719 const std::vector<jit_type *>& args |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
720 = std::vector<jit_type *> ()) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
721 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
722 return create_function (jit_convention::internal, name, ret, args); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
723 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
724 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
725 #define JIT_PARAM_ARGS const llvm::Twine& name, jit_type *ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
726 #define JIT_PARAMS name, ret, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
727 #define CREATE_FUNCTION(N) JIT_EXPAND(jit_function, create_internal, \ |
15016 | 728 jit_type *, /* empty */, N) |
729 | |
730 CREATE_FUNCTION(1); | |
731 CREATE_FUNCTION(2); | |
732 CREATE_FUNCTION(3); | |
733 CREATE_FUNCTION(4); | |
734 | |
735 #undef JIT_PARAM_ARGS | |
736 #undef JIT_PARAMS | |
737 #undef CREATE_FUNCTION | |
738 | |
739 jit_function create_identity (jit_type *type); | |
740 | |
741 llvm::Value *do_insert_error_check (llvm::IRBuilderD& bld); | |
742 | |
15603 | 743 llvm::Value *do_insert_interrupt_check (llvm::IRBuilderD& bld); |
744 | |
15016 | 745 void add_builtin (const std::string& name); |
746 | |
747 void register_intrinsic (const std::string& name, size_t id, | |
748 jit_type *result, jit_type *arg0) | |
749 { | |
750 std::vector<jit_type *> args (1, arg0); | |
751 register_intrinsic (name, id, result, args); | |
752 } | |
753 | |
754 void register_intrinsic (const std::string& name, size_t id, jit_type *result, | |
755 const std::vector<jit_type *>& args); | |
756 | |
757 void register_generic (const std::string& name, jit_type *result, | |
758 jit_type *arg0) | |
759 { | |
760 std::vector<jit_type *> args (1, arg0); | |
761 register_generic (name, result, args); | |
762 } | |
763 | |
764 void register_generic (const std::string& name, jit_type *result, | |
765 const std::vector<jit_type *>& args); | |
766 | |
767 octave_builtin *find_builtin (const std::string& name); | |
768 | |
769 jit_function mirror_binary (const jit_function& fn); | |
770 | |
771 llvm::Function *wrap_complex (llvm::Function *wrap); | |
772 | |
773 static llvm::Value *pack_complex (llvm::IRBuilderD& bld, | |
774 llvm::Value *cplx); | |
775 | |
776 static llvm::Value *unpack_complex (llvm::IRBuilderD& bld, | |
777 llvm::Value *result); | |
778 | |
779 llvm::Value *complex_real (llvm::Value *cx); | |
780 | |
781 llvm::Value *complex_real (llvm::Value *cx, llvm::Value *real); | |
782 | |
783 llvm::Value *complex_imag (llvm::Value *cx); | |
784 | |
785 llvm::Value *complex_imag (llvm::Value *cx, llvm::Value *imag); | |
786 | |
787 llvm::Value *complex_new (llvm::Value *real, llvm::Value *imag); | |
788 | |
789 void create_int (size_t nbits); | |
790 | |
791 jit_type *intN (size_t nbits) const; | |
792 | |
793 static jit_typeinfo *instance; | |
794 | |
795 llvm::Module *module; | |
796 llvm::ExecutionEngine *engine; | |
797 int next_id; | |
798 | |
799 llvm::GlobalVariable *lerror_state; | |
15603 | 800 llvm::GlobalVariable *loctave_interrupt_state; |
801 | |
802 llvm::Type *sig_atomic_type; | |
15016 | 803 |
804 std::vector<jit_type*> id_to_type; | |
805 jit_type *any; | |
806 jit_type *matrix; | |
807 jit_type *scalar; | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
808 jit_type *scalar_ptr; // a fake type for interfacing with C++ |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
809 jit_type *any_ptr; // a fake type for interfacing with C++ |
15016 | 810 jit_type *range; |
811 jit_type *string; | |
812 jit_type *boolean; | |
813 jit_type *index; | |
814 jit_type *complex; | |
815 jit_type *unknown_function; | |
816 std::map<size_t, jit_type *> ints; | |
817 std::map<std::string, jit_type *> builtins; | |
818 | |
819 llvm::StructType *complex_ret; | |
820 | |
821 std::vector<jit_operation> binary_ops; | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
822 std::vector<jit_operation> unary_ops; |
15016 | 823 jit_operation grab_fn; |
824 jit_operation release_fn; | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
825 jit_operation destroy_fn; |
15016 | 826 jit_operation print_fn; |
827 jit_operation for_init_fn; | |
828 jit_operation for_check_fn; | |
829 jit_operation for_index_fn; | |
830 jit_operation logically_true_fn; | |
831 jit_operation make_range_fn; | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
832 jit_paren_subsref paren_subsref_fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
833 jit_paren_subsasgn paren_subsasgn_fn; |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
834 jit_operation end1_fn; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
835 jit_operation end_fn; |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
836 jit_operation create_undef_fn; |
15016 | 837 |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
838 jit_function any_call; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
839 |
15016 | 840 // type id -> cast function TO that type |
841 std::vector<jit_operation> casts; | |
842 | |
843 // type id -> identity function | |
844 std::vector<jit_function> identities; | |
845 | |
846 llvm::IRBuilderD& builder; | |
847 }; | |
848 | |
849 #endif | |
850 #endif |