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