Mercurial > octave-nkf
annotate libinterp/corefcn/jit-typeinfo.cc @ 18559:1a82df63d65e draft
Fully int16 type support
***
Fix int16 type comments
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 04:18:59 +0800 |
parents | 1867774aaa2e |
children | fd138c51ca25 |
rev | line source |
---|---|
18553 | 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:
17164
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 // defines required by llvm |
28 #define __STDC_LIMIT_MACROS | |
29 #define __STDC_CONSTANT_MACROS | |
30 | |
31 #ifdef HAVE_CONFIG_H | |
32 #include <config.h> | |
33 #endif | |
34 | |
35 #ifdef HAVE_LLVM | |
36 | |
37 #include "jit-typeinfo.h" | |
38 | |
39 #include <llvm/Analysis/Verifier.h> | |
17164 | 40 #include <llvm/ExecutionEngine/ExecutionEngine.h> |
41 | |
42 #ifdef HAVE_LLVM_IR_FUNCTION_H | |
43 #include <llvm/IR/GlobalVariable.h> | |
44 #include <llvm/IR/LLVMContext.h> | |
45 #include <llvm/IR/Function.h> | |
46 #include <llvm/IR/Instructions.h> | |
47 #include <llvm/IR/Intrinsics.h> | |
48 #else | |
15016 | 49 #include <llvm/GlobalVariable.h> |
50 #include <llvm/LLVMContext.h> | |
51 #include <llvm/Function.h> | |
52 #include <llvm/Instructions.h> | |
53 #include <llvm/Intrinsics.h> | |
17164 | 54 #endif |
55 | |
56 #ifdef HAVE_LLVM_SUPPORT_IRBUILDER_H | |
15016 | 57 #include <llvm/Support/IRBuilder.h> |
17164 | 58 #elif defined(HAVE_LLVM_IR_IRBUILDER_H) |
59 #include <llvm/IR/IRBuilder.h> | |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
60 #else |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
61 #include <llvm/IRBuilder.h> |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
62 #endif |
17164 | 63 |
15016 | 64 #include <llvm/Support/raw_os_ostream.h> |
65 | |
66 #include "jit-ir.h" | |
67 #include "ov.h" | |
68 #include "ov-builtin.h" | |
69 #include "ov-complex.h" | |
70 #include "ov-scalar.h" | |
18554 | 71 #include "ov-float.h" |
18557 | 72 #include "ov-int8.h" |
18559 | 73 #include "ov-int16.h" |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
74 #include "ov-int64.h" |
18555 | 75 #include "ov-uint16.h" |
15016 | 76 #include "pager.h" |
77 | |
78 static llvm::LLVMContext& context = llvm::getGlobalContext (); | |
79 | |
80 jit_typeinfo *jit_typeinfo::instance = 0; | |
81 | |
82 std::ostream& jit_print (std::ostream& os, jit_type *atype) | |
83 { | |
84 if (! atype) | |
85 return os << "null"; | |
86 return os << atype->name (); | |
87 } | |
88 | |
89 // function that jit code calls | |
90 extern "C" void | |
91 octave_jit_print_any (const char *name, octave_base_value *obv) | |
92 { | |
93 obv->print_with_name (octave_stdout, name, true); | |
94 } | |
95 | |
96 extern "C" void | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
97 octave_jit_print_scalar (const char *name, double value) |
15016 | 98 { |
99 // FIXME: We should avoid allocating a new octave_scalar each time | |
100 octave_value ov (value); | |
101 ov.print_with_name (octave_stdout, name); | |
102 } | |
103 | |
104 extern "C" octave_base_value* | |
105 octave_jit_binary_any_any (octave_value::binary_op op, octave_base_value *lhs, | |
106 octave_base_value *rhs) | |
107 { | |
108 octave_value olhs (lhs, true); | |
109 octave_value orhs (rhs, true); | |
110 octave_value result = do_binary_op (op, olhs, orhs); | |
111 octave_base_value *rep = result.internal_rep (); | |
112 rep->grab (); | |
113 return rep; | |
114 } | |
115 | |
116 extern "C" octave_idx_type | |
117 octave_jit_compute_nelem (double base, double limit, double inc) | |
118 { | |
119 Range rng = Range (base, limit, inc); | |
120 return rng.nelem (); | |
121 } | |
122 | |
123 extern "C" void | |
124 octave_jit_release_any (octave_base_value *obv) | |
125 { | |
126 obv->release (); | |
127 } | |
128 | |
129 extern "C" void | |
130 octave_jit_release_matrix (jit_matrix *m) | |
131 { | |
132 delete m->array; | |
133 } | |
134 | |
135 extern "C" octave_base_value * | |
136 octave_jit_grab_any (octave_base_value *obv) | |
137 { | |
138 obv->grab (); | |
139 return obv; | |
140 } | |
141 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
142 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
143 octave_jit_grab_matrix (jit_matrix *m) |
15016 | 144 { |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
145 return *m->array; |
15016 | 146 } |
147 | |
148 extern "C" octave_base_value * | |
149 octave_jit_cast_any_matrix (jit_matrix *m) | |
150 { | |
151 octave_value ret (*m->array); | |
152 octave_base_value *rep = ret.internal_rep (); | |
153 rep->grab (); | |
154 delete m->array; | |
155 | |
156 return rep; | |
157 } | |
158 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
159 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
160 octave_jit_cast_matrix_any (octave_base_value *obv) |
15016 | 161 { |
162 NDArray m = obv->array_value (); | |
163 obv->release (); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
164 return m; |
15016 | 165 } |
166 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
167 extern "C" octave_base_value * |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
168 octave_jit_cast_any_range (jit_range *rng) |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
169 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
170 Range temp (*rng); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
171 octave_value ret (temp); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
172 octave_base_value *rep = ret.internal_rep (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
173 rep->grab (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
174 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
175 return rep; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
176 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
177 extern "C" jit_range |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
178 octave_jit_cast_range_any (octave_base_value *obv) |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
179 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
180 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
181 jit_range r (obv->range_value ()); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
182 obv->release (); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
183 return r; |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
184 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
185 |
15016 | 186 extern "C" double |
187 octave_jit_cast_scalar_any (octave_base_value *obv) | |
188 { | |
189 double ret = obv->double_value (); | |
190 obv->release (); | |
191 return ret; | |
192 } | |
193 | |
194 extern "C" octave_base_value * | |
195 octave_jit_cast_any_scalar (double value) | |
196 { | |
197 return new octave_scalar (value); | |
198 } | |
199 | |
18554 | 200 extern "C" float |
201 octave_jit_cast_single_any (octave_base_value *obv) | |
202 { | |
203 float ret = obv->float_value (); | |
204 obv->release (); | |
205 return ret; | |
206 } | |
207 | |
208 extern "C" octave_base_value * | |
209 octave_jit_cast_any_single (float value) | |
210 { | |
211 return new octave_float_scalar (value); | |
212 } | |
213 | |
18557 | 214 extern "C" int8_t |
215 octave_jit_cast_int8_any (octave_base_value *obv) | |
216 { | |
217 int8_t ret = obv->int8_scalar_value (); | |
218 obv->release (); | |
219 return ret; | |
220 } | |
221 | |
222 extern "C" octave_base_value * | |
223 octave_jit_cast_any_int8 (int8_t value) | |
224 { | |
225 return new octave_int8_scalar (value); | |
226 } | |
227 | |
18559 | 228 extern "C" int16_t |
229 octave_jit_cast_int16_any (octave_base_value *obv) | |
230 { | |
231 int16_t ret = obv->int16_scalar_value (); | |
232 obv->release (); | |
233 return ret; | |
234 } | |
235 | |
236 extern "C" octave_base_value * | |
237 octave_jit_cast_any_int16 (int16_t value) | |
238 { | |
239 return new octave_int16_scalar (value); | |
240 } | |
241 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
242 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
243 octave_jit_cast_int64_any (octave_base_value *obv) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
244 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
245 int64_t ret = obv->int64_scalar_value (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
246 obv->release (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
247 return ret; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
248 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
249 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
250 extern "C" octave_base_value * |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
251 octave_jit_cast_any_int64 (int64_t value) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
252 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
253 return new octave_int64_scalar (value); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
254 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
255 |
18555 | 256 extern "C" uint16_t |
257 octave_jit_cast_uint16_any (octave_base_value *obv) | |
258 { | |
259 uint16_t ret = obv->uint16_scalar_value (); | |
260 obv->release (); | |
261 return ret; | |
262 } | |
263 | |
264 extern "C" octave_base_value * | |
265 octave_jit_cast_any_uint16 (uint16_t value) | |
266 { | |
267 return new octave_uint16_scalar (value); | |
268 } | |
269 | |
15016 | 270 extern "C" Complex |
271 octave_jit_cast_complex_any (octave_base_value *obv) | |
272 { | |
273 Complex ret = obv->complex_value (); | |
274 obv->release (); | |
275 return ret; | |
276 } | |
277 | |
278 extern "C" octave_base_value * | |
279 octave_jit_cast_any_complex (Complex c) | |
280 { | |
281 if (c.imag () == 0) | |
282 return new octave_scalar (c.real ()); | |
283 else | |
284 return new octave_complex (c); | |
285 } | |
286 | |
287 extern "C" void | |
288 octave_jit_gripe_nan_to_logical_conversion (void) | |
289 { | |
290 try | |
291 { | |
292 gripe_nan_to_logical_conversion (); | |
293 } | |
294 catch (const octave_execution_exception&) | |
295 { | |
296 gripe_library_execution_error (); | |
297 } | |
298 } | |
299 | |
300 extern "C" void | |
301 octave_jit_ginvalid_index (void) | |
302 { | |
303 try | |
304 { | |
305 gripe_invalid_index (); | |
306 } | |
307 catch (const octave_execution_exception&) | |
308 { | |
309 gripe_library_execution_error (); | |
310 } | |
311 } | |
312 | |
313 extern "C" void | |
314 octave_jit_gindex_range (int nd, int dim, octave_idx_type iext, | |
315 octave_idx_type ext) | |
316 { | |
317 try | |
318 { | |
319 gripe_index_out_of_range (nd, dim, iext, ext); | |
320 } | |
321 catch (const octave_execution_exception&) | |
322 { | |
323 gripe_library_execution_error (); | |
324 } | |
325 } | |
326 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
327 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
328 octave_jit_paren_subsasgn_impl (jit_matrix *mat, octave_idx_type index, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
329 double value) |
15016 | 330 { |
331 NDArray *array = mat->array; | |
332 if (array->nelem () < index) | |
333 array->resize1 (index); | |
334 | |
335 double *data = array->fortran_vec (); | |
336 data[index - 1] = value; | |
337 | |
338 mat->update (); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
339 return *mat; |
15016 | 340 } |
341 | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
342 static void |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
343 make_indices (double *indices, octave_idx_type idx_count, |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
344 Array<idx_vector>& result) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
345 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
346 result.resize (dim_vector (1, idx_count)); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
347 for (octave_idx_type i = 0; i < idx_count; ++i) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
348 result(i) = idx_vector (indices[i]); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
349 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
350 |
15067 | 351 extern "C" double |
352 octave_jit_paren_scalar (jit_matrix *mat, double *indicies, | |
353 octave_idx_type idx_count) | |
354 { | |
355 // FIXME: Replace this with a more optimal version | |
356 try | |
357 { | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
358 Array<idx_vector> idx; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
359 make_indices (indicies, idx_count, idx); |
15067 | 360 |
361 Array<double> ret = mat->array->index (idx); | |
362 return ret.xelem (0); | |
363 } | |
364 catch (const octave_execution_exception&) | |
365 { | |
366 gripe_library_execution_error (); | |
367 return 0; | |
368 } | |
369 } | |
370 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
371 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
372 octave_jit_paren_scalar_subsasgn (jit_matrix *mat, double *indices, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
373 octave_idx_type idx_count, double value) |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
374 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
375 // FIXME: Replace this with a more optimal version |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
376 jit_matrix ret; |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
377 try |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
378 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
379 Array<idx_vector> idx; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
380 make_indices (indices, idx_count, idx); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
381 |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
382 Matrix temp (1, 1); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
383 temp.xelem(0) = value; |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
384 mat->array->assign (idx, temp); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
385 ret.update (mat->array); |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
386 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
387 catch (const octave_execution_exception&) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
388 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
389 gripe_library_execution_error (); |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
390 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
391 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
392 return ret; |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
393 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
394 |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
395 extern "C" jit_matrix |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
396 octave_jit_paren_subsasgn_matrix_range (jit_matrix *mat, jit_range *index, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
397 double value) |
15016 | 398 { |
399 NDArray *array = mat->array; | |
400 bool done = false; | |
401 | |
402 // optimize for the simple case (no resizing and no errors) | |
403 if (*array->jit_ref_count () == 1 | |
404 && index->all_elements_are_ints ()) | |
405 { | |
406 // this code is similar to idx_vector::fill, but we avoid allocating an | |
407 // idx_vector and its associated rep | |
408 octave_idx_type start = static_cast<octave_idx_type> (index->base) - 1; | |
409 octave_idx_type step = static_cast<octave_idx_type> (index->inc); | |
410 octave_idx_type nelem = index->nelem; | |
411 octave_idx_type final = start + nelem * step; | |
412 if (step < 0) | |
413 { | |
414 step = -step; | |
415 std::swap (final, start); | |
416 } | |
417 | |
418 if (start >= 0 && final < mat->slice_len) | |
419 { | |
420 done = true; | |
421 | |
422 double *data = array->jit_slice_data (); | |
423 if (step == 1) | |
424 std::fill (data + start, data + start + nelem, value); | |
425 else | |
426 { | |
427 for (octave_idx_type i = start; i < final; i += step) | |
428 data[i] = value; | |
429 } | |
430 } | |
431 } | |
432 | |
433 if (! done) | |
434 { | |
435 idx_vector idx (*index); | |
436 NDArray avalue (dim_vector (1, 1)); | |
437 avalue.xelem (0) = value; | |
438 array->assign (idx, avalue); | |
439 } | |
440 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
441 jit_matrix ret; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
442 ret.update (array); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
443 return ret; |
15016 | 444 } |
445 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
446 extern "C" double |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
447 octave_jit_end_matrix (jit_matrix *mat, octave_idx_type idx, |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
448 octave_idx_type count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
449 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
450 octave_idx_type ndim = mat->dimensions[-1]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
451 if (ndim == count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
452 return mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
453 else if (ndim > count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
454 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
455 if (idx == count - 1) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
456 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
457 double ret = mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
458 for (octave_idx_type i = idx + 1; i < ndim; ++i) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
459 ret *= mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
460 return ret; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
461 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
462 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
463 return mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
464 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
465 else // ndim < count |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
466 return idx < ndim ? mat->dimensions[idx] : 1; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
467 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
468 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
469 extern "C" octave_base_value * |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
470 octave_jit_create_undef (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
471 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
472 octave_value undef; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
473 octave_base_value *ret = undef.internal_rep (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
474 ret->grab (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
475 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
476 return ret; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
477 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
478 |
15016 | 479 extern "C" Complex |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
480 octave_jit_complex_mul (Complex lhs, Complex rhs) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
481 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
482 if (lhs.imag () == 0 && rhs.imag() == 0) |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
483 return Complex (lhs.real () * rhs.real (), 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
484 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
485 return lhs * rhs; |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
486 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
487 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
488 extern "C" Complex |
15016 | 489 octave_jit_complex_div (Complex lhs, Complex rhs) |
490 { | |
491 // see src/OPERATORS/op-cs-cs.cc | |
492 if (rhs == 0.0) | |
493 gripe_divide_by_zero (); | |
494 | |
495 return lhs / rhs; | |
496 } | |
497 | |
498 // FIXME: CP form src/xpow.cc | |
499 static inline int | |
500 xisint (double x) | |
501 { | |
502 return (D_NINT (x) == x | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
503 && ((x >= 0 && x < std::numeric_limits<int>::max ()) |
15219
aeba1adfd76b
Correct small typo in jit-typeinfo.cc
Melvin Robinson <melvin.robinson@mavs.uta.edu>
parents:
15215
diff
changeset
|
504 || (x <= 0 && x > std::numeric_limits<int>::min ()))); |
15016 | 505 } |
506 | |
507 extern "C" Complex | |
508 octave_jit_pow_scalar_scalar (double lhs, double rhs) | |
509 { | |
510 // FIXME: almost CP from src/xpow.cc | |
511 if (lhs < 0.0 && ! xisint (rhs)) | |
512 return std::pow (Complex (lhs), rhs); | |
513 return std::pow (lhs, rhs); | |
514 } | |
515 | |
516 extern "C" Complex | |
517 octave_jit_pow_complex_complex (Complex lhs, Complex rhs) | |
518 { | |
519 if (lhs.imag () == 0 && rhs.imag () == 0) | |
520 return octave_jit_pow_scalar_scalar (lhs.real (), rhs.real ()); | |
521 return std::pow (lhs, rhs); | |
522 } | |
523 | |
18554 | 524 // FIXME: should handle FloatComplex |
525 extern "C" Complex | |
526 octave_jit_pow_single_single (float lhs, float rhs) | |
527 { | |
528 // FIXME: almost CP from libinterp/corefcn/xpow.cc | |
529 float retval; | |
530 | |
531 if (lhs < 0.0 && ! xisint (rhs)) | |
532 { | |
533 FloatComplex lhstmp (lhs); | |
534 | |
535 return std::pow (lhstmp, rhs); | |
536 } | |
537 else | |
538 retval = std::pow (lhs, rhs); | |
539 | |
540 return retval; | |
541 } | |
542 | |
15016 | 543 extern "C" Complex |
544 octave_jit_pow_complex_scalar (Complex lhs, double rhs) | |
545 { | |
546 if (lhs.imag () == 0) | |
547 return octave_jit_pow_scalar_scalar (lhs.real (), rhs); | |
548 return std::pow (lhs, rhs); | |
549 } | |
550 | |
551 extern "C" Complex | |
552 octave_jit_pow_scalar_complex (double lhs, Complex rhs) | |
553 { | |
554 if (rhs.imag () == 0) | |
555 return octave_jit_pow_scalar_scalar (lhs, rhs.real ()); | |
556 return std::pow (lhs, rhs); | |
557 } | |
558 | |
18555 | 559 /************************************************************ |
560 * | |
18557 | 561 * int8 related external helper function |
562 * | |
563 ************************************************************/ | |
564 | |
565 extern "C" int8_t | |
566 octave_jit_add_int8_int8 (int8_t lhs, int8_t rhs) | |
567 { | |
568 uint8_t ulhs = lhs; | |
569 uint8_t urhs = rhs; | |
570 uint8_t res = ulhs + urhs; | |
571 | |
572 /* Calculate overflowed result. (Don't change the sign bit of ux) */ | |
573 ulhs = (ulhs >> 7) + SCHAR_MAX; | |
574 | |
575 /* Force compiler to use cmovns instruction */ | |
576 if ((int8_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) | |
577 { | |
578 res = ulhs; | |
579 } | |
580 | |
581 return res; | |
582 } | |
583 | |
584 extern "C" int8_t | |
585 octave_jit_sub_int8_int8 (int8_t lhs, int8_t rhs) | |
586 { | |
587 uint8_t ulhs = lhs; | |
588 uint8_t urhs = rhs; | |
589 uint8_t res = ulhs - urhs; | |
590 | |
591 ulhs = (ulhs >> 7) + SCHAR_MAX; | |
592 | |
593 /* Force compiler to use cmovns instruction */ | |
594 if ((int8_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) | |
595 { | |
596 res = ulhs; | |
597 } | |
598 | |
599 return res; | |
600 } | |
601 | |
602 extern "C" int8_t | |
603 octave_jit_mul_int8_int8 (int8_t lhs, int8_t rhs) | |
604 { | |
605 int16_t res = (int16_t) lhs * (int16_t) rhs; | |
606 uint8_t res2 = ((uint8_t) (lhs ^ rhs) >> 7) + SCHAR_MAX; | |
607 | |
608 int8_t hi = (res >> 8); | |
609 int8_t lo = res; | |
610 | |
611 if (hi != (lo >> 7)) res = res2; | |
612 | |
613 return res; | |
614 } | |
615 | |
616 extern "C" int8_t | |
617 octave_jit_incr_int8 (int8_t val) | |
618 { | |
619 return octave_jit_add_int8_int8 (val, 1); | |
620 } | |
621 | |
622 extern "C" int8_t | |
623 octave_jit_decr_int8 (int8_t val) | |
624 { | |
625 return octave_jit_sub_int8_int8 (val, 1); | |
626 } | |
627 | |
628 /************************************************************ | |
629 * | |
18559 | 630 * int16 related external helper function |
631 * | |
632 ************************************************************/ | |
633 | |
634 extern "C" int16_t | |
635 octave_jit_add_int16_int16 (int16_t lhs, int16_t rhs) | |
636 { | |
637 uint16_t ulhs = lhs; | |
638 uint16_t urhs = rhs; | |
639 uint16_t res = ulhs + urhs; | |
640 | |
641 /* Calculate overflowed result. (Don't change the sign bit of ux) */ | |
642 ulhs = (ulhs >> 15) + SHRT_MAX; | |
643 | |
644 /* Force compiler to use cmovns instruction */ | |
645 if ((int16_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) | |
646 { | |
647 res = ulhs; | |
648 } | |
649 | |
650 return res; | |
651 } | |
652 | |
653 extern "C" int16_t | |
654 octave_jit_sub_int16_int16 (int16_t lhs, int16_t rhs) | |
655 { | |
656 uint16_t ulhs = lhs; | |
657 uint16_t urhs = rhs; | |
658 uint16_t res = ulhs - urhs; | |
659 | |
660 ulhs = (ulhs >> 15) + SHRT_MAX; | |
661 | |
662 /* Force compiler to use cmovns instruction */ | |
663 if ((int16_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) | |
664 { | |
665 res = ulhs; | |
666 } | |
667 | |
668 return res; | |
669 } | |
670 | |
671 extern "C" int16_t | |
672 octave_jit_mul_int16_int16 (int16_t lhs, int16_t rhs) | |
673 { | |
674 int32_t res = (int32_t) lhs * (int32_t) rhs; | |
675 uint16_t res2 = ((uint16_t) (lhs ^ rhs) >> 15) + SHRT_MAX; | |
676 | |
677 int16_t hi = (res >> 16); | |
678 int16_t lo = res; | |
679 | |
680 if (hi != (lo >> 15)) res = res2; | |
681 | |
682 return res; | |
683 } | |
684 | |
685 extern "C" int16_t | |
686 octave_jit_incr_int16 (int16_t val) | |
687 { | |
688 return octave_jit_add_int16_int16 (val, 1); | |
689 } | |
690 | |
691 extern "C" int16_t | |
692 octave_jit_decr_int16 (int16_t val) | |
693 { | |
694 return octave_jit_sub_int16_int16 (val, 1); | |
695 } | |
696 | |
697 /************************************************************ | |
698 * | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
699 * int64 related external helper function |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
700 * |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
701 ************************************************************/ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
702 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
703 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
704 octave_jit_add_int64_int64 (int64_t lhs, int64_t rhs) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
705 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
706 uint64_t ulhs = lhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
707 uint64_t urhs = rhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
708 uint64_t res = ulhs + urhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
709 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
710 /* Calculate overflowed result. (Don't change the sign bit of ux) */ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
711 ulhs = (ulhs >> 63) + LONG_MAX; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
712 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
713 /* Force compiler to use cmovns instruction */ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
714 if ((int64_t) ((ulhs ^ urhs) | ~(urhs ^ res)) >= 0) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
715 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
716 res = ulhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
717 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
718 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
719 return res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
720 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
721 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
722 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
723 octave_jit_sub_int64_int64 (int64_t lhs, int64_t rhs) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
724 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
725 uint64_t ulhs = lhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
726 uint64_t urhs = rhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
727 uint64_t res = ulhs - urhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
728 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
729 ulhs = (ulhs >> 63) + LONG_MAX; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
730 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
731 /* Force compiler to use cmovns instruction */ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
732 if ((int64_t)((ulhs ^ urhs) & (ulhs ^ res)) < 0) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
733 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
734 res = ulhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
735 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
736 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
737 return res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
738 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
739 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
740 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
741 octave_jit_mul_int64_int64 (int64_t lhs, int64_t rhs) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
742 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
743 #ifdef OCTAVE_INT_USE_LONG_DOUBLE |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
744 long double p = static_cast<long double> (lhs) * static_cast<long double> (rhs); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
745 if (p > static_cast<long double> (std::numeric_limits<int64_t>::max ())) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
746 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
747 return std::numeric_limits<int64_t>::max (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
748 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
749 else if (p < static_cast<long double> (std::numeric_limits<int64_t>::min ())) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
750 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
751 return std::numeric_limits<int64_t>::min (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
752 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
753 else |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
754 return static_cast<int64_t> (p); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
755 #else |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
756 __int128_t res = (__int128_t) lhs * (__int128_t) rhs; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
757 uint64_t res2 = ((uint64_t) (lhs ^ rhs) >> 63) + LONG_MAX; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
758 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
759 int64_t hi = (res >> 64); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
760 int64_t lo = res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
761 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
762 if (hi != (lo >> 63)) res = res2; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
763 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
764 return res; |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
765 #endif |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
766 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
767 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
768 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
769 octave_jit_incr_int64 (int64_t val) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
770 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
771 return octave_jit_add_int64_int64 (val, 1); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
772 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
773 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
774 extern "C" int64_t |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
775 octave_jit_decr_int64 (int64_t val) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
776 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
777 return octave_jit_sub_int64_int64 (val, 1); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
778 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
779 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
780 /************************************************************ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
781 * |
18555 | 782 * uint16 related external helper function |
783 * | |
784 ************************************************************/ | |
785 | |
786 extern "C" uint16_t | |
787 octave_jit_add_uint16_uint16 (uint16_t lhs, uint16_t rhs) | |
788 { | |
789 uint16_t res = lhs + rhs; | |
790 res |= -(res < lhs); | |
791 | |
792 return res; | |
793 } | |
794 | |
795 extern "C" uint16_t | |
796 octave_jit_sub_uint16_uint16 (uint16_t lhs, uint16_t rhs) | |
797 { | |
798 uint16_t res = lhs - rhs; | |
799 res &= -(res <= lhs); | |
800 | |
801 return res; | |
802 } | |
803 | |
804 extern "C" uint16_t | |
805 octave_jit_mul_uint16_uint16 (uint16_t lhs, uint16_t rhs) | |
806 { | |
807 uint32_t res = (uint32_t) lhs * (uint32_t) rhs; | |
808 | |
809 uint16_t hi = res >> 16; | |
810 uint16_t lo = res; | |
811 | |
812 return lo | -!!hi; | |
813 } | |
814 | |
815 extern "C" uint16_t | |
816 octave_jit_incr_uint16 (uint16_t val) | |
817 { | |
818 return octave_jit_add_uint16_uint16 (val, 1); | |
819 } | |
820 | |
821 extern "C" uint16_t | |
822 octave_jit_decr_uint16 (uint16_t val) | |
823 { | |
824 return octave_jit_sub_uint16_uint16 (val, 1); | |
825 } | |
826 | |
15016 | 827 extern "C" void |
828 octave_jit_print_matrix (jit_matrix *m) | |
829 { | |
830 std::cout << *m << std::endl; | |
831 } | |
832 | |
833 static void | |
834 gripe_bad_result (void) | |
835 { | |
836 error ("incorrect type information given to the JIT compiler"); | |
837 } | |
838 | |
839 // FIXME: Add support for multiple outputs | |
840 extern "C" octave_base_value * | |
841 octave_jit_call (octave_builtin::fcn fn, size_t nargin, | |
842 octave_base_value **argin, jit_type *result_type) | |
843 { | |
844 octave_value_list ovl (nargin); | |
845 for (size_t i = 0; i < nargin; ++i) | |
846 ovl.xelem (i) = octave_value (argin[i]); | |
847 | |
848 ovl = fn (ovl, 1); | |
849 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
850 // FIXME: Check result_type somehow |
15016 | 851 if (result_type) |
852 { | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
853 if (ovl.length () < 1) |
15016 | 854 { |
855 gripe_bad_result (); | |
856 return 0; | |
857 } | |
858 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
859 octave_value result = ovl.xelem(0); |
15016 | 860 octave_base_value *ret = result.internal_rep (); |
861 ret->grab (); | |
862 return ret; | |
863 } | |
864 | |
865 if (! (ovl.length () == 0 | |
866 || (ovl.length () == 1 && ovl.xelem (0).is_undefined ()))) | |
867 gripe_bad_result (); | |
868 | |
869 return 0; | |
870 } | |
871 | |
872 // -------------------- jit_range -------------------- | |
873 bool | |
874 jit_range::all_elements_are_ints () const | |
875 { | |
876 Range r (*this); | |
877 return r.all_elements_are_ints (); | |
878 } | |
879 | |
880 std::ostream& | |
881 operator<< (std::ostream& os, const jit_range& rng) | |
882 { | |
883 return os << "Range[" << rng.base << ", " << rng.limit << ", " << rng.inc | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
884 << ", " << rng.nelem << "]"; |
15016 | 885 } |
886 | |
887 // -------------------- jit_matrix -------------------- | |
888 | |
889 std::ostream& | |
890 operator<< (std::ostream& os, const jit_matrix& mat) | |
891 { | |
892 return os << "Matrix[" << mat.ref_count << ", " << mat.slice_data << ", " | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
893 << mat.slice_len << ", " << mat.dimensions << ", " |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
894 << mat.array << "]"; |
15016 | 895 } |
896 | |
897 // -------------------- jit_type -------------------- | |
898 jit_type::jit_type (const std::string& aname, jit_type *aparent, | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
899 llvm::Type *allvm_type, bool askip_paren, int aid) : |
15016 | 900 mname (aname), mparent (aparent), llvm_type (allvm_type), mid (aid), |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
901 mdepth (aparent ? aparent->mdepth + 1 : 0), mskip_paren (askip_paren) |
15016 | 902 { |
903 std::memset (msret, 0, sizeof (msret)); | |
904 std::memset (mpointer_arg, 0, sizeof (mpointer_arg)); | |
905 std::memset (mpack, 0, sizeof (mpack)); | |
906 std::memset (munpack, 0, sizeof (munpack)); | |
907 | |
908 for (size_t i = 0; i < jit_convention::length; ++i) | |
909 mpacked_type[i] = llvm_type; | |
910 } | |
911 | |
912 llvm::Type * | |
913 jit_type::to_llvm_arg (void) const | |
914 { | |
915 return llvm_type ? llvm_type->getPointerTo () : 0; | |
916 } | |
917 | |
918 // -------------------- jit_function -------------------- | |
919 jit_function::jit_function () : module (0), llvm_function (0), mresult (0), | |
920 call_conv (jit_convention::length), | |
921 mcan_error (false) | |
922 {} | |
923 | |
924 jit_function::jit_function (llvm::Module *amodule, | |
925 jit_convention::type acall_conv, | |
926 const llvm::Twine& aname, jit_type *aresult, | |
927 const std::vector<jit_type *>& aargs) | |
928 : module (amodule), mresult (aresult), args (aargs), call_conv (acall_conv), | |
929 mcan_error (false) | |
930 { | |
931 llvm::SmallVector<llvm::Type *, 15> llvm_args; | |
932 | |
933 llvm::Type *rtype = llvm::Type::getVoidTy (context); | |
934 if (mresult) | |
935 { | |
936 rtype = mresult->packed_type (call_conv); | |
937 if (sret ()) | |
938 { | |
939 llvm_args.push_back (rtype->getPointerTo ()); | |
940 rtype = llvm::Type::getVoidTy (context); | |
941 } | |
942 } | |
943 | |
944 for (std::vector<jit_type *>::const_iterator iter = args.begin (); | |
945 iter != args.end (); ++iter) | |
946 { | |
947 jit_type *ty = *iter; | |
948 assert (ty); | |
949 llvm::Type *argty = ty->packed_type (call_conv); | |
950 if (ty->pointer_arg (call_conv)) | |
951 argty = argty->getPointerTo (); | |
952 | |
953 llvm_args.push_back (argty); | |
954 } | |
955 | |
956 // we mark all functinos as external linkage because this prevents llvm | |
957 // from getting rid of always inline functions | |
958 llvm::FunctionType *ft = llvm::FunctionType::get (rtype, llvm_args, false); | |
959 llvm_function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, | |
960 aname, module); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
961 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
962 if (sret ()) |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
963 { |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
964 #ifdef FUNCTION_ADDATTRIBUTE_ARG_IS_ATTRIBUTES |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
965 llvm::AttrBuilder attr_builder; |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
966 attr_builder.addAttribute (llvm::Attributes::StructRet); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
967 llvm::Attributes attrs = llvm::Attributes::get(context, attr_builder); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
968 llvm_function->addAttribute (1, attrs); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
969 #else |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
970 llvm_function->addAttribute (1, llvm::Attribute::StructRet); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
971 #endif |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
972 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
973 |
15016 | 974 if (call_conv == jit_convention::internal) |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
975 #ifdef FUNCTION_ADDFNATTR_ARG_IS_ATTRIBUTES |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
976 llvm_function->addFnAttr (llvm::Attributes::AlwaysInline); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
977 #else |
15016 | 978 llvm_function->addFnAttr (llvm::Attribute::AlwaysInline); |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
979 #endif |
15016 | 980 } |
981 | |
982 jit_function::jit_function (const jit_function& fn, jit_type *aresult, | |
983 const std::vector<jit_type *>& aargs) | |
984 : module (fn.module), llvm_function (fn.llvm_function), mresult (aresult), | |
985 args (aargs), call_conv (fn.call_conv), mcan_error (fn.mcan_error) | |
986 { | |
987 } | |
988 | |
989 jit_function::jit_function (const jit_function& fn) | |
990 : module (fn.module), llvm_function (fn.llvm_function), mresult (fn.mresult), | |
991 args (fn.args), call_conv (fn.call_conv), mcan_error (fn.mcan_error) | |
992 {} | |
993 | |
15385
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
994 void |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
995 jit_function::erase (void) |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
996 { |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
997 if (! llvm_function) |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
998 return; |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
999 |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1000 llvm_function->eraseFromParent (); |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1001 llvm_function = 0; |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1002 } |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
1003 |
15016 | 1004 std::string |
1005 jit_function::name (void) const | |
1006 { | |
1007 return llvm_function->getName (); | |
1008 } | |
1009 | |
1010 llvm::BasicBlock * | |
1011 jit_function::new_block (const std::string& aname, | |
1012 llvm::BasicBlock *insert_before) | |
1013 { | |
1014 return llvm::BasicBlock::Create (context, aname, llvm_function, | |
1015 insert_before); | |
1016 } | |
1017 | |
1018 llvm::Value * | |
1019 jit_function::call (llvm::IRBuilderD& builder, | |
1020 const std::vector<jit_value *>& in_args) const | |
1021 { | |
18556
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1022 // FIXME: Unhandled case: |
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1023 // function ret = lt(x, y) |
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1024 // ret = x < y; |
4d285a169b29
add comment for function support
LYH <lyh.kernel@gmail.com>
parents:
18555
diff
changeset
|
1025 // endfunction |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1026 if (! valid ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1027 throw jit_fail_exception ("Call not implemented"); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1028 |
15016 | 1029 assert (in_args.size () == args.size ()); |
1030 std::vector<llvm::Value *> llvm_args (args.size ()); | |
1031 for (size_t i = 0; i < in_args.size (); ++i) | |
1032 llvm_args[i] = in_args[i]->to_llvm (); | |
1033 | |
1034 return call (builder, llvm_args); | |
1035 } | |
1036 | |
1037 llvm::Value * | |
1038 jit_function::call (llvm::IRBuilderD& builder, | |
1039 const std::vector<llvm::Value *>& in_args) const | |
1040 { | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1041 if (! valid ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1042 throw jit_fail_exception ("Call not implemented"); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1043 |
15016 | 1044 assert (in_args.size () == args.size ()); |
1045 llvm::SmallVector<llvm::Value *, 10> llvm_args; | |
1046 llvm_args.reserve (in_args.size () + sret ()); | |
1047 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1048 llvm::BasicBlock *insert_block = builder.GetInsertBlock (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1049 llvm::Function *parent = insert_block->getParent (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1050 assert (parent); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1051 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1052 // we insert allocas inside the prelude block to prevent stack overflows |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1053 llvm::BasicBlock& prelude = parent->getEntryBlock (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1054 llvm::IRBuilder<> pre_builder (&prelude, prelude.begin ()); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1055 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1056 llvm::AllocaInst *sret_mem = 0; |
15016 | 1057 if (sret ()) |
1058 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1059 sret_mem = pre_builder.CreateAlloca (mresult->packed_type (call_conv)); |
15016 | 1060 llvm_args.push_back (sret_mem); |
1061 } | |
1062 | |
1063 for (size_t i = 0; i < in_args.size (); ++i) | |
1064 { | |
1065 llvm::Value *arg = in_args[i]; | |
1066 jit_type::convert_fn convert = args[i]->pack (call_conv); | |
1067 if (convert) | |
1068 arg = convert (builder, arg); | |
1069 | |
1070 if (args[i]->pointer_arg (call_conv)) | |
1071 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1072 llvm::Type *ty = args[i]->packed_type (call_conv); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1073 llvm::Value *alloca = pre_builder.CreateAlloca (ty); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1074 builder.CreateStore (arg, alloca); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1075 arg = alloca; |
15016 | 1076 } |
1077 | |
1078 llvm_args.push_back (arg); | |
1079 } | |
1080 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1081 llvm::CallInst *callinst = builder.CreateCall (llvm_function, llvm_args); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1082 llvm::Value *ret = callinst; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1083 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1084 if (sret ()) |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1085 { |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1086 #ifdef CALLINST_ADDATTRIBUTE_ARG_IS_ATTRIBUTES |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1087 llvm::AttrBuilder attr_builder; |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1088 attr_builder.addAttribute(llvm::Attributes::StructRet); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1089 llvm::Attributes attrs = llvm::Attributes::get(context, attr_builder); |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1090 callinst->addAttribute (1, attrs); |
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1091 #else |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1092 callinst->addAttribute (1, llvm::Attribute::StructRet); |
17031
38bcfd413db0
Handle LLVM API incoherence. Octave now works with LLVM 3.0, 3.1, and 3.2
LYH <lyh.kernel@gmail.com>
parents:
16892
diff
changeset
|
1093 #endif |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1094 ret = builder.CreateLoad (sret_mem); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1095 } |
15016 | 1096 |
1097 if (mresult) | |
1098 { | |
1099 jit_type::convert_fn unpack = mresult->unpack (call_conv); | |
1100 if (unpack) | |
1101 ret = unpack (builder, ret); | |
1102 } | |
1103 | |
1104 return ret; | |
1105 } | |
1106 | |
1107 llvm::Value * | |
1108 jit_function::argument (llvm::IRBuilderD& builder, size_t idx) const | |
1109 { | |
1110 assert (idx < args.size ()); | |
1111 | |
1112 // FIXME: We should be treating arguments like a list, not a vector. Shouldn't | |
1113 // matter much for now, as the number of arguments shouldn't be much bigger | |
1114 // than 4 | |
1115 llvm::Function::arg_iterator iter = llvm_function->arg_begin (); | |
1116 if (sret ()) | |
1117 ++iter; | |
1118 | |
1119 for (size_t i = 0; i < idx; ++i, ++iter); | |
1120 | |
1121 if (args[idx]->pointer_arg (call_conv)) | |
1122 return builder.CreateLoad (iter); | |
1123 | |
1124 return iter; | |
1125 } | |
1126 | |
1127 void | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1128 jit_function::do_return (llvm::IRBuilderD& builder, llvm::Value *rval, |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1129 bool verify) |
15016 | 1130 { |
1131 assert (! rval == ! mresult); | |
1132 | |
1133 if (rval) | |
1134 { | |
1135 jit_type::convert_fn convert = mresult->pack (call_conv); | |
1136 if (convert) | |
1137 rval = convert (builder, rval); | |
1138 | |
1139 if (sret ()) | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1140 { |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1141 builder.CreateStore (rval, llvm_function->arg_begin ()); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1142 builder.CreateRetVoid (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1143 } |
15016 | 1144 else |
1145 builder.CreateRet (rval); | |
1146 } | |
1147 else | |
1148 builder.CreateRetVoid (); | |
1149 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1150 if (verify) |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1151 llvm::verifyFunction (*llvm_function); |
15016 | 1152 } |
1153 | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1154 void |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1155 jit_function::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
|
1156 { |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1157 assert (valid ()); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1158 engine->addGlobalMapping (llvm_function, fn); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1159 } |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1160 |
15016 | 1161 std::ostream& |
1162 operator<< (std::ostream& os, const jit_function& fn) | |
1163 { | |
1164 llvm::Function *lfn = fn.to_llvm (); | |
1165 os << "jit_function: cc=" << fn.call_conv; | |
1166 llvm::raw_os_ostream llvm_out (os); | |
1167 lfn->print (llvm_out); | |
1168 llvm_out.flush (); | |
1169 return os; | |
1170 } | |
1171 | |
1172 // -------------------- jit_operation -------------------- | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1173 jit_operation::~jit_operation (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1174 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1175 for (generated_map::iterator iter = generated.begin (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1176 iter != generated.end (); ++iter) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1177 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1178 delete iter->first; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1179 delete iter->second; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1180 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1181 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1182 |
15016 | 1183 void |
1184 jit_operation::add_overload (const jit_function& func, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1185 const std::vector<jit_type*>& args) |
15016 | 1186 { |
1187 if (args.size () >= overloads.size ()) | |
1188 overloads.resize (args.size () + 1); | |
1189 | |
1190 Array<jit_function>& over = overloads[args.size ()]; | |
1191 dim_vector dv (over.dims ()); | |
1192 Array<octave_idx_type> idx = to_idx (args); | |
1193 bool must_resize = false; | |
1194 | |
1195 if (dv.length () != idx.numel ()) | |
1196 { | |
1197 dv.resize (idx.numel ()); | |
1198 must_resize = true; | |
1199 } | |
1200 | |
1201 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
1202 if (dv(i) <= idx(i)) | |
1203 { | |
1204 must_resize = true; | |
1205 dv(i) = idx(i) + 1; | |
1206 } | |
1207 | |
1208 if (must_resize) | |
1209 over.resize (dv); | |
1210 | |
1211 over(idx) = func; | |
1212 } | |
1213 | |
1214 const jit_function& | |
1215 jit_operation::overload (const std::vector<jit_type*>& types) const | |
1216 { | |
1217 static jit_function null_overload; | |
1218 for (size_t i =0; i < types.size (); ++i) | |
1219 if (! types[i]) | |
1220 return null_overload; | |
1221 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1222 if (types.size () >= overloads.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1223 return do_generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1224 |
15016 | 1225 const Array<jit_function>& over = overloads[types.size ()]; |
1226 dim_vector dv (over.dims ()); | |
1227 Array<octave_idx_type> idx = to_idx (types); | |
1228 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
1229 if (idx(i) >= dv(i)) | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1230 return do_generate (types); |
15016 | 1231 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1232 const jit_function& ret = over(idx); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1233 if (! ret.valid ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1234 return do_generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1235 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1236 return ret; |
15016 | 1237 } |
1238 | |
1239 Array<octave_idx_type> | |
1240 jit_operation::to_idx (const std::vector<jit_type*>& types) const | |
1241 { | |
1242 octave_idx_type numel = types.size (); | |
18277
cc1c19863ae3
jit-typeinfo.cc: Fix C++ function ambiguity (bug #41145).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
18274
diff
changeset
|
1243 numel = std::max (numel, static_cast<octave_idx_type>(2)); |
15016 | 1244 |
1245 Array<octave_idx_type> idx (dim_vector (1, numel)); | |
1246 for (octave_idx_type i = 0; i < static_cast<octave_idx_type> (types.size ()); | |
1247 ++i) | |
1248 idx(i) = types[i]->type_id (); | |
1249 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1250 if (types.size () == 0) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1251 idx(0) = idx(1) = 0; |
15016 | 1252 if (types.size () == 1) |
1253 { | |
1254 idx(1) = idx(0); | |
1255 idx(0) = 0; | |
1256 } | |
1257 | |
1258 return idx; | |
1259 } | |
1260 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1261 const jit_function& |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1262 jit_operation::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
|
1263 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1264 static jit_function null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1265 generated_map::const_iterator find = generated.find (&types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1266 if (find != generated.end ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1267 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1268 if (find->second) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1269 return *find->second; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1270 else |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1271 return null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1272 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1273 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1274 jit_function *ret = generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1275 generated[new signature_vec (types)] = ret; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1276 return ret ? *ret : null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1277 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1278 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1279 jit_function * |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1280 jit_operation::generate (const signature_vec&) const |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1281 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1282 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1283 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1284 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1285 bool |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1286 jit_operation::signature_cmp |
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
|
1287 ::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
|
1288 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1289 const signature_vec& l = *lhs; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1290 const signature_vec& r = *rhs; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1291 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1292 if (l.size () < r.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1293 return true; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1294 else if (l.size () > r.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1295 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1296 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1297 for (size_t i = 0; i < l.size (); ++i) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1298 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1299 if (l[i]->type_id () < r[i]->type_id ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1300 return true; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1301 else if (l[i]->type_id () > r[i]->type_id ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1302 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1303 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1304 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1305 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1306 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1307 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1308 // -------------------- jit_index_operation -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1309 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1310 jit_index_operation::generate (const signature_vec& types) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1311 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1312 if (types.size () > 2 && types[0] == jit_typeinfo::get_matrix ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1313 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1314 // indexing a matrix with scalars |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1315 jit_type *scalar = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1316 for (size_t i = 1; i < types.size (); ++i) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1317 if (types[i] != scalar) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1318 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1319 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1320 return generate_matrix (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1321 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1322 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1323 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1324 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1325 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1326 llvm::Value * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1327 jit_index_operation::create_arg_array (llvm::IRBuilderD& builder, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1328 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
|
1329 size_t end_idx) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1330 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1331 size_t n = end_idx - start_idx; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1332 llvm::Type *scalar_t = jit_typeinfo::get_scalar_llvm (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1333 llvm::ArrayType *array_t = llvm::ArrayType::get (scalar_t, n); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1334 llvm::Value *array = llvm::UndefValue::get (array_t); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1335 for (size_t i = start_idx; i < end_idx; ++i) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1336 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1337 llvm::Value *idx = fn.argument (builder, i); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1338 array = builder.CreateInsertValue (array, idx, i - start_idx); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1339 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1340 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1341 llvm::Value *array_mem = builder.CreateAlloca (array_t); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1342 builder.CreateStore (array, array_mem); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1343 return builder.CreateBitCast (array_mem, scalar_t->getPointerTo ()); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1344 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1345 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1346 // -------------------- jit_paren_subsref -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1347 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1348 jit_paren_subsref::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
|
1349 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1350 std::stringstream ss; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1351 ss << "jit_paren_subsref_matrix_scalar" << (types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1352 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1353 jit_type *scalar = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1354 jit_function *fn = new jit_function (module, jit_convention::internal, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1355 ss.str (), scalar, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1356 fn->mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1357 llvm::BasicBlock *body = fn->new_block (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1358 llvm::IRBuilder<> builder (body); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1359 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1360 llvm::Value *array = create_arg_array (builder, *fn, 1, types.size ()); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1361 jit_type *index = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1362 llvm::Value *nelem = llvm::ConstantInt::get (index->to_llvm (), |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1363 types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1364 llvm::Value *mat = fn->argument (builder, 0); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1365 llvm::Value *ret = paren_scalar.call (builder, mat, array, nelem); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1366 fn->do_return (builder, ret); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1367 return fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1368 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1369 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1370 void |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1371 jit_paren_subsref::do_initialize (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1372 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1373 std::vector<jit_type *> types (3); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1374 types[0] = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1375 types[1] = jit_typeinfo::get_scalar_ptr (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1376 types[2] = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1377 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1378 jit_type *scalar = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1379 paren_scalar = jit_function (module, jit_convention::external, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1380 "octave_jit_paren_scalar", scalar, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1381 paren_scalar.add_mapping (engine, &octave_jit_paren_scalar); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1382 paren_scalar.mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1383 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1384 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1385 // -------------------- jit_paren_subsasgn -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1386 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1387 jit_paren_subsasgn::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
|
1388 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1389 std::stringstream ss; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1390 ss << "jit_paren_subsasgn_matrix_scalar" << (types.size () - 2); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1391 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1392 jit_type *matrix = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1393 jit_function *fn = new jit_function (module, jit_convention::internal, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1394 ss.str (), matrix, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1395 fn->mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1396 llvm::BasicBlock *body = fn->new_block (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1397 llvm::IRBuilder<> builder (body); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1398 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1399 llvm::Value *array = create_arg_array (builder, *fn, 1, types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1400 jit_type *index = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1401 llvm::Value *nelem = llvm::ConstantInt::get (index->to_llvm (), |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1402 types.size () - 2); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1403 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1404 llvm::Value *mat = fn->argument (builder, 0); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1405 llvm::Value *value = fn->argument (builder, types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1406 llvm::Value *ret = paren_scalar.call (builder, mat, array, nelem, value); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1407 fn->do_return (builder, ret); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1408 return fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1409 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1410 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1411 void |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1412 jit_paren_subsasgn::do_initialize (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1413 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1414 if (paren_scalar.valid ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1415 return; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1416 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1417 jit_type *matrix = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1418 std::vector<jit_type *> types (4); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1419 types[0] = matrix; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1420 types[1] = jit_typeinfo::get_scalar_ptr (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1421 types[2] = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1422 types[3] = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1423 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1424 paren_scalar = jit_function (module, jit_convention::external, |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1425 "octave_jit_paren_scalar", matrix, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1426 paren_scalar.add_mapping (engine, &octave_jit_paren_scalar_subsasgn); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1427 paren_scalar.mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1428 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1429 |
15016 | 1430 // -------------------- jit_typeinfo -------------------- |
1431 void | |
1432 jit_typeinfo::initialize (llvm::Module *m, llvm::ExecutionEngine *e) | |
1433 { | |
1434 new jit_typeinfo (m, e); | |
1435 } | |
1436 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1437 // wrap function names to simplify jit_typeinfo::create_external |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1438 #define JIT_FN(fn) engine, &fn, #fn |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1439 |
15016 | 1440 jit_typeinfo::jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e) |
1441 : module (m), engine (e), next_id (0), | |
1442 builder (*new llvm::IRBuilderD (context)) | |
1443 { | |
1444 instance = this; | |
1445 | |
1446 // FIXME: We should be registering types like in octave_value_typeinfo | |
1447 llvm::Type *any_t = llvm::StructType::create (context, "octave_base_value"); | |
1448 any_t = any_t->getPointerTo (); | |
1449 | |
1450 llvm::Type *scalar_t = llvm::Type::getDoubleTy (context); | |
18554 | 1451 llvm::Type *single_t = llvm::Type::getFloatTy (context); |
18557 | 1452 llvm::Type *int8__t = llvm::Type::getIntNTy (context, 8); |
18559 | 1453 llvm::Type *int16__t = llvm::Type::getIntNTy (context, 16); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1454 llvm::Type *int64__t = llvm::Type::getIntNTy (context, 64); |
18555 | 1455 llvm::Type *uint16__t = llvm::Type::getIntNTy (context, 16); |
15016 | 1456 llvm::Type *bool_t = llvm::Type::getInt1Ty (context); |
1457 llvm::Type *string_t = llvm::Type::getInt8Ty (context); | |
1458 string_t = string_t->getPointerTo (); | |
1459 llvm::Type *index_t = llvm::Type::getIntNTy (context, | |
1460 sizeof(octave_idx_type) * 8); | |
1461 | |
1462 llvm::StructType *range_t = llvm::StructType::create (context, "range"); | |
1463 std::vector<llvm::Type *> range_contents (4, scalar_t); | |
1464 range_contents[3] = index_t; | |
1465 range_t->setBody (range_contents); | |
1466 | |
1467 llvm::Type *refcount_t = llvm::Type::getIntNTy (context, sizeof(int) * 8); | |
1468 | |
1469 llvm::StructType *matrix_t = llvm::StructType::create (context, "matrix"); | |
1470 llvm::Type *matrix_contents[5]; | |
1471 matrix_contents[0] = refcount_t->getPointerTo (); | |
1472 matrix_contents[1] = scalar_t->getPointerTo (); | |
1473 matrix_contents[2] = index_t; | |
1474 matrix_contents[3] = index_t->getPointerTo (); | |
1475 matrix_contents[4] = string_t; | |
1476 matrix_t->setBody (llvm::makeArrayRef (matrix_contents, 5)); | |
1477 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1478 llvm::Type *complex_t = llvm::ArrayType::get (scalar_t, 2); |
15016 | 1479 |
1480 // complex_ret is what is passed to C functions in order to get calling | |
1481 // convention right | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1482 llvm::Type *cmplx_inner_cont[] = {scalar_t, scalar_t}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1483 llvm::StructType *cmplx_inner = llvm::StructType::create (cmplx_inner_cont); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1484 |
15016 | 1485 complex_ret = llvm::StructType::create (context, "complex_ret"); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1486 { |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1487 llvm::Type *contents[] = {cmplx_inner}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1488 complex_ret->setBody (contents); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1489 } |
15016 | 1490 |
1491 // create types | |
1492 any = new_type ("any", 0, any_t); | |
1493 matrix = new_type ("matrix", any, matrix_t); | |
1494 complex = new_type ("complex", any, complex_t); | |
1495 scalar = new_type ("scalar", complex, scalar_t); | |
18554 | 1496 single = new_type ("single", any, single_t); |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1497 scalar_ptr = new_type ("scalar_ptr", 0, scalar_t->getPointerTo ()); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1498 any_ptr = new_type ("any_ptr", 0, any_t->getPointerTo ()); |
15016 | 1499 range = new_type ("range", any, range_t); |
1500 string = new_type ("string", any, string_t); | |
1501 boolean = new_type ("bool", any, bool_t); | |
1502 index = new_type ("index", any, index_t); | |
1503 | |
1504 create_int (8); | |
1505 create_int (16); | |
1506 create_int (32); | |
1507 create_int (64); | |
1508 | |
18555 | 1509 create_uint (16); |
1510 | |
15016 | 1511 casts.resize (next_id + 1); |
1512 identities.resize (next_id + 1); | |
1513 | |
1514 // specify calling conventions | |
1515 // FIXME: We should detect architecture and do something sane based on that | |
1516 // here we assume x86 or x86_64 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1517 matrix->mark_sret (jit_convention::external); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1518 matrix->mark_pointer_arg (jit_convention::external); |
15016 | 1519 |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1520 range->mark_sret (jit_convention::external); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1521 range->mark_pointer_arg (jit_convention::external); |
15016 | 1522 |
1523 complex->set_pack (jit_convention::external, &jit_typeinfo::pack_complex); | |
1524 complex->set_unpack (jit_convention::external, &jit_typeinfo::unpack_complex); | |
1525 complex->set_packed_type (jit_convention::external, complex_ret); | |
1526 | |
1527 if (sizeof (void *) == 4) | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1528 complex->mark_sret (jit_convention::external); |
15016 | 1529 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1530 paren_subsref_fn.initialize (module, engine); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1531 paren_subsasgn_fn.initialize (module, engine); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1532 |
15016 | 1533 // bind global variables |
1534 lerror_state = new llvm::GlobalVariable (*module, bool_t, false, | |
1535 llvm::GlobalValue::ExternalLinkage, | |
1536 0, "error_state"); | |
1537 engine->addGlobalMapping (lerror_state, | |
1538 reinterpret_cast<void *> (&error_state)); | |
1539 | |
15603 | 1540 // sig_atomic_type is going to be some sort of integer |
1541 sig_atomic_type = llvm::Type::getIntNTy (context, sizeof(sig_atomic_t) * 8); | |
1542 loctave_interrupt_state | |
1543 = new llvm::GlobalVariable (*module, sig_atomic_type, false, | |
1544 llvm::GlobalValue::ExternalLinkage, 0, | |
1545 "octave_interrupt_state"); | |
1546 engine->addGlobalMapping (loctave_interrupt_state, | |
1547 reinterpret_cast<void *> (&octave_interrupt_state)); | |
1548 | |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1549 // generic call function |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1550 { |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1551 jit_type *int_t = intN (sizeof (octave_builtin::fcn) * 8); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1552 any_call = create_external (JIT_FN (octave_jit_call), any, int_t, int_t, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1553 any_ptr, int_t); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1554 } |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1555 |
15016 | 1556 // any with anything is an any op |
1557 jit_function fn; | |
1558 jit_type *binary_op_type = intN (sizeof (octave_value::binary_op) * 8); | |
1559 llvm::Type *llvm_bo_type = binary_op_type->to_llvm (); | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1560 jit_function any_binary = create_external (JIT_FN (octave_jit_binary_any_any), |
15016 | 1561 any, binary_op_type, any, any); |
1562 any_binary.mark_can_error (); | |
1563 binary_ops.resize (octave_value::num_binary_ops); | |
1564 for (size_t i = 0; i < octave_value::num_binary_ops; ++i) | |
1565 { | |
1566 octave_value::binary_op op = static_cast<octave_value::binary_op> (i); | |
1567 std::string op_name = octave_value::binary_op_as_string (op); | |
1568 binary_ops[i].stash_name ("binary" + op_name); | |
1569 } | |
1570 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1571 unary_ops.resize (octave_value::num_unary_ops); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1572 for (size_t i = 0; i < octave_value::num_unary_ops; ++i) |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1573 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1574 octave_value::unary_op op = static_cast<octave_value::unary_op> (i); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1575 std::string op_name = octave_value::unary_op_as_string (op); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1576 unary_ops[i].stash_name ("unary" + op_name); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1577 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1578 |
15016 | 1579 for (int op = 0; op < octave_value::num_binary_ops; ++op) |
1580 { | |
1581 llvm::Twine fn_name ("octave_jit_binary_any_any_"); | |
1582 fn_name = fn_name + llvm::Twine (op); | |
1583 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1584 fn = create_internal (fn_name, any, any, any); |
15016 | 1585 fn.mark_can_error (); |
1586 llvm::BasicBlock *block = fn.new_block (); | |
1587 builder.SetInsertPoint (block); | |
1588 llvm::APInt op_int(sizeof (octave_value::binary_op) * 8, op, | |
1589 std::numeric_limits<octave_value::binary_op>::is_signed); | |
1590 llvm::Value *op_as_llvm = llvm::ConstantInt::get (llvm_bo_type, op_int); | |
1591 llvm::Value *ret = any_binary.call (builder, op_as_llvm, | |
1592 fn.argument (builder, 0), | |
1593 fn.argument (builder, 1)); | |
1594 fn.do_return (builder, ret); | |
1595 binary_ops[op].add_overload (fn); | |
1596 } | |
1597 | |
1598 // grab matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1599 fn = create_external (JIT_FN (octave_jit_grab_matrix), matrix, matrix); |
15016 | 1600 grab_fn.add_overload (fn); |
1601 | |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1602 grab_fn.add_overload (create_identity (scalar)); |
18554 | 1603 grab_fn.add_overload (create_identity (single)); |
18557 | 1604 grab_fn.add_overload (create_identity (intN (8))); |
18559 | 1605 grab_fn.add_overload (create_identity (intN (16))); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1606 grab_fn.add_overload (create_identity (intN (64))); |
18555 | 1607 grab_fn.add_overload (create_identity (uintN (16))); |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1608 grab_fn.add_overload (create_identity (scalar_ptr)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1609 grab_fn.add_overload (create_identity (any_ptr)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1610 grab_fn.add_overload (create_identity (boolean)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1611 grab_fn.add_overload (create_identity (complex)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1612 grab_fn.add_overload (create_identity (index)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1613 |
15016 | 1614 // release any |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1615 fn = create_external (JIT_FN (octave_jit_release_any), 0, any); |
15016 | 1616 release_fn.add_overload (fn); |
1617 release_fn.stash_name ("release"); | |
1618 | |
1619 // release matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1620 fn = create_external (JIT_FN (octave_jit_release_matrix), 0, matrix); |
15016 | 1621 release_fn.add_overload (fn); |
1622 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1623 // destroy |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1624 destroy_fn = release_fn; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1625 destroy_fn.stash_name ("destroy"); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1626 destroy_fn.add_overload (create_identity(scalar)); |
18554 | 1627 destroy_fn.add_overload (create_identity(single)); |
18557 | 1628 destroy_fn.add_overload (create_identity(intN (8))); |
18559 | 1629 destroy_fn.add_overload (create_identity(intN (16))); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1630 destroy_fn.add_overload (create_identity(intN (64))); |
18555 | 1631 destroy_fn.add_overload (create_identity(uintN (16))); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1632 destroy_fn.add_overload (create_identity(boolean)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1633 destroy_fn.add_overload (create_identity(index)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1634 destroy_fn.add_overload (create_identity(complex)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1635 |
18323
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1636 // -------------------- scalar related operations -------------------- |
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1637 |
15016 | 1638 // now for binary scalar operations |
1639 add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); | |
1640 add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); | |
1641 add_binary_op (scalar, octave_value::op_mul, llvm::Instruction::FMul); | |
1642 add_binary_op (scalar, octave_value::op_el_mul, llvm::Instruction::FMul); | |
1643 | |
1644 add_binary_fcmp (scalar, octave_value::op_lt, llvm::CmpInst::FCMP_ULT); | |
1645 add_binary_fcmp (scalar, octave_value::op_le, llvm::CmpInst::FCMP_ULE); | |
1646 add_binary_fcmp (scalar, octave_value::op_eq, llvm::CmpInst::FCMP_UEQ); | |
1647 add_binary_fcmp (scalar, octave_value::op_ge, llvm::CmpInst::FCMP_UGE); | |
1648 add_binary_fcmp (scalar, octave_value::op_gt, llvm::CmpInst::FCMP_UGT); | |
1649 add_binary_fcmp (scalar, octave_value::op_ne, llvm::CmpInst::FCMP_UNE); | |
1650 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1651 jit_function gripe_div0 = create_external (JIT_FN (gripe_divide_by_zero), 0); |
15016 | 1652 gripe_div0.mark_can_error (); |
1653 | |
1654 // divide is annoying because it might error | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1655 fn = create_internal ("octave_jit_div_scalar_scalar", scalar, scalar, scalar); |
15016 | 1656 fn.mark_can_error (); |
1657 | |
1658 llvm::BasicBlock *body = fn.new_block (); | |
1659 builder.SetInsertPoint (body); | |
1660 { | |
1661 llvm::BasicBlock *warn_block = fn.new_block ("warn"); | |
1662 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
1663 | |
1664 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
15095
9df70a18aa27
Correct division by zero check in JIT
Max Brister <max@2bass.com>
parents:
15078
diff
changeset
|
1665 llvm::Value *check = builder.CreateFCmpUEQ (zero, fn.argument (builder, 1)); |
15016 | 1666 builder.CreateCondBr (check, warn_block, normal_block); |
1667 | |
1668 builder.SetInsertPoint (warn_block); | |
1669 gripe_div0.call (builder); | |
1670 builder.CreateBr (normal_block); | |
1671 | |
1672 builder.SetInsertPoint (normal_block); | |
1673 llvm::Value *ret = builder.CreateFDiv (fn.argument (builder, 0), | |
1674 fn.argument (builder, 1)); | |
1675 fn.do_return (builder, ret); | |
1676 } | |
1677 binary_ops[octave_value::op_div].add_overload (fn); | |
1678 binary_ops[octave_value::op_el_div].add_overload (fn); | |
1679 | |
1680 // ldiv is the same as div with the operators reversed | |
1681 fn = mirror_binary (fn); | |
1682 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
1683 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
1684 | |
1685 // In general, the result of scalar ^ scalar is a complex number. We might be | |
1686 // able to improve on this if we keep track of the range of values varaibles | |
1687 // can take on. | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1688 fn = create_external (JIT_FN (octave_jit_pow_scalar_scalar), complex, scalar, |
15016 | 1689 scalar); |
1690 binary_ops[octave_value::op_pow].add_overload (fn); | |
1691 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1692 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1693 // now for unary scalar operations |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1694 // FIXME: Impelment not |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1695 fn = create_internal ("octave_jit_++", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1696 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1697 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1698 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1699 llvm::Value *one = llvm::ConstantFP::get (scalar_t, 1); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1700 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1701 val = builder.CreateFAdd (val, one); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1702 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1703 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1704 unary_ops[octave_value::op_incr].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1705 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1706 fn = create_internal ("octave_jit_--", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1707 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1708 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1709 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1710 llvm::Value *one = llvm::ConstantFP::get (scalar_t, 1); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1711 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1712 val = builder.CreateFSub (val, one); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1713 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1714 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1715 unary_ops[octave_value::op_decr].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1716 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1717 fn = create_internal ("octave_jit_uminus", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1718 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1719 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1720 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1721 llvm::Value *mone = llvm::ConstantFP::get (scalar_t, -1); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1722 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1723 val = builder.CreateFMul (val, mone); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1724 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1725 } |
18323
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1726 unary_ops[octave_value::op_uminus].add_overload (fn); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1727 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1728 fn = create_identity (scalar); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1729 unary_ops[octave_value::op_uplus].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1730 unary_ops[octave_value::op_transpose].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1731 unary_ops[octave_value::op_hermitian].add_overload (fn); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1732 |
18554 | 1733 /************************************************************ |
1734 * | |
1735 * complex related operations | |
1736 * | |
1737 ************************************************************/ | |
1738 | |
15016 | 1739 // now for binary complex operations |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1740 fn = create_internal ("octave_jit_+_complex_complex", complex, complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1741 complex); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1742 body = fn.new_block (); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1743 builder.SetInsertPoint (body); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1744 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1745 llvm::Value *lhs = fn.argument (builder, 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1746 llvm::Value *rhs = fn.argument (builder, 1); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1747 llvm::Value *real = builder.CreateFAdd (complex_real (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1748 complex_real (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1749 llvm::Value *imag = builder.CreateFAdd (complex_imag (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1750 complex_imag (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1751 fn.do_return (builder, complex_new (real, imag)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1752 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1753 binary_ops[octave_value::op_add].add_overload (fn); |
15016 | 1754 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1755 fn = create_internal ("octave_jit_-_complex_complex", complex, complex, |
15016 | 1756 complex); |
1757 body = fn.new_block (); | |
1758 builder.SetInsertPoint (body); | |
1759 { | |
1760 llvm::Value *lhs = fn.argument (builder, 0); | |
1761 llvm::Value *rhs = fn.argument (builder, 1); | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1762 llvm::Value *real = builder.CreateFSub (complex_real (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1763 complex_real (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1764 llvm::Value *imag = builder.CreateFSub (complex_imag (lhs), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1765 complex_imag (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1766 fn.do_return (builder, complex_new (real, imag)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1767 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1768 binary_ops[octave_value::op_sub].add_overload (fn); |
15016 | 1769 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1770 fn = create_external (JIT_FN (octave_jit_complex_mul), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1771 complex, complex, complex); |
15016 | 1772 binary_ops[octave_value::op_mul].add_overload (fn); |
1773 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
1774 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1775 jit_function complex_div = create_external (JIT_FN (octave_jit_complex_div), |
15016 | 1776 complex, complex, complex); |
1777 complex_div.mark_can_error (); | |
1778 binary_ops[octave_value::op_div].add_overload (fn); | |
1779 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
1780 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1781 fn = create_external (JIT_FN (octave_jit_pow_complex_complex), complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1782 complex, complex); |
15016 | 1783 binary_ops[octave_value::op_pow].add_overload (fn); |
1784 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1785 | |
18554 | 1786 /************************************************************ |
1787 * | |
1788 * single related operations | |
1789 * | |
1790 ************************************************************/ | |
1791 | |
1792 // now for binary single operations | |
1793 add_binary_op (single, octave_value::op_add, llvm::Instruction::FAdd); | |
1794 add_binary_op (single, octave_value::op_sub, llvm::Instruction::FSub); | |
1795 add_binary_op (single, octave_value::op_mul, llvm::Instruction::FMul); | |
1796 add_binary_op (single, octave_value::op_el_mul, llvm::Instruction::FMul); | |
1797 | |
1798 add_binary_fcmp (single, octave_value::op_lt, llvm::CmpInst::FCMP_ULT); | |
1799 add_binary_fcmp (single, octave_value::op_le, llvm::CmpInst::FCMP_ULE); | |
1800 add_binary_fcmp (single, octave_value::op_eq, llvm::CmpInst::FCMP_UEQ); | |
1801 add_binary_fcmp (single, octave_value::op_ge, llvm::CmpInst::FCMP_UGE); | |
1802 add_binary_fcmp (single, octave_value::op_gt, llvm::CmpInst::FCMP_UGT); | |
1803 add_binary_fcmp (single, octave_value::op_ne, llvm::CmpInst::FCMP_UNE); | |
1804 | |
1805 // divide is annoying because it might error | |
1806 fn = create_internal ("octave_jit_div_single_single", single, single, single); | |
1807 fn.mark_can_error (); | |
1808 | |
1809 body = fn.new_block (); | |
1810 builder.SetInsertPoint (body); | |
1811 { | |
1812 llvm::BasicBlock *warn_block = fn.new_block ("warn"); | |
1813 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
1814 | |
1815 llvm::Value *zero = llvm::ConstantFP::get (single_t, 0); | |
1816 llvm::Value *check = builder.CreateFCmpUEQ (zero, fn.argument (builder, 1)); | |
1817 builder.CreateCondBr (check, warn_block, normal_block); | |
1818 | |
1819 builder.SetInsertPoint (warn_block); | |
1820 gripe_div0.call (builder); | |
1821 builder.CreateBr (normal_block); | |
1822 | |
1823 builder.SetInsertPoint (normal_block); | |
1824 llvm::Value *ret = builder.CreateFDiv (fn.argument (builder, 0), | |
1825 fn.argument (builder, 1)); | |
1826 fn.do_return (builder, ret); | |
1827 } | |
1828 binary_ops[octave_value::op_div].add_overload (fn); | |
1829 binary_ops[octave_value::op_el_div].add_overload (fn); | |
1830 | |
1831 // ldiv is the same as div with the operators reversed | |
1832 fn = mirror_binary (fn); | |
1833 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
1834 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
1835 | |
1836 // In general, the result of scalar ^ scalar is a complex number. We might be | |
1837 // able to improve on this if we keep track of the range of values varaibles | |
1838 // can take on. | |
1839 fn = create_external (JIT_FN (octave_jit_pow_single_single), complex, single, | |
1840 single); | |
1841 binary_ops[octave_value::op_pow].add_overload (fn); | |
1842 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1843 | |
1844 // now for unary single operations | |
1845 // FIXME: Impelment not | |
1846 fn = create_internal ("octave_jit_++", single, single); | |
1847 body = fn.new_block (); | |
1848 builder.SetInsertPoint (body); | |
1849 { | |
1850 llvm::Value *one = llvm::ConstantFP::get (single_t, 1); | |
1851 llvm::Value *val = fn.argument (builder, 0); | |
1852 val = builder.CreateFAdd (val, one); | |
1853 fn.do_return (builder, val); | |
1854 } | |
1855 unary_ops[octave_value::op_incr].add_overload (fn); | |
1856 | |
1857 fn = create_internal ("octave_jit_--", single, single); | |
1858 body = fn.new_block (); | |
1859 builder.SetInsertPoint (body); | |
1860 { | |
1861 llvm::Value *one = llvm::ConstantFP::get (single_t, 1); | |
1862 llvm::Value *val = fn.argument (builder, 0); | |
1863 val = builder.CreateFSub (val, one); | |
1864 fn.do_return (builder, val); | |
1865 } | |
1866 unary_ops[octave_value::op_decr].add_overload (fn); | |
1867 | |
1868 fn = create_internal ("octave_jit_uminus", single, single); | |
1869 body = fn.new_block (); | |
1870 builder.SetInsertPoint (body); | |
1871 { | |
1872 llvm::Value *mone = llvm::ConstantFP::get (single_t, -1); | |
1873 llvm::Value *val = fn.argument (builder, 0); | |
1874 val = builder.CreateFMul (val, mone); | |
1875 fn.do_return (builder, val); | |
1876 } | |
1877 unary_ops[octave_value::op_uminus].add_overload (fn); | |
1878 | |
1879 fn = create_identity (single); | |
1880 unary_ops[octave_value::op_uplus].add_overload (fn); | |
1881 unary_ops[octave_value::op_transpose].add_overload (fn); | |
1882 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
1883 | |
18555 | 1884 /************************************************************ |
1885 * | |
18557 | 1886 * int8 related operations |
1887 * | |
1888 ************************************************************/ | |
1889 | |
1890 // now for binary int8 operations | |
1891 fn = create_external (JIT_FN (octave_jit_add_int8_int8), intN (8), intN (8), | |
1892 intN (8)); | |
1893 binary_ops[octave_value::op_add].add_overload (fn); | |
1894 fn = create_external (JIT_FN (octave_jit_sub_int8_int8), intN (8), intN (8), | |
1895 intN (8)); | |
1896 binary_ops[octave_value::op_sub].add_overload (fn); | |
1897 fn = create_external (JIT_FN (octave_jit_mul_int8_int8), intN (8), intN (8), | |
1898 intN (8)); | |
1899 binary_ops[octave_value::op_mul].add_overload (fn); | |
1900 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
1901 | |
1902 add_binary_icmp (intN (8), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); | |
1903 add_binary_icmp (intN (8), octave_value::op_le, llvm::CmpInst::ICMP_SLE); | |
1904 add_binary_icmp (intN (8), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
1905 add_binary_icmp (intN (8), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); | |
1906 add_binary_icmp (intN (8), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); | |
1907 add_binary_icmp (intN (8), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
1908 | |
1909 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. | |
1910 // divide is annoying because it might error | |
1911 // FIXME: Implement div | |
1912 | |
1913 // FIXME: Implement pow | |
1914 | |
1915 // now for unary int8 operations | |
1916 // FIXME: Impelment not | |
1917 fn = create_external (JIT_FN (octave_jit_incr_int8), intN (8), intN (8)); | |
1918 unary_ops[octave_value::op_incr].add_overload (fn); | |
1919 | |
1920 fn = create_external (JIT_FN (octave_jit_decr_int8), intN (8), intN (8)); | |
1921 unary_ops[octave_value::op_decr].add_overload (fn); | |
1922 | |
1923 fn = create_internal ("octave_jit_uminus", intN (8), intN (8)); | |
1924 body = fn.new_block (); | |
1925 builder.SetInsertPoint (body); | |
1926 { | |
1927 llvm::Value *mone = llvm::ConstantInt::get (int8__t, -1); | |
1928 llvm::Value *val = fn.argument (builder, 0); | |
1929 val = builder.CreateMul (val, mone); | |
1930 fn.do_return (builder, val); | |
1931 } | |
1932 unary_ops[octave_value::op_uminus].add_overload (fn); | |
1933 | |
1934 fn = create_identity (intN (8)); | |
1935 unary_ops[octave_value::op_uplus].add_overload (fn); | |
1936 unary_ops[octave_value::op_transpose].add_overload (fn); | |
1937 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
1938 | |
1939 /************************************************************ | |
1940 * | |
18559 | 1941 * int16 related operations |
1942 * | |
1943 ************************************************************/ | |
1944 | |
1945 // now for binary int16 operations | |
1946 fn = create_external (JIT_FN (octave_jit_add_int16_int16), intN (16), intN (16), | |
1947 intN (16)); | |
1948 binary_ops[octave_value::op_add].add_overload (fn); | |
1949 fn = create_external (JIT_FN (octave_jit_sub_int16_int16), intN (16), intN (16), | |
1950 intN (16)); | |
1951 binary_ops[octave_value::op_sub].add_overload (fn); | |
1952 fn = create_external (JIT_FN (octave_jit_mul_int16_int16), intN (16), intN (16), | |
1953 intN (16)); | |
1954 binary_ops[octave_value::op_mul].add_overload (fn); | |
1955 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
1956 | |
1957 add_binary_icmp (intN (16), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); | |
1958 add_binary_icmp (intN (16), octave_value::op_le, llvm::CmpInst::ICMP_SLE); | |
1959 add_binary_icmp (intN (16), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
1960 add_binary_icmp (intN (16), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); | |
1961 add_binary_icmp (intN (16), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); | |
1962 add_binary_icmp (intN (16), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
1963 | |
1964 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. | |
1965 // divide is annoying because it might error | |
1966 // FIXME: Implement div | |
1967 | |
1968 // FIXME: Implement pow | |
1969 | |
1970 // now for unary int16 operations | |
1971 // FIXME: Impelment not | |
1972 fn = create_external (JIT_FN (octave_jit_incr_int16), intN (16), intN (16)); | |
1973 unary_ops[octave_value::op_incr].add_overload (fn); | |
1974 | |
1975 fn = create_external (JIT_FN (octave_jit_decr_int16), intN (16), intN (16)); | |
1976 unary_ops[octave_value::op_decr].add_overload (fn); | |
1977 | |
1978 fn = create_internal ("octave_jit_uminus", intN (16), intN (16)); | |
1979 body = fn.new_block (); | |
1980 builder.SetInsertPoint (body); | |
1981 { | |
1982 llvm::Value *mone = llvm::ConstantInt::get (int16__t, -1); | |
1983 llvm::Value *val = fn.argument (builder, 0); | |
1984 val = builder.CreateMul (val, mone); | |
1985 fn.do_return (builder, val); | |
1986 } | |
1987 unary_ops[octave_value::op_uminus].add_overload (fn); | |
1988 | |
1989 fn = create_identity (intN (16)); | |
1990 unary_ops[octave_value::op_uplus].add_overload (fn); | |
1991 unary_ops[octave_value::op_transpose].add_overload (fn); | |
1992 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
1993 | |
1994 /************************************************************ | |
1995 * | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1996 * int64 related operations |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1997 * |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1998 ************************************************************/ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
1999 |
18559 | 2000 // FIXME: interpreter overflow occurs at minus + minus, minus - plus |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2001 // now for binary int64 operations |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2002 fn = create_external (JIT_FN (octave_jit_add_int64_int64), intN (64), intN (64), |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2003 intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2004 binary_ops[octave_value::op_add].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2005 fn = create_external (JIT_FN (octave_jit_sub_int64_int64), intN (64), intN (64), |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2006 intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2007 binary_ops[octave_value::op_sub].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2008 fn = create_external (JIT_FN (octave_jit_mul_int64_int64), intN (64), intN (64), |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2009 intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2010 binary_ops[octave_value::op_mul].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2011 binary_ops[octave_value::op_el_mul].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2012 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2013 add_binary_icmp (intN (64), octave_value::op_lt, llvm::CmpInst::ICMP_SLT); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2014 add_binary_icmp (intN (64), octave_value::op_le, llvm::CmpInst::ICMP_SLE); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2015 add_binary_icmp (intN (64), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2016 add_binary_icmp (intN (64), octave_value::op_ge, llvm::CmpInst::ICMP_SGE); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2017 add_binary_icmp (intN (64), octave_value::op_gt, llvm::CmpInst::ICMP_SGT); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2018 add_binary_icmp (intN (64), octave_value::op_ne, llvm::CmpInst::ICMP_NE); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2019 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2020 // FIXME: saturation divide definition? interpreter convert int to double, calculate and round. |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2021 // divide is annoying because it might error |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2022 // FIXME: Implement div |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2023 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2024 // FIXME: Implement pow |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2025 |
18559 | 2026 // now for unary int64 operations |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2027 // FIXME: Impelment not |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2028 fn = create_external (JIT_FN (octave_jit_incr_int64), intN (64), intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2029 unary_ops[octave_value::op_incr].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2030 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2031 fn = create_external (JIT_FN (octave_jit_decr_int64), intN (64), intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2032 unary_ops[octave_value::op_decr].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2033 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2034 fn = create_internal ("octave_jit_uminus", intN (64), intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2035 body = fn.new_block (); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2036 builder.SetInsertPoint (body); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2037 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2038 llvm::Value *mone = llvm::ConstantInt::get (int64__t, -1); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2039 llvm::Value *val = fn.argument (builder, 0); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2040 val = builder.CreateMul (val, mone); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2041 fn.do_return (builder, val); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2042 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2043 unary_ops[octave_value::op_uminus].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2044 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2045 fn = create_identity (intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2046 unary_ops[octave_value::op_uplus].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2047 unary_ops[octave_value::op_transpose].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2048 unary_ops[octave_value::op_hermitian].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2049 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2050 /************************************************************ |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2051 * |
18555 | 2052 * uint16 related operations |
2053 * | |
2054 ************************************************************/ | |
2055 | |
2056 // now for binary uint16 operations | |
2057 fn = create_external (JIT_FN (octave_jit_add_uint16_uint16), uintN (16), uintN (16), | |
2058 uintN (16)); | |
2059 binary_ops[octave_value::op_add].add_overload (fn); | |
2060 fn = create_external (JIT_FN (octave_jit_sub_uint16_uint16), uintN (16), uintN (16), | |
2061 uintN (16)); | |
2062 binary_ops[octave_value::op_sub].add_overload (fn); | |
2063 fn = create_external (JIT_FN (octave_jit_mul_uint16_uint16), uintN (16), uintN (16), | |
2064 uintN (16)); | |
2065 binary_ops[octave_value::op_mul].add_overload (fn); | |
2066 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2067 | |
2068 add_binary_icmp (uintN (16), octave_value::op_lt, llvm::CmpInst::ICMP_ULT); | |
2069 add_binary_icmp (uintN (16), octave_value::op_le, llvm::CmpInst::ICMP_ULE); | |
2070 add_binary_icmp (uintN (16), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); | |
2071 add_binary_icmp (uintN (16), octave_value::op_ge, llvm::CmpInst::ICMP_UGE); | |
2072 add_binary_icmp (uintN (16), octave_value::op_gt, llvm::CmpInst::ICMP_UGT); | |
2073 add_binary_icmp (uintN (16), octave_value::op_ne, llvm::CmpInst::ICMP_NE); | |
2074 | |
2075 // FIXME: saturation divide definition? interpreter convert uint to double, calculate and round. | |
2076 // divide is annoying because it might error | |
2077 #if 0 | |
2078 fn = create_internal ("octave_jit_div_uint16_uint16", uintN (16), uintN (16), uintN (16)); | |
2079 fn.mark_can_error (); | |
2080 | |
2081 body = fn.new_block (); | |
2082 builder.SetInsertPoint (body); | |
2083 { | |
2084 llvm::BasicBlock *warn_block = fn.new_block ("warn"); | |
2085 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
2086 | |
2087 llvm::Value *zero = llvm::ConstantInt::get (uint16__t, 0); | |
2088 llvm::Value *check = builder.CreateICmpEQ (zero, fn.argument (builder, 1)); | |
2089 builder.CreateCondBr (check, warn_block, normal_block); | |
2090 | |
2091 builder.SetInsertPoint (warn_block); | |
2092 gripe_div0.call (builder); | |
2093 builder.CreateBr (normal_block); | |
2094 | |
2095 builder.SetInsertPoint (normal_block); | |
2096 llvm::Value *ret = builder.CreateUDiv (fn.argument (builder, 0), | |
2097 fn.argument (builder, 1)); | |
2098 fn.do_return (builder, ret); | |
2099 } | |
2100 binary_ops[octave_value::op_div].add_overload (fn); | |
2101 binary_ops[octave_value::op_el_div].add_overload (fn); | |
2102 | |
2103 // ldiv is the same as div with the operators reversed | |
2104 fn = mirror_binary (fn); | |
2105 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
2106 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
2107 #endif | |
2108 | |
2109 // FIXME: Implement pow | |
2110 | |
2111 // now for unary uint16 operations | |
2112 // FIXME: Impelment not | |
2113 fn = create_external (JIT_FN (octave_jit_incr_uint16), uintN (16), uintN (16)); | |
2114 unary_ops[octave_value::op_incr].add_overload (fn); | |
2115 | |
2116 fn = create_external (JIT_FN (octave_jit_decr_uint16), uintN (16), uintN (16)); | |
2117 unary_ops[octave_value::op_decr].add_overload (fn); | |
2118 | |
2119 fn = create_internal ("octave_jit_uminus", uintN (16), uintN (16)); | |
2120 body = fn.new_block (); | |
2121 builder.SetInsertPoint (body); | |
2122 { | |
2123 llvm::Value *zero = llvm::ConstantInt::get (uint16__t, 0); | |
2124 | |
2125 fn.do_return (builder, zero); | |
2126 } | |
2127 unary_ops[octave_value::op_uminus].add_overload (fn); | |
2128 | |
2129 fn = create_identity (uintN (16)); | |
2130 unary_ops[octave_value::op_uplus].add_overload (fn); | |
2131 unary_ops[octave_value::op_transpose].add_overload (fn); | |
2132 unary_ops[octave_value::op_hermitian].add_overload (fn); | |
2133 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2134 fn = create_internal ("octave_jit_*_scalar_complex", complex, scalar, |
15016 | 2135 complex); |
2136 jit_function mul_scalar_complex = fn; | |
2137 body = fn.new_block (); | |
2138 builder.SetInsertPoint (body); | |
2139 { | |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2140 llvm::BasicBlock *complex_mul = fn.new_block ("complex_mul"); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2141 llvm::BasicBlock *scalar_mul = fn.new_block ("scalar_mul"); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2142 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2143 llvm::Value *fzero = llvm::ConstantFP::get (scalar_t, 0); |
15016 | 2144 llvm::Value *lhs = fn.argument (builder, 0); |
2145 llvm::Value *rhs = fn.argument (builder, 1); | |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2146 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2147 llvm::Value *cmp = builder.CreateFCmpUEQ (complex_imag (rhs), fzero); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2148 builder.CreateCondBr (cmp, scalar_mul, complex_mul); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2149 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2150 builder.SetInsertPoint (scalar_mul); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2151 llvm::Value *temp = complex_real (rhs); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2152 temp = builder.CreateFMul (lhs, temp); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2153 fn.do_return (builder, complex_new (temp, fzero), false); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2154 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2155 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2156 builder.SetInsertPoint (complex_mul); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2157 temp = complex_new (builder.CreateFMul (lhs, complex_real (rhs)), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2158 builder.CreateFMul (lhs, complex_imag (rhs))); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2159 fn.do_return (builder, temp); |
15016 | 2160 } |
2161 binary_ops[octave_value::op_mul].add_overload (fn); | |
2162 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2163 | |
2164 | |
2165 fn = mirror_binary (mul_scalar_complex); | |
2166 binary_ops[octave_value::op_mul].add_overload (fn); | |
2167 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
2168 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2169 fn = create_internal ("octave_jit_+_scalar_complex", complex, scalar, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2170 complex); |
15016 | 2171 body = fn.new_block (); |
2172 builder.SetInsertPoint (body); | |
2173 { | |
2174 llvm::Value *lhs = fn.argument (builder, 0); | |
2175 llvm::Value *rhs = fn.argument (builder, 1); | |
2176 llvm::Value *real = builder.CreateFAdd (lhs, complex_real (rhs)); | |
2177 fn.do_return (builder, complex_real (rhs, real)); | |
2178 } | |
2179 binary_ops[octave_value::op_add].add_overload (fn); | |
2180 | |
2181 fn = mirror_binary (fn); | |
2182 binary_ops[octave_value::op_add].add_overload (fn); | |
2183 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2184 fn = create_internal ("octave_jit_-_complex_scalar", complex, complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2185 scalar); |
15016 | 2186 body = fn.new_block (); |
2187 builder.SetInsertPoint (body); | |
2188 { | |
2189 llvm::Value *lhs = fn.argument (builder, 0); | |
2190 llvm::Value *rhs = fn.argument (builder, 1); | |
2191 llvm::Value *real = builder.CreateFSub (complex_real (lhs), rhs); | |
2192 fn.do_return (builder, complex_real (lhs, real)); | |
2193 } | |
2194 binary_ops[octave_value::op_sub].add_overload (fn); | |
2195 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2196 fn = create_internal ("octave_jit_-_scalar_complex", complex, scalar, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2197 complex); |
15016 | 2198 body = fn.new_block (); |
2199 builder.SetInsertPoint (body); | |
2200 { | |
2201 llvm::Value *lhs = fn.argument (builder, 0); | |
2202 llvm::Value *rhs = fn.argument (builder, 1); | |
2203 llvm::Value *real = builder.CreateFSub (lhs, complex_real (rhs)); | |
2204 fn.do_return (builder, complex_real (rhs, real)); | |
2205 } | |
2206 binary_ops[octave_value::op_sub].add_overload (fn); | |
2207 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2208 fn = create_external (JIT_FN (octave_jit_pow_scalar_complex), complex, scalar, |
15016 | 2209 complex); |
2210 binary_ops[octave_value::op_pow].add_overload (fn); | |
2211 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
2212 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2213 fn = create_external (JIT_FN (octave_jit_pow_complex_scalar), complex, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2214 complex, scalar); |
15016 | 2215 binary_ops[octave_value::op_pow].add_overload (fn); |
2216 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
2217 | |
2218 // now for binary index operators | |
2219 add_binary_op (index, octave_value::op_add, llvm::Instruction::Add); | |
2220 | |
2221 // and binary bool operators | |
2222 add_binary_op (boolean, octave_value::op_el_or, llvm::Instruction::Or); | |
2223 add_binary_op (boolean, octave_value::op_el_and, llvm::Instruction::And); | |
2224 | |
2225 // now for printing functions | |
2226 print_fn.stash_name ("print"); | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2227 add_print (any, reinterpret_cast<void *> (&octave_jit_print_any)); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2228 add_print (scalar, reinterpret_cast<void *> (&octave_jit_print_scalar)); |
15016 | 2229 |
2230 // initialize for loop | |
2231 for_init_fn.stash_name ("for_init"); | |
2232 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2233 fn = create_internal ("octave_jit_for_range_init", index, range); |
15016 | 2234 body = fn.new_block (); |
2235 builder.SetInsertPoint (body); | |
2236 { | |
2237 llvm::Value *zero = llvm::ConstantInt::get (index_t, 0); | |
2238 fn.do_return (builder, zero); | |
2239 } | |
2240 for_init_fn.add_overload (fn); | |
2241 | |
2242 // bounds check for for loop | |
2243 for_check_fn.stash_name ("for_check"); | |
2244 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2245 fn = create_internal ("octave_jit_for_range_check", boolean, range, index); |
15016 | 2246 body = fn.new_block (); |
2247 builder.SetInsertPoint (body); | |
2248 { | |
2249 llvm::Value *nelem | |
2250 = builder.CreateExtractValue (fn.argument (builder, 0), 3); | |
2251 llvm::Value *idx = fn.argument (builder, 1); | |
2252 llvm::Value *ret = builder.CreateICmpULT (idx, nelem); | |
2253 fn.do_return (builder, ret); | |
2254 } | |
2255 for_check_fn.add_overload (fn); | |
2256 | |
2257 // index variabe for for loop | |
2258 for_index_fn.stash_name ("for_index"); | |
2259 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2260 fn = create_internal ("octave_jit_for_range_idx", scalar, range, index); |
15016 | 2261 body = fn.new_block (); |
2262 builder.SetInsertPoint (body); | |
2263 { | |
2264 llvm::Value *idx = fn.argument (builder, 1); | |
2265 llvm::Value *didx = builder.CreateSIToFP (idx, scalar_t); | |
2266 llvm::Value *rng = fn.argument (builder, 0); | |
2267 llvm::Value *base = builder.CreateExtractValue (rng, 0); | |
2268 llvm::Value *inc = builder.CreateExtractValue (rng, 2); | |
2269 | |
2270 llvm::Value *ret = builder.CreateFMul (didx, inc); | |
2271 ret = builder.CreateFAdd (base, ret); | |
2272 fn.do_return (builder, ret); | |
2273 } | |
2274 for_index_fn.add_overload (fn); | |
2275 | |
2276 // logically true | |
2277 logically_true_fn.stash_name ("logically_true"); | |
2278 | |
2279 jit_function gripe_nantl | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2280 = create_external (JIT_FN (octave_jit_gripe_nan_to_logical_conversion), 0); |
15016 | 2281 gripe_nantl.mark_can_error (); |
2282 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2283 fn = create_internal ("octave_jit_logically_true_scalar", boolean, scalar); |
15016 | 2284 fn.mark_can_error (); |
2285 | |
2286 body = fn.new_block (); | |
2287 builder.SetInsertPoint (body); | |
2288 { | |
2289 llvm::BasicBlock *error_block = fn.new_block ("error"); | |
2290 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
2291 | |
2292 llvm::Value *check = builder.CreateFCmpUNE (fn.argument (builder, 0), | |
2293 fn.argument (builder, 0)); | |
2294 builder.CreateCondBr (check, error_block, normal_block); | |
2295 | |
2296 builder.SetInsertPoint (error_block); | |
2297 gripe_nantl.call (builder); | |
2298 builder.CreateBr (normal_block); | |
2299 builder.SetInsertPoint (normal_block); | |
2300 | |
2301 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
2302 llvm::Value *ret = builder.CreateFCmpONE (fn.argument (builder, 0), zero); | |
2303 fn.do_return (builder, ret); | |
2304 } | |
2305 logically_true_fn.add_overload (fn); | |
2306 | |
2307 // logically_true boolean | |
2308 fn = create_identity (boolean); | |
2309 logically_true_fn.add_overload (fn); | |
2310 | |
2311 // make_range | |
2312 // FIXME: May be benificial to implement all in LLVM | |
2313 make_range_fn.stash_name ("make_range"); | |
2314 jit_function compute_nelem | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2315 = create_external (JIT_FN (octave_jit_compute_nelem), |
15016 | 2316 index, scalar, scalar, scalar); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2317 |
15016 | 2318 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2319 fn = create_internal ("octave_jit_make_range", range, scalar, scalar, scalar); |
15016 | 2320 body = fn.new_block (); |
2321 builder.SetInsertPoint (body); | |
2322 { | |
2323 llvm::Value *base = fn.argument (builder, 0); | |
2324 llvm::Value *limit = fn.argument (builder, 1); | |
2325 llvm::Value *inc = fn.argument (builder, 2); | |
2326 llvm::Value *nelem = compute_nelem.call (builder, base, limit, inc); | |
2327 | |
2328 llvm::Value *dzero = llvm::ConstantFP::get (scalar_t, 0); | |
2329 llvm::Value *izero = llvm::ConstantInt::get (index_t, 0); | |
2330 llvm::Value *rng = llvm::ConstantStruct::get (range_t, dzero, dzero, dzero, | |
2331 izero, NULL); | |
2332 rng = builder.CreateInsertValue (rng, base, 0); | |
2333 rng = builder.CreateInsertValue (rng, limit, 1); | |
2334 rng = builder.CreateInsertValue (rng, inc, 2); | |
2335 rng = builder.CreateInsertValue (rng, nelem, 3); | |
2336 fn.do_return (builder, rng); | |
2337 } | |
2338 make_range_fn.add_overload (fn); | |
2339 | |
2340 // paren_subsref | |
2341 jit_type *jit_int = intN (sizeof (int) * 8); | |
2342 llvm::Type *int_t = jit_int->to_llvm (); | |
2343 jit_function ginvalid_index | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2344 = create_external (JIT_FN (octave_jit_ginvalid_index), 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2345 jit_function gindex_range = create_external (JIT_FN (octave_jit_gindex_range), |
15016 | 2346 0, jit_int, jit_int, index, |
2347 index); | |
2348 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2349 fn = create_internal ("()subsref", scalar, matrix, scalar); |
15016 | 2350 fn.mark_can_error (); |
2351 | |
2352 body = fn.new_block (); | |
2353 builder.SetInsertPoint (body); | |
2354 { | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2355 llvm::Value *one_idx = llvm::ConstantInt::get (index_t, 1); |
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2356 llvm::Value *one_int = llvm::ConstantInt::get (int_t, 1); |
15016 | 2357 |
2358 llvm::Value *undef = llvm::UndefValue::get (scalar_t); | |
2359 llvm::Value *mat = fn.argument (builder, 0); | |
2360 llvm::Value *idx = fn.argument (builder, 1); | |
2361 | |
2362 // convert index to scalar to integer, and check index >= 1 | |
2363 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); | |
2364 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); | |
2365 llvm::Value *cond0 = builder.CreateFCmpUNE (idx, check_idx); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2366 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one_idx); |
15016 | 2367 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
2368 | |
2369 llvm::BasicBlock *done = fn.new_block ("done"); | |
2370 llvm::BasicBlock *conv_error = fn.new_block ("conv_error", done); | |
2371 llvm::BasicBlock *normal = fn.new_block ("normal", done); | |
2372 builder.CreateCondBr (cond, conv_error, normal); | |
2373 | |
2374 builder.SetInsertPoint (conv_error); | |
2375 ginvalid_index.call (builder); | |
2376 builder.CreateBr (done); | |
2377 | |
2378 builder.SetInsertPoint (normal); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2379 llvm::Value *len |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2380 = builder.CreateExtractValue (mat, llvm::ArrayRef<unsigned> (2)); |
15016 | 2381 cond = builder.CreateICmpSGT (int_idx, len); |
2382 | |
2383 | |
2384 llvm::BasicBlock *bounds_error = fn.new_block ("bounds_error", done); | |
2385 llvm::BasicBlock *success = fn.new_block ("success", done); | |
2386 builder.CreateCondBr (cond, bounds_error, success); | |
2387 | |
2388 builder.SetInsertPoint (bounds_error); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2389 gindex_range.call (builder, one_int, one_int, int_idx, len); |
15016 | 2390 builder.CreateBr (done); |
2391 | |
2392 builder.SetInsertPoint (success); | |
2393 llvm::Value *data = builder.CreateExtractValue (mat, | |
2394 llvm::ArrayRef<unsigned> (1)); | |
2395 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); | |
2396 llvm::Value *ret = builder.CreateLoad (gep); | |
2397 builder.CreateBr (done); | |
2398 | |
2399 builder.SetInsertPoint (done); | |
2400 | |
2401 llvm::PHINode *merge = llvm::PHINode::Create (scalar_t, 3); | |
2402 builder.Insert (merge); | |
2403 merge->addIncoming (undef, conv_error); | |
2404 merge->addIncoming (undef, bounds_error); | |
2405 merge->addIncoming (ret, success); | |
2406 fn.do_return (builder, merge); | |
2407 } | |
2408 paren_subsref_fn.add_overload (fn); | |
2409 | |
2410 // paren subsasgn | |
2411 paren_subsasgn_fn.stash_name ("()subsasgn"); | |
2412 | |
2413 jit_function resize_paren_subsasgn | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2414 = create_external (JIT_FN (octave_jit_paren_subsasgn_impl), matrix, matrix, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2415 index, scalar); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2416 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2417 fn = create_internal ("octave_jit_paren_subsasgn", matrix, matrix, scalar, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2418 scalar); |
15016 | 2419 fn.mark_can_error (); |
2420 body = fn.new_block (); | |
2421 builder.SetInsertPoint (body); | |
2422 { | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2423 llvm::Value *one_idx = llvm::ConstantInt::get (index_t, 1); |
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2424 llvm::Value *one_int = llvm::ConstantInt::get (int_t, 1); |
15016 | 2425 |
2426 llvm::Value *mat = fn.argument (builder, 0); | |
2427 llvm::Value *idx = fn.argument (builder, 1); | |
2428 llvm::Value *value = fn.argument (builder, 2); | |
2429 | |
2430 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); | |
2431 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); | |
2432 llvm::Value *cond0 = builder.CreateFCmpUNE (idx, check_idx); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2433 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one_idx); |
15016 | 2434 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
2435 | |
2436 llvm::BasicBlock *done = fn.new_block ("done"); | |
2437 | |
2438 llvm::BasicBlock *conv_error = fn.new_block ("conv_error", done); | |
2439 llvm::BasicBlock *normal = fn.new_block ("normal", done); | |
2440 builder.CreateCondBr (cond, conv_error, normal); | |
2441 builder.SetInsertPoint (conv_error); | |
2442 ginvalid_index.call (builder); | |
2443 builder.CreateBr (done); | |
2444 | |
2445 builder.SetInsertPoint (normal); | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2446 llvm::Value *len = builder.CreateExtractValue (mat, 2); |
15016 | 2447 cond0 = builder.CreateICmpSGT (int_idx, len); |
2448 | |
2449 llvm::Value *rcount = builder.CreateExtractValue (mat, 0); | |
2450 rcount = builder.CreateLoad (rcount); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
2451 cond1 = builder.CreateICmpSGT (rcount, one_int); |
15016 | 2452 cond = builder.CreateOr (cond0, cond1); |
2453 | |
2454 llvm::BasicBlock *bounds_error = fn.new_block ("bounds_error", done); | |
2455 llvm::BasicBlock *success = fn.new_block ("success", done); | |
2456 builder.CreateCondBr (cond, bounds_error, success); | |
2457 | |
2458 // resize on out of bounds access | |
2459 builder.SetInsertPoint (bounds_error); | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2460 llvm::Value *resize_result = resize_paren_subsasgn.call (builder, mat, |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2461 int_idx, value); |
15016 | 2462 builder.CreateBr (done); |
2463 | |
2464 builder.SetInsertPoint (success); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2465 llvm::Value *data |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2466 = builder.CreateExtractValue (mat, llvm::ArrayRef<unsigned> (1)); |
15016 | 2467 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); |
2468 builder.CreateStore (value, gep); | |
2469 builder.CreateBr (done); | |
2470 | |
2471 builder.SetInsertPoint (done); | |
2472 | |
2473 llvm::PHINode *merge = llvm::PHINode::Create (matrix_t, 3); | |
2474 builder.Insert (merge); | |
2475 merge->addIncoming (mat, conv_error); | |
2476 merge->addIncoming (resize_result, bounds_error); | |
2477 merge->addIncoming (mat, success); | |
2478 fn.do_return (builder, merge); | |
2479 } | |
2480 paren_subsasgn_fn.add_overload (fn); | |
2481 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2482 fn = create_external (JIT_FN (octave_jit_paren_subsasgn_matrix_range), matrix, |
15016 | 2483 matrix, range, scalar); |
2484 fn.mark_can_error (); | |
2485 paren_subsasgn_fn.add_overload (fn); | |
2486 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2487 end1_fn.stash_name ("end1"); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2488 fn = create_internal ("octave_jit_end1_matrix", scalar, matrix, index, index); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2489 body = fn.new_block (); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2490 builder.SetInsertPoint (body); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2491 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2492 llvm::Value *mat = fn.argument (builder, 0); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2493 llvm::Value *ret = builder.CreateExtractValue (mat, 2); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2494 fn.do_return (builder, builder.CreateSIToFP (ret, scalar_t)); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2495 } |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2496 end1_fn.add_overload (fn); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2497 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2498 end_fn.stash_name ("end"); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2499 fn = create_external (JIT_FN (octave_jit_end_matrix),scalar, matrix, index, |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2500 index); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2501 end_fn.add_overload (fn); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
2502 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2503 // -------------------- create_undef -------------------- |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2504 create_undef_fn.stash_name ("create_undef"); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2505 fn = create_external (JIT_FN (octave_jit_create_undef), any); |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2506 create_undef_fn.add_overload (fn); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
2507 |
15016 | 2508 casts[any->type_id ()].stash_name ("(any)"); |
2509 casts[scalar->type_id ()].stash_name ("(scalar)"); | |
18554 | 2510 casts[single->type_id ()].stash_name ("(single)"); |
18557 | 2511 casts[intN (8)->type_id ()].stash_name ("(int8)"); |
18559 | 2512 casts[intN (16)->type_id ()].stash_name ("(int16)"); |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2513 casts[intN (64)->type_id ()].stash_name ("(int64)"); |
18555 | 2514 casts[uintN (16)->type_id ()].stash_name ("(uint16)"); |
15016 | 2515 casts[complex->type_id ()].stash_name ("(complex)"); |
2516 casts[matrix->type_id ()].stash_name ("(matrix)"); | |
15603 | 2517 casts[range->type_id ()].stash_name ("(range)"); |
15016 | 2518 |
2519 // cast any <- matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2520 fn = create_external (JIT_FN (octave_jit_cast_any_matrix), any, matrix); |
15016 | 2521 casts[any->type_id ()].add_overload (fn); |
2522 | |
2523 // cast matrix <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2524 fn = create_external (JIT_FN (octave_jit_cast_matrix_any), matrix, any); |
15016 | 2525 casts[matrix->type_id ()].add_overload (fn); |
2526 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2527 // cast any <- range |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2528 fn = create_external (JIT_FN (octave_jit_cast_any_range), any, range); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2529 casts[any->type_id ()].add_overload (fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2530 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2531 // cast range <- any |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2532 fn = create_external (JIT_FN (octave_jit_cast_range_any), range, any); |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2533 casts[range->type_id ()].add_overload (fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
2534 |
15016 | 2535 // cast any <- scalar |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2536 fn = create_external (JIT_FN (octave_jit_cast_any_scalar), any, scalar); |
15016 | 2537 casts[any->type_id ()].add_overload (fn); |
2538 | |
2539 // cast scalar <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2540 fn = create_external (JIT_FN (octave_jit_cast_scalar_any), scalar, any); |
15016 | 2541 casts[scalar->type_id ()].add_overload (fn); |
2542 | |
18554 | 2543 // cast any <- single |
2544 fn = create_external (JIT_FN (octave_jit_cast_any_single), any, single); | |
2545 casts[any->type_id ()].add_overload (fn); | |
2546 | |
2547 // cast single <- any | |
2548 fn = create_external (JIT_FN (octave_jit_cast_single_any), single, any); | |
2549 casts[single->type_id ()].add_overload (fn); | |
2550 | |
18557 | 2551 // cast any <- int8 |
2552 fn = create_external (JIT_FN (octave_jit_cast_any_int8), any, intN (8)); | |
2553 casts[any->type_id ()].add_overload (fn); | |
2554 | |
2555 // cast int8 <- any | |
2556 fn = create_external (JIT_FN (octave_jit_cast_int8_any), intN (8), any); | |
2557 casts[intN (8)->type_id ()].add_overload (fn); | |
2558 | |
18559 | 2559 // cast any <- int16 |
2560 fn = create_external (JIT_FN (octave_jit_cast_any_int16), any, intN (16)); | |
2561 casts[any->type_id ()].add_overload (fn); | |
2562 | |
2563 // cast int16 <- any | |
2564 fn = create_external (JIT_FN (octave_jit_cast_int16_any), intN (16), any); | |
2565 casts[intN (16)->type_id ()].add_overload (fn); | |
2566 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2567 // cast any <- int64 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2568 fn = create_external (JIT_FN (octave_jit_cast_any_int64), any, intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2569 casts[any->type_id ()].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2570 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2571 // cast int64 <- any |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2572 fn = create_external (JIT_FN (octave_jit_cast_int64_any), intN (64), any); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2573 casts[intN (64)->type_id ()].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2574 |
18555 | 2575 // cast any <- uint16 |
2576 fn = create_external (JIT_FN (octave_jit_cast_any_uint16), any, uintN (16)); | |
2577 casts[any->type_id ()].add_overload (fn); | |
2578 | |
2579 // cast uint16 <- any | |
2580 fn = create_external (JIT_FN (octave_jit_cast_uint16_any), uintN (16), any); | |
2581 casts[uintN (16)->type_id ()].add_overload (fn); | |
2582 | |
15016 | 2583 // cast any <- complex |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2584 fn = create_external (JIT_FN (octave_jit_cast_any_complex), any, complex); |
15016 | 2585 casts[any->type_id ()].add_overload (fn); |
2586 | |
2587 // cast complex <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2588 fn = create_external (JIT_FN (octave_jit_cast_complex_any), complex, any); |
15016 | 2589 casts[complex->type_id ()].add_overload (fn); |
2590 | |
2591 // cast complex <- scalar | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2592 fn = create_internal ("octave_jit_cast_complex_scalar", complex, scalar); |
15016 | 2593 body = fn.new_block (); |
2594 builder.SetInsertPoint (body); | |
2595 { | |
2596 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
2597 fn.do_return (builder, complex_new (fn.argument (builder, 0), zero)); | |
2598 } | |
2599 casts[complex->type_id ()].add_overload (fn); | |
2600 | |
2601 // cast scalar <- complex | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2602 fn = create_internal ("octave_jit_cast_scalar_complex", scalar, complex); |
15016 | 2603 body = fn.new_block (); |
2604 builder.SetInsertPoint (body); | |
2605 fn.do_return (builder, complex_real (fn.argument (builder, 0))); | |
2606 casts[scalar->type_id ()].add_overload (fn); | |
2607 | |
2608 // cast any <- any | |
2609 fn = create_identity (any); | |
2610 casts[any->type_id ()].add_overload (fn); | |
2611 | |
2612 // cast scalar <- scalar | |
2613 fn = create_identity (scalar); | |
2614 casts[scalar->type_id ()].add_overload (fn); | |
2615 | |
18554 | 2616 // cast single <- single |
2617 fn = create_identity (single); | |
2618 casts[single->type_id ()].add_overload (fn); | |
2619 | |
18557 | 2620 // cast int8 <- int8 |
2621 fn = create_identity (intN (8)); | |
2622 casts[intN (8)->type_id ()].add_overload (fn); | |
2623 | |
18559 | 2624 // cast int16 <- int16 |
2625 fn = create_identity (intN (16)); | |
2626 casts[intN (16)->type_id ()].add_overload (fn); | |
2627 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2628 // cast int64 <- int64 |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2629 fn = create_identity (intN (64)); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2630 casts[intN (64)->type_id ()].add_overload (fn); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
2631 |
18555 | 2632 // cast uint16 <- uint16 |
2633 fn = create_identity (uintN (16)); | |
2634 casts[uintN (16)->type_id ()].add_overload (fn); | |
2635 | |
15016 | 2636 // cast complex <- complex |
2637 fn = create_identity (complex); | |
2638 casts[complex->type_id ()].add_overload (fn); | |
2639 | |
2640 // -------------------- builtin functions -------------------- | |
2641 add_builtin ("#unknown_function"); | |
2642 unknown_function = builtins["#unknown_function"]; | |
2643 | |
2644 add_builtin ("sin"); | |
2645 register_intrinsic ("sin", llvm::Intrinsic::sin, scalar, scalar); | |
2646 register_generic ("sin", matrix, matrix); | |
2647 | |
2648 add_builtin ("cos"); | |
2649 register_intrinsic ("cos", llvm::Intrinsic::cos, scalar, scalar); | |
2650 register_generic ("cos", matrix, matrix); | |
2651 | |
2652 add_builtin ("exp"); | |
18446
634d9989bf7b
Fix copy&paste typo when registering exp with JIT (bug #41560).
Rik <rik@octave.org>
parents:
18323
diff
changeset
|
2653 register_intrinsic ("exp", llvm::Intrinsic::exp, scalar, scalar); |
15016 | 2654 register_generic ("exp", matrix, matrix); |
2655 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2656 add_builtin ("balance"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2657 register_generic ("balance", matrix, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2658 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2659 add_builtin ("cond"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2660 register_generic ("cond", scalar, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2661 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2662 add_builtin ("det"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2663 register_generic ("det", scalar, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2664 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2665 add_builtin ("norm"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2666 register_generic ("norm", scalar, matrix); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2667 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2668 add_builtin ("rand"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2669 register_generic ("rand", matrix, scalar); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2670 register_generic ("rand", matrix, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2671 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2672 add_builtin ("magic"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2673 register_generic ("magic", matrix, scalar); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2674 register_generic ("magic", matrix, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2675 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2676 add_builtin ("eye"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2677 register_generic ("eye", matrix, scalar); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2678 register_generic ("eye", matrix, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2679 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2680 add_builtin ("mod"); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2681 register_generic ("mod", scalar, std::vector<jit_type *> (2, scalar)); |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2682 |
15016 | 2683 casts.resize (next_id + 1); |
2684 jit_function any_id = create_identity (any); | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2685 jit_function grab_any = create_external (JIT_FN (octave_jit_grab_any), |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2686 any, any); |
15016 | 2687 jit_function release_any = get_release (any); |
2688 std::vector<jit_type *> args; | |
2689 args.resize (1); | |
2690 | |
2691 for (std::map<std::string, jit_type *>::iterator iter = builtins.begin (); | |
2692 iter != builtins.end (); ++iter) | |
2693 { | |
2694 jit_type *btype = iter->second; | |
2695 args[0] = btype; | |
2696 | |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
2697 grab_fn.add_overload (jit_function (grab_any, btype, args)); |
15016 | 2698 release_fn.add_overload (jit_function (release_any, 0, args)); |
2699 casts[any->type_id ()].add_overload (jit_function (any_id, any, args)); | |
2700 | |
2701 args[0] = any; | |
2702 casts[btype->type_id ()].add_overload (jit_function (any_id, btype, | |
2703 args)); | |
2704 } | |
2705 } | |
2706 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2707 const jit_function& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2708 jit_typeinfo::do_end (jit_value *value, jit_value *idx, jit_value *count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2709 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2710 jit_const_index *ccount = dynamic_cast<jit_const_index *> (count); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2711 if (ccount && ccount->value () == 1) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2712 return end1_fn.overload (value->type (), idx->type (), count->type ()); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2713 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2714 return end_fn.overload (value->type (), idx->type (), count->type ()); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2715 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2716 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2717 jit_type* |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2718 jit_typeinfo::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
|
2719 llvm::Type *llvm_type, bool skip_paren) |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2720 { |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
2721 jit_type *ret = new jit_type (name, parent, llvm_type, skip_paren, next_id++); |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2722 id_to_type.push_back (ret); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2723 return ret; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2724 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
2725 |
15016 | 2726 void |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2727 jit_typeinfo::add_print (jit_type *ty, void *fptr) |
15016 | 2728 { |
2729 std::stringstream name; | |
2730 name << "octave_jit_print_" << ty->name (); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2731 jit_function fn = create_external (engine, fptr, name.str (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2732 0, intN (8), ty); |
15016 | 2733 print_fn.add_overload (fn); |
2734 } | |
2735 | |
2736 // FIXME: cp between add_binary_op, add_binary_icmp, and add_binary_fcmp | |
2737 void | |
2738 jit_typeinfo::add_binary_op (jit_type *ty, int op, int llvm_op) | |
2739 { | |
2740 std::stringstream fname; | |
2741 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
2742 fname << "octave_jit_" << octave_value::binary_op_as_string (ov_op) | |
2743 << "_" << ty->name (); | |
2744 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2745 jit_function fn = create_internal (fname.str (), ty, ty, ty); |
15016 | 2746 llvm::BasicBlock *block = fn.new_block (); |
2747 builder.SetInsertPoint (block); | |
2748 llvm::Instruction::BinaryOps temp | |
2749 = static_cast<llvm::Instruction::BinaryOps>(llvm_op); | |
2750 | |
2751 llvm::Value *ret = builder.CreateBinOp (temp, fn.argument (builder, 0), | |
2752 fn.argument (builder, 1)); | |
2753 fn.do_return (builder, ret); | |
2754 binary_ops[op].add_overload (fn); | |
2755 } | |
2756 | |
2757 void | |
2758 jit_typeinfo::add_binary_icmp (jit_type *ty, int op, int llvm_op) | |
2759 { | |
2760 std::stringstream fname; | |
2761 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
2762 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) | |
2763 << "_" << ty->name (); | |
2764 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2765 jit_function fn = create_internal (fname.str (), boolean, ty, ty); |
15016 | 2766 llvm::BasicBlock *block = fn.new_block (); |
2767 builder.SetInsertPoint (block); | |
2768 llvm::CmpInst::Predicate temp | |
2769 = static_cast<llvm::CmpInst::Predicate>(llvm_op); | |
2770 llvm::Value *ret = builder.CreateICmp (temp, fn.argument (builder, 0), | |
2771 fn.argument (builder, 1)); | |
2772 fn.do_return (builder, ret); | |
2773 binary_ops[op].add_overload (fn); | |
2774 } | |
2775 | |
2776 void | |
2777 jit_typeinfo::add_binary_fcmp (jit_type *ty, int op, int llvm_op) | |
2778 { | |
2779 std::stringstream fname; | |
2780 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
2781 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) | |
2782 << "_" << ty->name (); | |
2783 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2784 jit_function fn = create_internal (fname.str (), boolean, ty, ty); |
15016 | 2785 llvm::BasicBlock *block = fn.new_block (); |
2786 builder.SetInsertPoint (block); | |
2787 llvm::CmpInst::Predicate temp | |
2788 = static_cast<llvm::CmpInst::Predicate>(llvm_op); | |
2789 llvm::Value *ret = builder.CreateFCmp (temp, fn.argument (builder, 0), | |
2790 fn.argument (builder, 1)); | |
2791 fn.do_return (builder, ret); | |
2792 binary_ops[op].add_overload (fn); | |
2793 } | |
2794 | |
2795 jit_function | |
2796 jit_typeinfo::create_function (jit_convention::type cc, const llvm::Twine& name, | |
2797 jit_type *ret, | |
2798 const std::vector<jit_type *>& args) | |
2799 { | |
2800 jit_function result (module, cc, name, ret, args); | |
2801 return result; | |
2802 } | |
2803 | |
2804 jit_function | |
2805 jit_typeinfo::create_identity (jit_type *type) | |
2806 { | |
2807 size_t id = type->type_id (); | |
2808 if (id >= identities.size ()) | |
2809 identities.resize (id + 1); | |
2810 | |
2811 if (! identities[id].valid ()) | |
2812 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2813 std::stringstream name; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2814 name << "id_" << type->name (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2815 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2816 jit_function fn = create_internal (name.str (), type, type); |
15016 | 2817 llvm::BasicBlock *body = fn.new_block (); |
2818 builder.SetInsertPoint (body); | |
2819 fn.do_return (builder, fn.argument (builder, 0)); | |
2820 return identities[id] = fn; | |
2821 } | |
2822 | |
2823 return identities[id]; | |
2824 } | |
2825 | |
2826 llvm::Value * | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2827 jit_typeinfo::do_insert_error_check (llvm::IRBuilderD& abuilder) |
15016 | 2828 { |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
2829 return abuilder.CreateLoad (lerror_state); |
15016 | 2830 } |
2831 | |
15603 | 2832 llvm::Value * |
2833 jit_typeinfo::do_insert_interrupt_check (llvm::IRBuilderD& abuilder) | |
2834 { | |
2835 llvm::LoadInst *val = abuilder.CreateLoad (loctave_interrupt_state); | |
2836 val->setVolatile (true); | |
2837 return abuilder.CreateICmpSGT (val, abuilder.getInt32 (0)); | |
2838 } | |
2839 | |
15016 | 2840 void |
2841 jit_typeinfo::add_builtin (const std::string& name) | |
2842 { | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
2843 jit_type *btype = new_type (name, any, any->to_llvm (), true); |
15016 | 2844 builtins[name] = btype; |
2845 | |
2846 octave_builtin *ov_builtin = find_builtin (name); | |
2847 if (ov_builtin) | |
2848 ov_builtin->stash_jit (*btype); | |
2849 } | |
2850 | |
2851 void | |
2852 jit_typeinfo::register_intrinsic (const std::string& name, size_t iid, | |
2853 jit_type *result, | |
2854 const std::vector<jit_type *>& args) | |
2855 { | |
2856 jit_type *builtin_type = builtins[name]; | |
2857 size_t nargs = args.size (); | |
2858 llvm::SmallVector<llvm::Type *, 5> llvm_args (nargs); | |
2859 for (size_t i = 0; i < nargs; ++i) | |
2860 llvm_args[i] = args[i]->to_llvm (); | |
2861 | |
2862 llvm::Intrinsic::ID id = static_cast<llvm::Intrinsic::ID> (iid); | |
2863 llvm::Function *ifun = llvm::Intrinsic::getDeclaration (module, id, | |
2864 llvm_args); | |
2865 std::stringstream fn_name; | |
2866 fn_name << "octave_jit_" << name; | |
2867 | |
2868 std::vector<jit_type *> args1 (nargs + 1); | |
2869 args1[0] = builtin_type; | |
2870 std::copy (args.begin (), args.end (), args1.begin () + 1); | |
2871 | |
2872 // The first argument will be the Octave function, but we already know that | |
2873 // the function call is the equivalent of the intrinsic, so we ignore it and | |
2874 // call the intrinsic with the remaining arguments. | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2875 jit_function fn = create_internal (fn_name.str (), result, args1); |
15016 | 2876 llvm::BasicBlock *body = fn.new_block (); |
2877 builder.SetInsertPoint (body); | |
2878 | |
2879 llvm::SmallVector<llvm::Value *, 5> fargs (nargs); | |
2880 for (size_t i = 0; i < nargs; ++i) | |
2881 fargs[i] = fn.argument (builder, i + 1); | |
2882 | |
2883 llvm::Value *ret = builder.CreateCall (ifun, fargs); | |
2884 fn.do_return (builder, ret); | |
2885 paren_subsref_fn.add_overload (fn); | |
2886 } | |
2887 | |
2888 octave_builtin * | |
2889 jit_typeinfo::find_builtin (const std::string& name) | |
2890 { | |
2891 // FIXME: Finalize what we want to store in octave_builtin, then add functions | |
2892 // to access these values in octave_value | |
2893 octave_value ov_builtin = symbol_table::find (name); | |
2894 return dynamic_cast<octave_builtin *> (ov_builtin.internal_rep ()); | |
2895 } | |
2896 | |
2897 void | |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2898 jit_typeinfo::register_generic (const std::string& name, jit_type *result, |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2899 const std::vector<jit_type *>& args) |
15016 | 2900 { |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2901 octave_builtin *builtin = find_builtin (name); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2902 if (! builtin) |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2903 return; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2904 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2905 std::vector<jit_type *> fn_args (args.size () + 1); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2906 fn_args[0] = builtins[name]; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2907 std::copy (args.begin (), args.end (), fn_args.begin () + 1); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2908 jit_function fn = create_internal (name, result, fn_args); |
15136
eeaaac7c86b6
jit-typeinfo.cc (jit_typeinfo::register_generic): Mark can error
Max Brister <max@2bass.com>
parents:
15135
diff
changeset
|
2909 fn.mark_can_error (); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2910 llvm::BasicBlock *block = fn.new_block (); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2911 builder.SetInsertPoint (block); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2912 llvm::Type *any_t = any->to_llvm (); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2913 llvm::ArrayType *array_t = llvm::ArrayType::get (any_t, args.size ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2914 llvm::Value *array = llvm::UndefValue::get (array_t); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2915 for (size_t i = 0; i < args.size (); ++i) |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2916 { |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2917 llvm::Value *arg = fn.argument (builder, i + 1); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2918 jit_function agrab = get_grab (args[i]); |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2919 if (agrab.valid ()) |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2920 arg = agrab.call (builder, arg); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2921 jit_function acast = cast (any, args[i]); |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
2922 array = builder.CreateInsertValue (array, acast.call (builder, arg), i); |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2923 } |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2924 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2925 llvm::Value *array_mem = builder.CreateAlloca (array_t); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2926 builder.CreateStore (array, array_mem); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2927 array = builder.CreateBitCast (array_mem, any_t->getPointerTo ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2928 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2929 jit_type *jintTy = intN (sizeof (octave_builtin::fcn) * 8); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2930 llvm::Type *intTy = jintTy->to_llvm (); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2931 size_t fcn_int = reinterpret_cast<size_t> (builtin->function ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2932 llvm::Value *fcn = llvm::ConstantInt::get (intTy, fcn_int); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2933 llvm::Value *nargin = llvm::ConstantInt::get (intTy, args.size ()); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2934 size_t result_int = reinterpret_cast<size_t> (result); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2935 llvm::Value *res_llvm = llvm::ConstantInt::get (intTy, result_int); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2936 llvm::Value *ret = any_call.call (builder, fcn, nargin, array, res_llvm); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2937 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2938 jit_function cast_result = cast (result, any); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2939 fn.do_return (builder, cast_result.call (builder, ret)); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2940 paren_subsref_fn.add_overload (fn); |
15016 | 2941 } |
2942 | |
2943 jit_function | |
2944 jit_typeinfo::mirror_binary (const jit_function& fn) | |
2945 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2946 jit_function ret = create_internal (fn.name () + "_reverse", |
15016 | 2947 fn.result (), fn.argument_type (1), |
2948 fn.argument_type (0)); | |
2949 if (fn.can_error ()) | |
2950 ret.mark_can_error (); | |
2951 | |
2952 llvm::BasicBlock *body = ret.new_block (); | |
2953 builder.SetInsertPoint (body); | |
2954 llvm::Value *result = fn.call (builder, ret.argument (builder, 1), | |
2955 ret.argument (builder, 0)); | |
2956 if (ret.result ()) | |
2957 ret.do_return (builder, result); | |
2958 else | |
2959 ret.do_return (builder); | |
2960 | |
2961 return ret; | |
2962 } | |
2963 | |
2964 llvm::Value * | |
2965 jit_typeinfo::pack_complex (llvm::IRBuilderD& bld, llvm::Value *cplx) | |
2966 { | |
2967 llvm::Type *complex_ret = instance->complex_ret; | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2968 llvm::Value *real = bld.CreateExtractValue (cplx, 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2969 llvm::Value *imag = bld.CreateExtractValue (cplx, 1); |
15016 | 2970 llvm::Value *ret = llvm::UndefValue::get (complex_ret); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2971 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2972 unsigned int re_idx[] = {0, 0}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2973 unsigned int im_idx[] = {0, 1}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2974 ret = bld.CreateInsertValue (ret, real, re_idx); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2975 return bld.CreateInsertValue (ret, imag, im_idx); |
15016 | 2976 } |
2977 | |
2978 llvm::Value * | |
2979 jit_typeinfo::unpack_complex (llvm::IRBuilderD& bld, llvm::Value *result) | |
2980 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2981 unsigned int re_idx[] = {0, 0}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2982 unsigned int im_idx[] = {0, 1}; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2983 |
15016 | 2984 llvm::Type *complex_t = get_complex ()->to_llvm (); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2985 llvm::Value *real = bld.CreateExtractValue (result, re_idx); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2986 llvm::Value *imag = bld.CreateExtractValue (result, im_idx); |
15016 | 2987 llvm::Value *ret = llvm::UndefValue::get (complex_t); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2988 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2989 ret = bld.CreateInsertValue (ret, real, 0); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2990 return bld.CreateInsertValue (ret, imag, 1); |
15016 | 2991 } |
2992 | |
2993 llvm::Value * | |
2994 jit_typeinfo::complex_real (llvm::Value *cx) | |
2995 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2996 return builder.CreateExtractValue (cx, 0); |
15016 | 2997 } |
2998 | |
2999 llvm::Value * | |
3000 jit_typeinfo::complex_real (llvm::Value *cx, llvm::Value *real) | |
3001 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3002 return builder.CreateInsertValue (cx, real, 0); |
15016 | 3003 } |
3004 | |
3005 llvm::Value * | |
3006 jit_typeinfo::complex_imag (llvm::Value *cx) | |
3007 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3008 return builder.CreateExtractValue (cx, 1); |
15016 | 3009 } |
3010 | |
3011 llvm::Value * | |
3012 jit_typeinfo::complex_imag (llvm::Value *cx, llvm::Value *imag) | |
3013 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3014 return builder.CreateInsertValue (cx, imag, 1); |
15016 | 3015 } |
3016 | |
3017 llvm::Value * | |
3018 jit_typeinfo::complex_new (llvm::Value *real, llvm::Value *imag) | |
3019 { | |
3020 llvm::Value *ret = llvm::UndefValue::get (complex->to_llvm ()); | |
3021 ret = complex_real (ret, real); | |
3022 return complex_imag (ret, imag); | |
3023 } | |
3024 | |
3025 void | |
3026 jit_typeinfo::create_int (size_t nbits) | |
3027 { | |
3028 std::stringstream tname; | |
3029 tname << "int" << nbits; | |
3030 ints[nbits] = new_type (tname.str (), any, llvm::Type::getIntNTy (context, | |
3031 nbits)); | |
3032 } | |
3033 | |
18555 | 3034 void |
3035 jit_typeinfo::create_uint (size_t nbits) | |
3036 { | |
3037 std::stringstream tname; | |
3038 tname << "uint" << nbits; | |
3039 uints[nbits] = new_type (tname.str (), any, llvm::Type::getIntNTy (context, | |
3040 nbits)); | |
3041 } | |
3042 | |
15016 | 3043 jit_type * |
3044 jit_typeinfo::intN (size_t nbits) const | |
3045 { | |
3046 std::map<size_t, jit_type *>::const_iterator iter = ints.find (nbits); | |
3047 if (iter != ints.end ()) | |
3048 return iter->second; | |
3049 | |
3050 throw jit_fail_exception ("No such integer type"); | |
3051 } | |
3052 | |
3053 jit_type * | |
18555 | 3054 jit_typeinfo::uintN (size_t nbits) const |
3055 { | |
3056 std::map<size_t, jit_type *>::const_iterator iter = uints.find (nbits); | |
3057 if (iter != uints.end ()) | |
3058 return iter->second; | |
3059 | |
3060 throw jit_fail_exception ("No such unsigned integer type"); | |
3061 } | |
3062 | |
3063 jit_type * | |
15016 | 3064 jit_typeinfo::do_type_of (const octave_value &ov) const |
3065 { | |
3066 if (ov.is_function ()) | |
3067 { | |
3068 // FIXME: This is ugly, we need to finalize how we want to to this, then | |
3069 // have octave_value fully support the needed functionality | |
3070 octave_builtin *builtin | |
3071 = dynamic_cast<octave_builtin *> (ov.internal_rep ()); | |
3072 return builtin && builtin->to_jit () ? builtin->to_jit () | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3073 : unknown_function; |
15016 | 3074 } |
3075 | |
3076 if (ov.is_range ()) | |
3077 return get_range (); | |
3078 | |
15311
de9bfcf637df
Fix error when compiling with complex matrix (bug #37247)
Max Brister <max@2bass.com>
parents:
15219
diff
changeset
|
3079 if (ov.is_double_type () && ! ov.is_complex_type ()) |
15016 | 3080 { |
3081 if (ov.is_real_scalar ()) | |
3082 return get_scalar (); | |
3083 | |
3084 if (ov.is_matrix_type ()) | |
3085 return get_matrix (); | |
3086 } | |
3087 | |
18554 | 3088 if (ov.is_single_type () && ! ov.is_complex_type ()) |
3089 { | |
3090 if (ov.is_real_scalar ()) | |
3091 return get_single (); | |
3092 } | |
3093 | |
18557 | 3094 if (ov.is_int8_type()) |
3095 { | |
3096 return intN (8); | |
3097 } | |
3098 | |
18559 | 3099 if (ov.is_int16_type()) |
3100 { | |
3101 return intN (16); | |
3102 } | |
3103 | |
18558
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3104 if (ov.is_int64_type()) |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3105 { |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3106 return intN (64); |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3107 } |
1867774aaa2e
jit compiler: Add support for int64 type
LYH <lyh.kernel@gmail.com>
parents:
18557
diff
changeset
|
3108 |
18555 | 3109 if (ov.is_uint16_type()) |
3110 { | |
3111 return uintN (16); | |
3112 } | |
3113 | |
15016 | 3114 if (ov.is_complex_scalar ()) |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3115 { |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3116 Complex cv = ov.complex_value (); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3117 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3118 // We don't really represent complex values, instead we represent |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3119 // complex_or_scalar. If the imag value is zero, we assume a scalar. |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
3120 if (cv.imag () != 0) |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3121 return get_complex (); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
3122 } |
15016 | 3123 |
3124 return get_any (); | |
3125 } | |
3126 | |
3127 #endif | |
18553 | 3128 |
3129 #pragma GCC diagnostic pop |