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