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