Mercurial > octave
annotate libinterp/parse-tree/jit-typeinfo.cc @ 23807:336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Better performance when string constructor isn't required.
* Figure.cc, __init_qt__.cc, files-dock-widget.cc, file-editor-tab.cc,
file-editor.cc, octave-qscintilla.cc, main-window.cc, octave-dock-widget.cc,
octave-qt-link.cc, parser.cc, webinfo.cc, resource-manager.cc,
settings-dialog.cc, workspace-view.cc, __magick_read__.cc, balance.cc,
debug.cc, dynamic-ld.cc, ft-text-renderer.cc, gl-render.cc, gl2ps-print.cc,
graphics.cc, hook-fcn.h, input.cc, load-path.cc, load-save.cc, ls-hdf5.cc,
oct-hist.cc, oct-stream.cc, pager.cc, pr-output.cc, qz.cc, symtab.cc, symtab.h,
tril.cc, __delaunayn__.cc, __init_fltk__.cc, __voronoi__.cc, audioread.cc,
ccolamd.cc, colamd.cc, convhulln.cc, ov-base-int.cc, ov-base-mat.cc,
ov-base-scalar.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc,
ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cx-mat.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-fcn.h, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-java.cc,
ov-oncleanup.cc, ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-str-mat.cc,
ov-struct.cc, ov-usr-fcn.cc, ov.cc, octave.cc, bp-table.cc, jit-ir.cc,
jit-ir.h, jit-typeinfo.cc, pt-funcall.cc, pt-idx.cc, pt-pr-code.cc, pt.h,
Array.cc, CDiagMatrix.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc,
Range.cc, boolSparse.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc,
dRowVector.cc, dSparse.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc,
fCRowVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
idx-vector.cc, intNDArray.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc,
LSODE.cc, oct-time.cc, cmd-hist.cc, kpse.cc, lo-array-errwarn.cc, lo-regexp.cc,
lo-utils.cc, str-vec.cc, url-transfer.cc, main-cli.cc, main-gui.cc,
mkoctfile.in.cc:
Replace 1-character string literals "c" with the character literal 'c'.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 28 Jul 2017 15:40:00 -0700 |
parents | 980f39c3ab90 |
children | 51e408a7d38f |
rev | line source |
---|---|
15016 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2012-2017 Max Brister |
15016 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
10 (at your option) any later version. |
15016 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
15 GNU General Public License for more details. |
15016 | 16 |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
16768 | 23 // Author: Max Brister <max@2bass.com> |
24 | |
15016 | 25 // defines required by llvm |
26 #define __STDC_LIMIT_MACROS | |
27 #define __STDC_CONSTANT_MACROS | |
28 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
29 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
30 # include "config.h" |
15016 | 31 #endif |
32 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
33 #if defined (HAVE_LLVM) |
15016 | 34 |
35 #include "jit-typeinfo.h" | |
36 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
37 #if defined (HAVE_LLVM_IR_VERIFIER_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
38 # include <llvm/IR/Verifier.h> |
18831
4a4edf0f2077
fix LLVM 3.4 build (bug #41061)
Stefan Mahr <dac922@gmx.de>
parents:
18446
diff
changeset
|
39 #else |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
40 # include <llvm/Analysis/Verifier.h> |
18831
4a4edf0f2077
fix LLVM 3.4 build (bug #41061)
Stefan Mahr <dac922@gmx.de>
parents:
18446
diff
changeset
|
41 #endif |
4a4edf0f2077
fix LLVM 3.4 build (bug #41061)
Stefan Mahr <dac922@gmx.de>
parents:
18446
diff
changeset
|
42 |
17164 | 43 #include <llvm/ExecutionEngine/ExecutionEngine.h> |
44 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
45 #if defined (HAVE_LLVM_IR_FUNCTION_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
46 # include <llvm/IR/GlobalVariable.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
47 # include <llvm/IR/LLVMContext.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
48 # include <llvm/IR/Function.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
49 # include <llvm/IR/Instructions.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
50 # include <llvm/IR/Intrinsics.h> |
17164 | 51 #else |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
52 # include <llvm/GlobalVariable.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
53 # include <llvm/LLVMContext.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
54 # include <llvm/Function.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
55 # include <llvm/Instructions.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
56 # include <llvm/Intrinsics.h> |
17164 | 57 #endif |
58 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
59 #if defined (HAVE_LLVM_SUPPORT_IRBUILDER_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
60 # include <llvm/Support/IRBuilder.h> |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
61 # elif defined(HAVE_LLVM_IR_IRBUILDER_H) |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
62 # 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
|
63 #else |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21102
diff
changeset
|
64 # include <llvm/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
|
65 #endif |
17164 | 66 |
15016 | 67 #include <llvm/Support/raw_os_ostream.h> |
68 | |
69 #include "jit-ir.h" | |
70 #include "ov.h" | |
71 #include "ov-builtin.h" | |
72 #include "ov-complex.h" | |
73 #include "ov-scalar.h" | |
74 #include "pager.h" | |
75 | |
76 static llvm::LLVMContext& context = llvm::getGlobalContext (); | |
77 | |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
78 jit_typeinfo *jit_typeinfo::instance = nullptr; |
15016 | 79 |
80 std::ostream& jit_print (std::ostream& os, jit_type *atype) | |
81 { | |
82 if (! atype) | |
83 return os << "null"; | |
84 return os << atype->name (); | |
85 } | |
86 | |
87 // function that jit code calls | |
88 extern "C" void | |
89 octave_jit_print_any (const char *name, octave_base_value *obv) | |
90 { | |
91 obv->print_with_name (octave_stdout, name, true); | |
92 } | |
93 | |
94 extern "C" void | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
95 octave_jit_print_scalar (const char *name, double value) |
15016 | 96 { |
97 // FIXME: We should avoid allocating a new octave_scalar each time | |
98 octave_value ov (value); | |
99 ov.print_with_name (octave_stdout, name); | |
100 } | |
101 | |
102 extern "C" octave_base_value* | |
103 octave_jit_binary_any_any (octave_value::binary_op op, octave_base_value *lhs, | |
104 octave_base_value *rhs) | |
105 { | |
106 octave_value olhs (lhs, true); | |
107 octave_value orhs (rhs, true); | |
108 octave_value result = do_binary_op (op, olhs, orhs); | |
109 octave_base_value *rep = result.internal_rep (); | |
110 rep->grab (); | |
111 return rep; | |
112 } | |
113 | |
114 extern "C" octave_idx_type | |
115 octave_jit_compute_nelem (double base, double limit, double inc) | |
116 { | |
117 Range rng = Range (base, limit, inc); | |
20614
d35201e5ce5d
Fix compilation of jit broken by dd6345fd8a97 (bug #46191).
Rik <rik@octave.org>
parents:
20535
diff
changeset
|
118 return rng.numel (); |
15016 | 119 } |
120 | |
121 extern "C" void | |
122 octave_jit_release_any (octave_base_value *obv) | |
123 { | |
124 obv->release (); | |
125 } | |
126 | |
127 extern "C" void | |
128 octave_jit_release_matrix (jit_matrix *m) | |
129 { | |
130 delete m->array; | |
131 } | |
132 | |
133 extern "C" octave_base_value * | |
134 octave_jit_grab_any (octave_base_value *obv) | |
135 { | |
136 obv->grab (); | |
137 return obv; | |
138 } | |
139 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
140 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
|
141 octave_jit_grab_matrix (jit_matrix *m) |
15016 | 142 { |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
143 return *m->array; |
15016 | 144 } |
145 | |
146 extern "C" octave_base_value * | |
147 octave_jit_cast_any_matrix (jit_matrix *m) | |
148 { | |
149 octave_value ret (*m->array); | |
150 octave_base_value *rep = ret.internal_rep (); | |
151 rep->grab (); | |
152 delete m->array; | |
153 | |
154 return rep; | |
155 } | |
156 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
157 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
|
158 octave_jit_cast_matrix_any (octave_base_value *obv) |
15016 | 159 { |
160 NDArray m = obv->array_value (); | |
161 obv->release (); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
162 return m; |
15016 | 163 } |
164 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
165 extern "C" octave_base_value * |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
166 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
|
167 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
168 Range temp (*rng); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
169 octave_value ret (temp); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
170 octave_base_value *rep = ret.internal_rep (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
171 rep->grab (); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
172 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
173 return rep; |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
174 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
175 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
|
176 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
|
177 { |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
178 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
179 jit_range r (obv->range_value ()); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
180 obv->release (); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
181 return r; |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
182 } |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
183 |
15016 | 184 extern "C" double |
185 octave_jit_cast_scalar_any (octave_base_value *obv) | |
186 { | |
187 double ret = obv->double_value (); | |
188 obv->release (); | |
189 return ret; | |
190 } | |
191 | |
192 extern "C" octave_base_value * | |
193 octave_jit_cast_any_scalar (double value) | |
194 { | |
195 return new octave_scalar (value); | |
196 } | |
197 | |
198 extern "C" Complex | |
199 octave_jit_cast_complex_any (octave_base_value *obv) | |
200 { | |
201 Complex ret = obv->complex_value (); | |
202 obv->release (); | |
203 return ret; | |
204 } | |
205 | |
206 extern "C" octave_base_value * | |
207 octave_jit_cast_any_complex (Complex c) | |
208 { | |
209 if (c.imag () == 0) | |
210 return new octave_scalar (c.real ()); | |
211 else | |
212 return new octave_complex (c); | |
213 } | |
214 | |
215 extern "C" void | |
23242
c21939b04931
Fix compilation of jit caused by cset d0562b3159c7 (bug #50398).
Mike Miller <mtmiller@octave.org>
parents:
23219
diff
changeset
|
216 octave_jit_err_nan_to_logical_conversion (void) |
15016 | 217 { |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
218 octave::err_nan_to_logical_conversion (); |
15016 | 219 } |
220 | |
221 extern "C" void | |
222 octave_jit_ginvalid_index (void) | |
223 { | |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
224 // FIXME: 0-argument form of octave::err_invalid_index removed in cset dd6345fd8a97 |
20614
d35201e5ce5d
Fix compilation of jit broken by dd6345fd8a97 (bug #46191).
Rik <rik@octave.org>
parents:
20535
diff
changeset
|
225 // Report -1 as the bad index for all occurrences. |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
226 octave::err_invalid_index (static_cast<octave_idx_type> (-1)); |
15016 | 227 } |
228 | |
229 extern "C" void | |
230 octave_jit_gindex_range (int nd, int dim, octave_idx_type iext, | |
231 octave_idx_type ext) | |
232 { | |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
233 octave::err_index_out_of_range (nd, dim, iext, ext); |
15016 | 234 } |
235 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
236 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
|
237 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
|
238 double value) |
15016 | 239 { |
240 NDArray *array = mat->array; | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
241 if (array->numel () < index) |
15016 | 242 array->resize1 (index); |
243 | |
244 double *data = array->fortran_vec (); | |
245 data[index - 1] = value; | |
246 | |
247 mat->update (); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
248 return *mat; |
15016 | 249 } |
250 | |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
251 static void |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
252 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
|
253 Array<idx_vector>& result) |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
254 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
259 |
15067 | 260 extern "C" double |
261 octave_jit_paren_scalar (jit_matrix *mat, double *indicies, | |
262 octave_idx_type idx_count) | |
263 { | |
264 // FIXME: Replace this with a more optimal version | |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
265 Array<idx_vector> idx; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
266 make_indices (indicies, idx_count, idx); |
15067 | 267 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
268 Array<double> ret = mat->array->index (idx); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
269 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
270 return ret.xelem (0); |
15067 | 271 } |
272 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 { |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
277 // 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
|
278 jit_matrix ret; |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
279 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
280 Array<idx_vector> idx; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
281 make_indices (indices, idx_count, idx); |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
282 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
283 Matrix temp (1, 1); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
284 temp.xelem(0) = value; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
285 mat->array->assign (idx, temp); |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
286 ret.update (mat->array); |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
287 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
288 return ret; |
15068
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
289 } |
f57d7578c1a6
Support ND matrix indexing with scalar assignment in JIT.
Max Brister <max@2bass.com>
parents:
15067
diff
changeset
|
290 |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
291 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
|
292 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
|
293 double value) |
15016 | 294 { |
295 NDArray *array = mat->array; | |
296 bool done = false; | |
297 | |
298 // optimize for the simple case (no resizing and no errors) | |
299 if (*array->jit_ref_count () == 1 | |
300 && index->all_elements_are_ints ()) | |
301 { | |
302 // this code is similar to idx_vector::fill, but we avoid allocating an | |
303 // idx_vector and its associated rep | |
304 octave_idx_type start = static_cast<octave_idx_type> (index->base) - 1; | |
305 octave_idx_type step = static_cast<octave_idx_type> (index->inc); | |
306 octave_idx_type nelem = index->nelem; | |
307 octave_idx_type final = start + nelem * step; | |
308 if (step < 0) | |
309 { | |
310 step = -step; | |
311 std::swap (final, start); | |
312 } | |
313 | |
314 if (start >= 0 && final < mat->slice_len) | |
315 { | |
316 done = true; | |
317 | |
318 double *data = array->jit_slice_data (); | |
319 if (step == 1) | |
320 std::fill (data + start, data + start + nelem, value); | |
321 else | |
322 { | |
323 for (octave_idx_type i = start; i < final; i += step) | |
324 data[i] = value; | |
325 } | |
326 } | |
327 } | |
328 | |
329 if (! done) | |
330 { | |
331 idx_vector idx (*index); | |
332 NDArray avalue (dim_vector (1, 1)); | |
333 avalue.xelem (0) = value; | |
334 array->assign (idx, avalue); | |
335 } | |
336 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
337 jit_matrix ret; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
338 ret.update (array); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
339 return ret; |
15016 | 340 } |
341 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
342 extern "C" double |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
343 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
|
344 octave_idx_type count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
345 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
346 octave_idx_type ndim = mat->dimensions[-1]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
347 if (ndim == count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
348 return mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
349 else if (ndim > count) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
350 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
351 if (idx == count - 1) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
352 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
353 double ret = mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
354 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
|
355 ret *= mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
356 return ret; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
357 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
358 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
359 return mat->dimensions[idx]; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
360 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
361 else // ndim < count |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
362 return idx < ndim ? mat->dimensions[idx] : 1; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
363 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
364 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
365 extern "C" octave_base_value * |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
366 octave_jit_create_undef (void) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
367 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
368 octave_value undef; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
369 octave_base_value *ret = undef.internal_rep (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
370 ret->grab (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
371 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
372 return ret; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
373 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
374 |
15016 | 375 extern "C" Complex |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
376 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
|
377 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
378 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
|
379 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
|
380 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
381 return lhs * rhs; |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
382 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
383 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
384 extern "C" Complex |
15016 | 385 octave_jit_complex_div (Complex lhs, Complex rhs) |
386 { | |
387 // see src/OPERATORS/op-cs-cs.cc | |
388 if (rhs == 0.0) | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
389 warn_divide_by_zero (); |
15016 | 390 |
391 return lhs / rhs; | |
392 } | |
393 | |
394 // FIXME: CP form src/xpow.cc | |
395 static inline int | |
396 xisint (double x) | |
397 { | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
398 return (octave::math::x_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
|
399 && ((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
|
400 || (x <= 0 && x > std::numeric_limits<int>::min ()))); |
15016 | 401 } |
402 | |
403 extern "C" Complex | |
404 octave_jit_pow_scalar_scalar (double lhs, double rhs) | |
405 { | |
406 // FIXME: almost CP from src/xpow.cc | |
407 if (lhs < 0.0 && ! xisint (rhs)) | |
408 return std::pow (Complex (lhs), rhs); | |
409 return std::pow (lhs, rhs); | |
410 } | |
411 | |
412 extern "C" Complex | |
413 octave_jit_pow_complex_complex (Complex lhs, Complex rhs) | |
414 { | |
415 if (lhs.imag () == 0 && rhs.imag () == 0) | |
416 return octave_jit_pow_scalar_scalar (lhs.real (), rhs.real ()); | |
417 return std::pow (lhs, rhs); | |
418 } | |
419 | |
420 extern "C" Complex | |
421 octave_jit_pow_complex_scalar (Complex lhs, double rhs) | |
422 { | |
423 if (lhs.imag () == 0) | |
424 return octave_jit_pow_scalar_scalar (lhs.real (), rhs); | |
425 return std::pow (lhs, rhs); | |
426 } | |
427 | |
428 extern "C" Complex | |
429 octave_jit_pow_scalar_complex (double lhs, Complex rhs) | |
430 { | |
431 if (rhs.imag () == 0) | |
432 return octave_jit_pow_scalar_scalar (lhs, rhs.real ()); | |
433 return std::pow (lhs, rhs); | |
434 } | |
435 | |
436 extern "C" void | |
437 octave_jit_print_matrix (jit_matrix *m) | |
438 { | |
439 std::cout << *m << std::endl; | |
440 } | |
441 | |
21040
3e7cfee5f786
maint: Rename attributes GCC_ATTR_XXX to OCTAVE_XXX.
Rik <rik@octave.org>
parents:
21029
diff
changeset
|
442 OCTAVE_NORETURN static |
21029
e3b3bb522d62
maint: Move GCC_ attributes to start of declaration for future compatibility.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
443 void |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
444 err_bad_result (void) |
15016 | 445 { |
446 error ("incorrect type information given to the JIT compiler"); | |
447 } | |
448 | |
449 // FIXME: Add support for multiple outputs | |
450 extern "C" octave_base_value * | |
451 octave_jit_call (octave_builtin::fcn fn, size_t nargin, | |
452 octave_base_value **argin, jit_type *result_type) | |
453 { | |
454 octave_value_list ovl (nargin); | |
455 for (size_t i = 0; i < nargin; ++i) | |
456 ovl.xelem (i) = octave_value (argin[i]); | |
457 | |
458 ovl = fn (ovl, 1); | |
459 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
460 // FIXME: Check result_type somehow |
15016 | 461 if (result_type) |
462 { | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
463 if (ovl.length () < 1) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
464 err_bad_result (); |
15016 | 465 |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
466 octave_value result = ovl.xelem(0); |
15016 | 467 octave_base_value *ret = result.internal_rep (); |
468 ret->grab (); | |
469 return ret; | |
470 } | |
471 | |
21937
55f7de37b618
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
472 if (! (ovl.empty () |
15016 | 473 || (ovl.length () == 1 && ovl.xelem (0).is_undefined ()))) |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
474 err_bad_result (); |
15016 | 475 |
476 return 0; | |
477 } | |
478 | |
479 // -------------------- jit_range -------------------- | |
480 bool | |
481 jit_range::all_elements_are_ints () const | |
482 { | |
483 Range r (*this); | |
484 return r.all_elements_are_ints (); | |
485 } | |
486 | |
487 std::ostream& | |
488 operator<< (std::ostream& os, const jit_range& rng) | |
489 { | |
490 return os << "Range[" << rng.base << ", " << rng.limit << ", " << rng.inc | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
491 << ", " << rng.nelem << ']'; |
15016 | 492 } |
493 | |
494 // -------------------- jit_matrix -------------------- | |
495 | |
496 std::ostream& | |
497 operator<< (std::ostream& os, const jit_matrix& mat) | |
498 { | |
499 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
|
500 << mat.slice_len << ", " << mat.dimensions << ", " |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
501 << mat.array << ']'; |
15016 | 502 } |
503 | |
504 // -------------------- jit_type -------------------- | |
505 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
|
506 llvm::Type *allvm_type, bool askip_paren, int aid) : |
15016 | 507 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
|
508 mdepth (aparent ? aparent->mdepth + 1 : 0), mskip_paren (askip_paren) |
15016 | 509 { |
510 std::memset (msret, 0, sizeof (msret)); | |
511 std::memset (mpointer_arg, 0, sizeof (mpointer_arg)); | |
512 std::memset (mpack, 0, sizeof (mpack)); | |
513 std::memset (munpack, 0, sizeof (munpack)); | |
514 | |
515 for (size_t i = 0; i < jit_convention::length; ++i) | |
516 mpacked_type[i] = llvm_type; | |
517 } | |
518 | |
519 llvm::Type * | |
520 jit_type::to_llvm_arg (void) const | |
521 { | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
522 return llvm_type ? llvm_type->getPointerTo () : nullptr; |
15016 | 523 } |
524 | |
525 // -------------------- jit_function -------------------- | |
526 jit_function::jit_function () : module (0), llvm_function (0), mresult (0), | |
527 call_conv (jit_convention::length), | |
528 mcan_error (false) | |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
529 { } |
15016 | 530 |
531 jit_function::jit_function (llvm::Module *amodule, | |
532 jit_convention::type acall_conv, | |
533 const llvm::Twine& aname, jit_type *aresult, | |
534 const std::vector<jit_type *>& aargs) | |
535 : module (amodule), mresult (aresult), args (aargs), call_conv (acall_conv), | |
536 mcan_error (false) | |
537 { | |
538 llvm::SmallVector<llvm::Type *, 15> llvm_args; | |
539 | |
540 llvm::Type *rtype = llvm::Type::getVoidTy (context); | |
541 if (mresult) | |
542 { | |
543 rtype = mresult->packed_type (call_conv); | |
544 if (sret ()) | |
545 { | |
546 llvm_args.push_back (rtype->getPointerTo ()); | |
547 rtype = llvm::Type::getVoidTy (context); | |
548 } | |
549 } | |
550 | |
551 for (std::vector<jit_type *>::const_iterator iter = args.begin (); | |
552 iter != args.end (); ++iter) | |
553 { | |
554 jit_type *ty = *iter; | |
555 assert (ty); | |
556 llvm::Type *argty = ty->packed_type (call_conv); | |
557 if (ty->pointer_arg (call_conv)) | |
558 argty = argty->getPointerTo (); | |
559 | |
560 llvm_args.push_back (argty); | |
561 } | |
562 | |
563 // we mark all functinos as external linkage because this prevents llvm | |
564 // from getting rid of always inline functions | |
565 llvm::FunctionType *ft = llvm::FunctionType::get (rtype, llvm_args, false); | |
566 llvm_function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, | |
567 aname, module); | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
568 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
569 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
|
570 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
571 #if defined (FUNCTION_ADDATTRIBUTE_ARG_IS_ATTRIBUTES) |
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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 #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
|
577 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
|
578 #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
|
579 } |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
580 |
15016 | 581 if (call_conv == jit_convention::internal) |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
582 #if defined (FUNCTION_ADDFNATTR_ARG_IS_ATTRIBUTES) |
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
|
583 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
|
584 #else |
15016 | 585 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
|
586 #endif |
15016 | 587 } |
588 | |
589 jit_function::jit_function (const jit_function& fn, jit_type *aresult, | |
590 const std::vector<jit_type *>& aargs) | |
591 : module (fn.module), llvm_function (fn.llvm_function), mresult (aresult), | |
592 args (aargs), call_conv (fn.call_conv), mcan_error (fn.mcan_error) | |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
593 { } |
15016 | 594 |
595 jit_function::jit_function (const jit_function& fn) | |
596 : module (fn.module), llvm_function (fn.llvm_function), mresult (fn.mresult), | |
597 args (fn.args), call_conv (fn.call_conv), mcan_error (fn.mcan_error) | |
22417
48c00363dc74
maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
598 { } |
15016 | 599 |
15385
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
600 void |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
601 jit_function::erase (void) |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
602 { |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
603 if (! llvm_function) |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
604 return; |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
605 |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
606 llvm_function->eraseFromParent (); |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
607 llvm_function = 0; |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
608 } |
8ccb187b24e9
Erase partially created functions on JIT compilation failure (bug #37308)
Max Brister <max@2bass.com>
parents:
15370
diff
changeset
|
609 |
15016 | 610 std::string |
611 jit_function::name (void) const | |
612 { | |
613 return llvm_function->getName (); | |
614 } | |
615 | |
616 llvm::BasicBlock * | |
617 jit_function::new_block (const std::string& aname, | |
618 llvm::BasicBlock *insert_before) | |
619 { | |
620 return llvm::BasicBlock::Create (context, aname, llvm_function, | |
621 insert_before); | |
622 } | |
623 | |
624 llvm::Value * | |
625 jit_function::call (llvm::IRBuilderD& builder, | |
626 const std::vector<jit_value *>& in_args) const | |
627 { | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
628 if (! valid ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
629 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
|
630 |
15016 | 631 assert (in_args.size () == args.size ()); |
632 std::vector<llvm::Value *> llvm_args (args.size ()); | |
633 for (size_t i = 0; i < in_args.size (); ++i) | |
634 llvm_args[i] = in_args[i]->to_llvm (); | |
635 | |
636 return call (builder, llvm_args); | |
637 } | |
638 | |
639 llvm::Value * | |
640 jit_function::call (llvm::IRBuilderD& builder, | |
641 const std::vector<llvm::Value *>& in_args) const | |
642 { | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
643 if (! valid ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
644 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
|
645 |
15016 | 646 assert (in_args.size () == args.size ()); |
647 llvm::SmallVector<llvm::Value *, 10> llvm_args; | |
648 llvm_args.reserve (in_args.size () + sret ()); | |
649 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
650 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
|
651 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
|
652 assert (parent); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
653 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
654 // 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
|
655 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
|
656 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
|
657 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
658 llvm::AllocaInst *sret_mem = nullptr; |
15016 | 659 if (sret ()) |
660 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
661 sret_mem = pre_builder.CreateAlloca (mresult->packed_type (call_conv)); |
15016 | 662 llvm_args.push_back (sret_mem); |
663 } | |
664 | |
665 for (size_t i = 0; i < in_args.size (); ++i) | |
666 { | |
667 llvm::Value *arg = in_args[i]; | |
668 jit_type::convert_fn convert = args[i]->pack (call_conv); | |
669 if (convert) | |
670 arg = convert (builder, arg); | |
671 | |
672 if (args[i]->pointer_arg (call_conv)) | |
673 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 arg = alloca; |
15016 | 678 } |
679 | |
680 llvm_args.push_back (arg); | |
681 } | |
682 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
683 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
|
684 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
|
685 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
686 if (sret ()) |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
687 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21568
diff
changeset
|
688 #if defined (CALLINST_ADDATTRIBUTE_ARG_IS_ATTRIBUTES) |
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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 #else |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
694 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
|
695 #endif |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
696 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
|
697 } |
15016 | 698 |
699 if (mresult) | |
700 { | |
701 jit_type::convert_fn unpack = mresult->unpack (call_conv); | |
702 if (unpack) | |
703 ret = unpack (builder, ret); | |
704 } | |
705 | |
706 return ret; | |
707 } | |
708 | |
709 llvm::Value * | |
710 jit_function::argument (llvm::IRBuilderD& builder, size_t idx) const | |
711 { | |
712 assert (idx < args.size ()); | |
713 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
714 // FIXME: We should be treating arguments like a list, not a vector. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
715 // Shouldn't matter much for now, as the number of arguments shouldn't |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
716 // be much bigger than 4 |
15016 | 717 llvm::Function::arg_iterator iter = llvm_function->arg_begin (); |
718 if (sret ()) | |
719 ++iter; | |
720 | |
721 for (size_t i = 0; i < idx; ++i, ++iter); | |
722 | |
723 if (args[idx]->pointer_arg (call_conv)) | |
724 return builder.CreateLoad (iter); | |
725 | |
726 return iter; | |
727 } | |
728 | |
729 void | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
730 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
|
731 bool verify) |
15016 | 732 { |
733 assert (! rval == ! mresult); | |
734 | |
735 if (rval) | |
736 { | |
737 jit_type::convert_fn convert = mresult->pack (call_conv); | |
738 if (convert) | |
739 rval = convert (builder, rval); | |
740 | |
741 if (sret ()) | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
742 { |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
743 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
|
744 builder.CreateRetVoid (); |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
745 } |
15016 | 746 else |
747 builder.CreateRet (rval); | |
748 } | |
749 else | |
750 builder.CreateRetVoid (); | |
751 | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
752 if (verify) |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
753 llvm::verifyFunction (*llvm_function); |
15016 | 754 } |
755 | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
756 void |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
757 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
|
758 { |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
759 assert (valid ()); |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
760 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
|
761 } |
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
762 |
15016 | 763 std::ostream& |
764 operator<< (std::ostream& os, const jit_function& fn) | |
765 { | |
766 llvm::Function *lfn = fn.to_llvm (); | |
767 os << "jit_function: cc=" << fn.call_conv; | |
768 llvm::raw_os_ostream llvm_out (os); | |
769 lfn->print (llvm_out); | |
770 llvm_out.flush (); | |
771 return os; | |
772 } | |
773 | |
774 // -------------------- jit_operation -------------------- | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
775 jit_operation::~jit_operation (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
776 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
777 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
|
778 iter != generated.end (); ++iter) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
779 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
780 delete iter->first; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
781 delete iter->second; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
782 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
783 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
784 |
15016 | 785 void |
786 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
|
787 const std::vector<jit_type*>& args) |
15016 | 788 { |
789 if (args.size () >= overloads.size ()) | |
790 overloads.resize (args.size () + 1); | |
791 | |
792 Array<jit_function>& over = overloads[args.size ()]; | |
793 dim_vector dv (over.dims ()); | |
794 Array<octave_idx_type> idx = to_idx (args); | |
795 bool must_resize = false; | |
796 | |
797 if (dv.length () != idx.numel ()) | |
798 { | |
799 dv.resize (idx.numel ()); | |
800 must_resize = true; | |
801 } | |
802 | |
803 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
804 if (dv(i) <= idx(i)) | |
805 { | |
806 must_resize = true; | |
807 dv(i) = idx(i) + 1; | |
808 } | |
809 | |
810 if (must_resize) | |
811 over.resize (dv); | |
812 | |
813 over(idx) = func; | |
814 } | |
815 | |
816 const jit_function& | |
817 jit_operation::overload (const std::vector<jit_type*>& types) const | |
818 { | |
819 static jit_function null_overload; | |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
820 for (size_t i = 0; i < types.size (); ++i) |
15016 | 821 if (! types[i]) |
822 return null_overload; | |
823 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
824 if (types.size () >= overloads.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
825 return do_generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
826 |
15016 | 827 const Array<jit_function>& over = overloads[types.size ()]; |
828 dim_vector dv (over.dims ()); | |
829 Array<octave_idx_type> idx = to_idx (types); | |
830 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
831 if (idx(i) >= dv(i)) | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
832 return do_generate (types); |
15016 | 833 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
834 const jit_function& ret = over(idx); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
835 if (! ret.valid ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
836 return do_generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
837 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
838 return ret; |
15016 | 839 } |
840 | |
841 Array<octave_idx_type> | |
842 jit_operation::to_idx (const std::vector<jit_type*>& types) const | |
843 { | |
844 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
|
845 numel = std::max (numel, static_cast<octave_idx_type>(2)); |
15016 | 846 |
847 Array<octave_idx_type> idx (dim_vector (1, numel)); | |
848 for (octave_idx_type i = 0; i < static_cast<octave_idx_type> (types.size ()); | |
849 ++i) | |
850 idx(i) = types[i]->type_id (); | |
851 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
852 if (types.size () == 0) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
853 idx(0) = idx(1) = 0; |
15016 | 854 if (types.size () == 1) |
855 { | |
856 idx(1) = idx(0); | |
857 idx(0) = 0; | |
858 } | |
859 | |
860 return idx; | |
861 } | |
862 | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
863 const jit_function& |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
864 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
|
865 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
866 static jit_function null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
867 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
|
868 if (find != generated.end ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
869 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
870 if (find->second) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
871 return *find->second; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
872 else |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
873 return null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
874 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
875 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
876 jit_function *ret = generate (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
877 generated[new signature_vec (types)] = ret; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
878 return ret ? *ret : null_overload; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
879 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
880 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
881 jit_function * |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
882 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
|
883 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
884 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
885 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
886 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
887 bool |
22600
dd80fb1ef949
maint: minor style fixes for C++ code.
John W. Eaton <jwe@octave.org>
parents:
22417
diff
changeset
|
888 jit_operation::signature_cmp::operator () (const signature_vec *lhs, |
dd80fb1ef949
maint: minor style fixes for C++ code.
John W. Eaton <jwe@octave.org>
parents:
22417
diff
changeset
|
889 const signature_vec *rhs) const |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
890 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
891 const signature_vec& l = *lhs; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
892 const signature_vec& r = *rhs; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
893 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
894 if (l.size () < r.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
895 return true; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
896 else if (l.size () > r.size ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
897 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
898 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
899 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
|
900 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
901 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
|
902 return true; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
903 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
|
904 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
905 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
906 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
907 return false; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
908 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
909 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
910 // -------------------- jit_index_operation -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
911 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
912 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
|
913 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
914 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
|
915 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
916 // indexing a matrix with scalars |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
917 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
|
918 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
|
919 if (types[i] != scalar) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
920 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
921 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
922 return generate_matrix (types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
923 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
924 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
925 return 0; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
926 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
927 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
928 llvm::Value * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
929 jit_index_operation::create_arg_array (llvm::IRBuilderD& builder, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23247
diff
changeset
|
930 const jit_function& fn, size_t start_idx, |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
931 size_t end_idx) const |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
932 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
933 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
|
934 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
|
935 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
|
936 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
|
937 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
|
938 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
939 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
|
940 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
|
941 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
942 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
943 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
|
944 builder.CreateStore (array, array_mem); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
945 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
|
946 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
947 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
948 // -------------------- jit_paren_subsref -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
949 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
950 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
|
951 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
952 std::stringstream ss; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
953 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
|
954 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
955 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
|
956 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
|
957 ss.str (), scalar, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
958 fn->mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
959 llvm::BasicBlock *body = fn->new_block (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
960 llvm::IRBuilder<> builder (body); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
961 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
962 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
|
963 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
|
964 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
|
965 types.size () - 1); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
966 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
|
967 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
|
968 fn->do_return (builder, ret); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
969 return fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
970 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
971 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
972 void |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
973 jit_paren_subsref::do_initialize (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
974 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
975 std::vector<jit_type *> types (3); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
976 types[0] = jit_typeinfo::get_matrix (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
977 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
|
978 types[2] = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
979 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
980 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
|
981 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
|
982 "octave_jit_paren_scalar", scalar, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
983 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
|
984 paren_scalar.mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
985 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
986 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
987 // -------------------- jit_paren_subsasgn -------------------- |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
988 jit_function * |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
989 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
|
990 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
991 std::stringstream ss; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
992 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
|
993 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
994 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
|
995 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
|
996 ss.str (), matrix, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
997 fn->mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
998 llvm::BasicBlock *body = fn->new_block (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
999 llvm::IRBuilder<> builder (body); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1000 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1001 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
|
1002 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
|
1003 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
|
1004 types.size () - 2); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1005 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1006 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
|
1007 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
|
1008 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
|
1009 fn->do_return (builder, ret); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1010 return fn; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1011 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1012 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1013 void |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1014 jit_paren_subsasgn::do_initialize (void) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1015 { |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1016 if (paren_scalar.valid ()) |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1017 return; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1018 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1019 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
|
1020 std::vector<jit_type *> types (4); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1021 types[0] = matrix; |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1022 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
|
1023 types[2] = jit_typeinfo::get_index (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1024 types[3] = jit_typeinfo::get_scalar (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1025 |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1026 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
|
1027 "octave_jit_paren_scalar", matrix, types); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1028 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
|
1029 paren_scalar.mark_can_error (); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1030 } |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1031 |
15016 | 1032 // -------------------- jit_typeinfo -------------------- |
1033 void | |
1034 jit_typeinfo::initialize (llvm::Module *m, llvm::ExecutionEngine *e) | |
1035 { | |
1036 new jit_typeinfo (m, e); | |
1037 } | |
1038 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1039 // 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
|
1040 #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
|
1041 |
15016 | 1042 jit_typeinfo::jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e) |
1043 : module (m), engine (e), next_id (0), | |
1044 builder (*new llvm::IRBuilderD (context)) | |
1045 { | |
1046 instance = this; | |
1047 | |
1048 // FIXME: We should be registering types like in octave_value_typeinfo | |
1049 llvm::Type *any_t = llvm::StructType::create (context, "octave_base_value"); | |
1050 any_t = any_t->getPointerTo (); | |
1051 | |
1052 llvm::Type *scalar_t = llvm::Type::getDoubleTy (context); | |
1053 llvm::Type *bool_t = llvm::Type::getInt1Ty (context); | |
1054 llvm::Type *string_t = llvm::Type::getInt8Ty (context); | |
1055 string_t = string_t->getPointerTo (); | |
1056 llvm::Type *index_t = llvm::Type::getIntNTy (context, | |
1057 sizeof(octave_idx_type) * 8); | |
1058 | |
1059 llvm::StructType *range_t = llvm::StructType::create (context, "range"); | |
1060 std::vector<llvm::Type *> range_contents (4, scalar_t); | |
1061 range_contents[3] = index_t; | |
1062 range_t->setBody (range_contents); | |
1063 | |
1064 llvm::Type *refcount_t = llvm::Type::getIntNTy (context, sizeof(int) * 8); | |
1065 | |
1066 llvm::StructType *matrix_t = llvm::StructType::create (context, "matrix"); | |
1067 llvm::Type *matrix_contents[5]; | |
1068 matrix_contents[0] = refcount_t->getPointerTo (); | |
1069 matrix_contents[1] = scalar_t->getPointerTo (); | |
1070 matrix_contents[2] = index_t; | |
1071 matrix_contents[3] = index_t->getPointerTo (); | |
1072 matrix_contents[4] = string_t; | |
1073 matrix_t->setBody (llvm::makeArrayRef (matrix_contents, 5)); | |
1074 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1075 llvm::Type *complex_t = llvm::ArrayType::get (scalar_t, 2); |
15016 | 1076 |
1077 // complex_ret is what is passed to C functions in order to get calling | |
1078 // convention right | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1079 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
|
1080 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
|
1081 |
15016 | 1082 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
|
1083 { |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1084 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
|
1085 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
|
1086 } |
15016 | 1087 |
1088 // create types | |
1089 any = new_type ("any", 0, any_t); | |
1090 matrix = new_type ("matrix", any, matrix_t); | |
1091 complex = new_type ("complex", any, complex_t); | |
1092 scalar = new_type ("scalar", complex, scalar_t); | |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1093 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
|
1094 any_ptr = new_type ("any_ptr", 0, any_t->getPointerTo ()); |
15016 | 1095 range = new_type ("range", any, range_t); |
1096 string = new_type ("string", any, string_t); | |
1097 boolean = new_type ("bool", any, bool_t); | |
1098 index = new_type ("index", any, index_t); | |
1099 | |
1100 create_int (8); | |
1101 create_int (16); | |
1102 create_int (32); | |
1103 create_int (64); | |
1104 | |
1105 casts.resize (next_id + 1); | |
1106 identities.resize (next_id + 1); | |
1107 | |
1108 // specify calling conventions | |
1109 // FIXME: We should detect architecture and do something sane based on that | |
1110 // 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
|
1111 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
|
1112 matrix->mark_pointer_arg (jit_convention::external); |
15016 | 1113 |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1114 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
|
1115 range->mark_pointer_arg (jit_convention::external); |
15016 | 1116 |
1117 complex->set_pack (jit_convention::external, &jit_typeinfo::pack_complex); | |
1118 complex->set_unpack (jit_convention::external, &jit_typeinfo::unpack_complex); | |
1119 complex->set_packed_type (jit_convention::external, complex_ret); | |
1120 | |
1121 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
|
1122 complex->mark_sret (jit_convention::external); |
15016 | 1123 |
15078
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1124 paren_subsref_fn.initialize (module, engine); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1125 paren_subsasgn_fn.initialize (module, engine); |
fe4752f772e2
Generate ND indexing functions on demand in JIT.
Max Brister <max@2bass.com>
parents:
15068
diff
changeset
|
1126 |
15016 | 1127 // bind global variables |
1128 lerror_state = new llvm::GlobalVariable (*module, bool_t, false, | |
1129 llvm::GlobalValue::ExternalLinkage, | |
1130 0, "error_state"); | |
1131 engine->addGlobalMapping (lerror_state, | |
1132 reinterpret_cast<void *> (&error_state)); | |
1133 | |
15603 | 1134 // sig_atomic_type is going to be some sort of integer |
1135 sig_atomic_type = llvm::Type::getIntNTy (context, sizeof(sig_atomic_t) * 8); | |
1136 loctave_interrupt_state | |
1137 = new llvm::GlobalVariable (*module, sig_atomic_type, false, | |
1138 llvm::GlobalValue::ExternalLinkage, 0, | |
1139 "octave_interrupt_state"); | |
1140 engine->addGlobalMapping (loctave_interrupt_state, | |
1141 reinterpret_cast<void *> (&octave_interrupt_state)); | |
1142 | |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1143 // generic call function |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1144 { |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1145 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
|
1146 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
|
1147 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
|
1148 } |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
1149 |
15016 | 1150 // any with anything is an any op |
1151 jit_function fn; | |
1152 jit_type *binary_op_type = intN (sizeof (octave_value::binary_op) * 8); | |
1153 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
|
1154 jit_function any_binary = create_external (JIT_FN (octave_jit_binary_any_any), |
15016 | 1155 any, binary_op_type, any, any); |
1156 any_binary.mark_can_error (); | |
1157 binary_ops.resize (octave_value::num_binary_ops); | |
1158 for (size_t i = 0; i < octave_value::num_binary_ops; ++i) | |
1159 { | |
1160 octave_value::binary_op op = static_cast<octave_value::binary_op> (i); | |
1161 std::string op_name = octave_value::binary_op_as_string (op); | |
1162 binary_ops[i].stash_name ("binary" + op_name); | |
1163 } | |
1164 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1165 unary_ops.resize (octave_value::num_unary_ops); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1166 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
|
1167 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1168 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
|
1169 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
|
1170 unary_ops[i].stash_name ("unary" + op_name); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1171 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1172 |
15016 | 1173 for (int op = 0; op < octave_value::num_binary_ops; ++op) |
1174 { | |
1175 llvm::Twine fn_name ("octave_jit_binary_any_any_"); | |
1176 fn_name = fn_name + llvm::Twine (op); | |
1177 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1178 fn = create_internal (fn_name, any, any, any); |
15016 | 1179 fn.mark_can_error (); |
1180 llvm::BasicBlock *block = fn.new_block (); | |
1181 builder.SetInsertPoint (block); | |
1182 llvm::APInt op_int(sizeof (octave_value::binary_op) * 8, op, | |
1183 std::numeric_limits<octave_value::binary_op>::is_signed); | |
1184 llvm::Value *op_as_llvm = llvm::ConstantInt::get (llvm_bo_type, op_int); | |
1185 llvm::Value *ret = any_binary.call (builder, op_as_llvm, | |
1186 fn.argument (builder, 0), | |
1187 fn.argument (builder, 1)); | |
1188 fn.do_return (builder, ret); | |
1189 binary_ops[op].add_overload (fn); | |
1190 } | |
1191 | |
1192 // grab matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1193 fn = create_external (JIT_FN (octave_jit_grab_matrix), matrix, matrix); |
15016 | 1194 grab_fn.add_overload (fn); |
1195 | |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1196 grab_fn.add_overload (create_identity (scalar)); |
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1197 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
|
1198 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
|
1199 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
|
1200 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
|
1201 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
|
1202 |
15016 | 1203 // release any |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1204 fn = create_external (JIT_FN (octave_jit_release_any), 0, any); |
15016 | 1205 release_fn.add_overload (fn); |
1206 release_fn.stash_name ("release"); | |
1207 | |
1208 // release matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1209 fn = create_external (JIT_FN (octave_jit_release_matrix), 0, matrix); |
15016 | 1210 release_fn.add_overload (fn); |
1211 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1212 // destroy |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1213 destroy_fn = release_fn; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1214 destroy_fn.stash_name ("destroy"); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1215 destroy_fn.add_overload (create_identity(scalar)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1216 destroy_fn.add_overload (create_identity(boolean)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1217 destroy_fn.add_overload (create_identity(index)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1218 destroy_fn.add_overload (create_identity(complex)); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1219 |
18323
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1220 // -------------------- scalar related operations -------------------- |
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1221 |
15016 | 1222 // now for binary scalar operations |
1223 add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); | |
1224 add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); | |
1225 add_binary_op (scalar, octave_value::op_mul, llvm::Instruction::FMul); | |
1226 add_binary_op (scalar, octave_value::op_el_mul, llvm::Instruction::FMul); | |
1227 | |
1228 add_binary_fcmp (scalar, octave_value::op_lt, llvm::CmpInst::FCMP_ULT); | |
1229 add_binary_fcmp (scalar, octave_value::op_le, llvm::CmpInst::FCMP_ULE); | |
1230 add_binary_fcmp (scalar, octave_value::op_eq, llvm::CmpInst::FCMP_UEQ); | |
1231 add_binary_fcmp (scalar, octave_value::op_ge, llvm::CmpInst::FCMP_UGE); | |
1232 add_binary_fcmp (scalar, octave_value::op_gt, llvm::CmpInst::FCMP_UGT); | |
1233 add_binary_fcmp (scalar, octave_value::op_ne, llvm::CmpInst::FCMP_UNE); | |
1234 | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21040
diff
changeset
|
1235 jit_function gripe_div0 = create_external (JIT_FN (warn_divide_by_zero), 0); |
15016 | 1236 gripe_div0.mark_can_error (); |
1237 | |
1238 // 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
|
1239 fn = create_internal ("octave_jit_div_scalar_scalar", scalar, scalar, scalar); |
15016 | 1240 fn.mark_can_error (); |
1241 | |
1242 llvm::BasicBlock *body = fn.new_block (); | |
1243 builder.SetInsertPoint (body); | |
1244 { | |
1245 llvm::BasicBlock *warn_block = fn.new_block ("warn"); | |
1246 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
1247 | |
1248 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
|
1249 llvm::Value *check = builder.CreateFCmpUEQ (zero, fn.argument (builder, 1)); |
15016 | 1250 builder.CreateCondBr (check, warn_block, normal_block); |
1251 | |
1252 builder.SetInsertPoint (warn_block); | |
1253 gripe_div0.call (builder); | |
1254 builder.CreateBr (normal_block); | |
1255 | |
1256 builder.SetInsertPoint (normal_block); | |
1257 llvm::Value *ret = builder.CreateFDiv (fn.argument (builder, 0), | |
1258 fn.argument (builder, 1)); | |
1259 fn.do_return (builder, ret); | |
1260 } | |
1261 binary_ops[octave_value::op_div].add_overload (fn); | |
1262 binary_ops[octave_value::op_el_div].add_overload (fn); | |
1263 | |
1264 // ldiv is the same as div with the operators reversed | |
1265 fn = mirror_binary (fn); | |
1266 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
1267 binary_ops[octave_value::op_el_ldiv].add_overload (fn); | |
1268 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
1269 // In general, the result of scalar ^ scalar is a complex number. We might |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
1270 // be able to improve on this if we keep track of the range of values |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
1271 // variables can take on. |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1272 fn = create_external (JIT_FN (octave_jit_pow_scalar_scalar), complex, scalar, |
15016 | 1273 scalar); |
1274 binary_ops[octave_value::op_pow].add_overload (fn); | |
1275 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1276 | |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1277 // now for unary scalar operations |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1278 // FIXME: Impelment not |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1279 fn = create_internal ("octave_jit_++", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1280 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1281 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1282 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1283 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
|
1284 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1285 val = builder.CreateFAdd (val, one); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1286 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1287 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1288 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
|
1289 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1290 fn = create_internal ("octave_jit_--", scalar, scalar); |
15146
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1291 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1292 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1293 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1294 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
|
1295 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1296 val = builder.CreateFSub (val, one); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1297 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1298 } |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1299 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
|
1300 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1301 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
|
1302 body = fn.new_block (); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1303 builder.SetInsertPoint (body); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1304 { |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1305 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
|
1306 llvm::Value *val = fn.argument (builder, 0); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1307 val = builder.CreateFMul (val, mone); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1308 fn.do_return (builder, val); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1309 } |
18323
0122fad27435
jit compiler: Fix uminus op support with scalar type
LYH <lyh.kernel@gmail.com>
parents:
18279
diff
changeset
|
1310 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
|
1311 |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1312 fn = create_identity (scalar); |
709e8928e68c
Scalar unary operation support in JIT
Max Brister <max@2bass.com>
parents:
15136
diff
changeset
|
1313 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
|
1314 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
|
1315 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
|
1316 |
15016 | 1317 // 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
|
1318 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
|
1319 complex); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1320 body = fn.new_block (); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1321 builder.SetInsertPoint (body); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1322 { |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1323 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
|
1324 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
|
1325 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
|
1326 complex_real (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1327 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
|
1328 complex_imag (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1329 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
|
1330 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1331 binary_ops[octave_value::op_add].add_overload (fn); |
15016 | 1332 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1333 fn = create_internal ("octave_jit_-_complex_complex", complex, complex, |
15016 | 1334 complex); |
1335 body = fn.new_block (); | |
1336 builder.SetInsertPoint (body); | |
1337 { | |
1338 llvm::Value *lhs = fn.argument (builder, 0); | |
1339 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
|
1340 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
|
1341 complex_real (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1342 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
|
1343 complex_imag (rhs)); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1344 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
|
1345 } |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1346 binary_ops[octave_value::op_sub].add_overload (fn); |
15016 | 1347 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1348 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
|
1349 complex, complex, complex); |
15016 | 1350 binary_ops[octave_value::op_mul].add_overload (fn); |
1351 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
1352 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1353 jit_function complex_div = create_external (JIT_FN (octave_jit_complex_div), |
15016 | 1354 complex, complex, complex); |
1355 complex_div.mark_can_error (); | |
1356 binary_ops[octave_value::op_div].add_overload (fn); | |
1357 binary_ops[octave_value::op_ldiv].add_overload (fn); | |
1358 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1359 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
|
1360 complex, complex); |
15016 | 1361 binary_ops[octave_value::op_pow].add_overload (fn); |
1362 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1363 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1364 fn = create_internal ("octave_jit_*_scalar_complex", complex, scalar, |
15016 | 1365 complex); |
1366 jit_function mul_scalar_complex = fn; | |
1367 body = fn.new_block (); | |
1368 builder.SetInsertPoint (body); | |
1369 { | |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1370 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
|
1371 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
|
1372 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1373 llvm::Value *fzero = llvm::ConstantFP::get (scalar_t, 0); |
15016 | 1374 llvm::Value *lhs = fn.argument (builder, 0); |
1375 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
|
1376 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1377 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
|
1378 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
|
1379 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1380 builder.SetInsertPoint (scalar_mul); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1381 llvm::Value *temp = complex_real (rhs); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1382 temp = builder.CreateFMul (lhs, temp); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1383 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
|
1384 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
1385 builder.SetInsertPoint (complex_mul); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1386 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
|
1387 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
|
1388 fn.do_return (builder, temp); |
15016 | 1389 } |
1390 binary_ops[octave_value::op_mul].add_overload (fn); | |
1391 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
1392 | |
1393 fn = mirror_binary (mul_scalar_complex); | |
1394 binary_ops[octave_value::op_mul].add_overload (fn); | |
1395 binary_ops[octave_value::op_el_mul].add_overload (fn); | |
1396 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1397 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
|
1398 complex); |
15016 | 1399 body = fn.new_block (); |
1400 builder.SetInsertPoint (body); | |
1401 { | |
1402 llvm::Value *lhs = fn.argument (builder, 0); | |
1403 llvm::Value *rhs = fn.argument (builder, 1); | |
1404 llvm::Value *real = builder.CreateFAdd (lhs, complex_real (rhs)); | |
1405 fn.do_return (builder, complex_real (rhs, real)); | |
1406 } | |
1407 binary_ops[octave_value::op_add].add_overload (fn); | |
1408 | |
1409 fn = mirror_binary (fn); | |
1410 binary_ops[octave_value::op_add].add_overload (fn); | |
1411 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1412 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
|
1413 scalar); |
15016 | 1414 body = fn.new_block (); |
1415 builder.SetInsertPoint (body); | |
1416 { | |
1417 llvm::Value *lhs = fn.argument (builder, 0); | |
1418 llvm::Value *rhs = fn.argument (builder, 1); | |
1419 llvm::Value *real = builder.CreateFSub (complex_real (lhs), rhs); | |
1420 fn.do_return (builder, complex_real (lhs, real)); | |
1421 } | |
1422 binary_ops[octave_value::op_sub].add_overload (fn); | |
1423 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1424 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
|
1425 complex); |
15016 | 1426 body = fn.new_block (); |
1427 builder.SetInsertPoint (body); | |
1428 { | |
1429 llvm::Value *lhs = fn.argument (builder, 0); | |
1430 llvm::Value *rhs = fn.argument (builder, 1); | |
1431 llvm::Value *real = builder.CreateFSub (lhs, complex_real (rhs)); | |
1432 fn.do_return (builder, complex_real (rhs, real)); | |
1433 } | |
1434 binary_ops[octave_value::op_sub].add_overload (fn); | |
1435 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1436 fn = create_external (JIT_FN (octave_jit_pow_scalar_complex), complex, scalar, |
15016 | 1437 complex); |
1438 binary_ops[octave_value::op_pow].add_overload (fn); | |
1439 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1440 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1441 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
|
1442 complex, scalar); |
15016 | 1443 binary_ops[octave_value::op_pow].add_overload (fn); |
1444 binary_ops[octave_value::op_el_pow].add_overload (fn); | |
1445 | |
1446 // now for binary index operators | |
1447 add_binary_op (index, octave_value::op_add, llvm::Instruction::Add); | |
1448 | |
1449 // and binary bool operators | |
1450 add_binary_op (boolean, octave_value::op_el_or, llvm::Instruction::Or); | |
1451 add_binary_op (boolean, octave_value::op_el_and, llvm::Instruction::And); | |
1452 | |
1453 // now for printing functions | |
1454 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
|
1455 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
|
1456 add_print (scalar, reinterpret_cast<void *> (&octave_jit_print_scalar)); |
15016 | 1457 |
1458 // initialize for loop | |
1459 for_init_fn.stash_name ("for_init"); | |
1460 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1461 fn = create_internal ("octave_jit_for_range_init", index, range); |
15016 | 1462 body = fn.new_block (); |
1463 builder.SetInsertPoint (body); | |
1464 { | |
1465 llvm::Value *zero = llvm::ConstantInt::get (index_t, 0); | |
1466 fn.do_return (builder, zero); | |
1467 } | |
1468 for_init_fn.add_overload (fn); | |
1469 | |
1470 // bounds check for for loop | |
1471 for_check_fn.stash_name ("for_check"); | |
1472 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1473 fn = create_internal ("octave_jit_for_range_check", boolean, range, index); |
15016 | 1474 body = fn.new_block (); |
1475 builder.SetInsertPoint (body); | |
1476 { | |
1477 llvm::Value *nelem | |
1478 = builder.CreateExtractValue (fn.argument (builder, 0), 3); | |
1479 llvm::Value *idx = fn.argument (builder, 1); | |
1480 llvm::Value *ret = builder.CreateICmpULT (idx, nelem); | |
1481 fn.do_return (builder, ret); | |
1482 } | |
1483 for_check_fn.add_overload (fn); | |
1484 | |
1485 // index variabe for for loop | |
1486 for_index_fn.stash_name ("for_index"); | |
1487 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1488 fn = create_internal ("octave_jit_for_range_idx", scalar, range, index); |
15016 | 1489 body = fn.new_block (); |
1490 builder.SetInsertPoint (body); | |
1491 { | |
1492 llvm::Value *idx = fn.argument (builder, 1); | |
1493 llvm::Value *didx = builder.CreateSIToFP (idx, scalar_t); | |
1494 llvm::Value *rng = fn.argument (builder, 0); | |
1495 llvm::Value *base = builder.CreateExtractValue (rng, 0); | |
1496 llvm::Value *inc = builder.CreateExtractValue (rng, 2); | |
1497 | |
1498 llvm::Value *ret = builder.CreateFMul (didx, inc); | |
1499 ret = builder.CreateFAdd (base, ret); | |
1500 fn.do_return (builder, ret); | |
1501 } | |
1502 for_index_fn.add_overload (fn); | |
1503 | |
1504 // logically true | |
1505 logically_true_fn.stash_name ("logically_true"); | |
1506 | |
1507 jit_function gripe_nantl | |
23242
c21939b04931
Fix compilation of jit caused by cset d0562b3159c7 (bug #50398).
Mike Miller <mtmiller@octave.org>
parents:
23219
diff
changeset
|
1508 = create_external (JIT_FN (octave_jit_err_nan_to_logical_conversion), 0); |
15016 | 1509 gripe_nantl.mark_can_error (); |
1510 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1511 fn = create_internal ("octave_jit_logically_true_scalar", boolean, scalar); |
15016 | 1512 fn.mark_can_error (); |
1513 | |
1514 body = fn.new_block (); | |
1515 builder.SetInsertPoint (body); | |
1516 { | |
1517 llvm::BasicBlock *error_block = fn.new_block ("error"); | |
1518 llvm::BasicBlock *normal_block = fn.new_block ("normal"); | |
1519 | |
1520 llvm::Value *check = builder.CreateFCmpUNE (fn.argument (builder, 0), | |
1521 fn.argument (builder, 0)); | |
1522 builder.CreateCondBr (check, error_block, normal_block); | |
1523 | |
1524 builder.SetInsertPoint (error_block); | |
1525 gripe_nantl.call (builder); | |
1526 builder.CreateBr (normal_block); | |
1527 builder.SetInsertPoint (normal_block); | |
1528 | |
1529 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
1530 llvm::Value *ret = builder.CreateFCmpONE (fn.argument (builder, 0), zero); | |
1531 fn.do_return (builder, ret); | |
1532 } | |
1533 logically_true_fn.add_overload (fn); | |
1534 | |
1535 // logically_true boolean | |
1536 fn = create_identity (boolean); | |
1537 logically_true_fn.add_overload (fn); | |
1538 | |
1539 // make_range | |
1540 // FIXME: May be benificial to implement all in LLVM | |
1541 make_range_fn.stash_name ("make_range"); | |
1542 jit_function compute_nelem | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1543 = create_external (JIT_FN (octave_jit_compute_nelem), |
15016 | 1544 index, scalar, scalar, scalar); |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1545 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1546 fn = create_internal ("octave_jit_make_range", range, scalar, scalar, scalar); |
15016 | 1547 body = fn.new_block (); |
1548 builder.SetInsertPoint (body); | |
1549 { | |
1550 llvm::Value *base = fn.argument (builder, 0); | |
1551 llvm::Value *limit = fn.argument (builder, 1); | |
1552 llvm::Value *inc = fn.argument (builder, 2); | |
1553 llvm::Value *nelem = compute_nelem.call (builder, base, limit, inc); | |
1554 | |
1555 llvm::Value *dzero = llvm::ConstantFP::get (scalar_t, 0); | |
1556 llvm::Value *izero = llvm::ConstantInt::get (index_t, 0); | |
1557 llvm::Value *rng = llvm::ConstantStruct::get (range_t, dzero, dzero, dzero, | |
1558 izero, NULL); | |
1559 rng = builder.CreateInsertValue (rng, base, 0); | |
1560 rng = builder.CreateInsertValue (rng, limit, 1); | |
1561 rng = builder.CreateInsertValue (rng, inc, 2); | |
1562 rng = builder.CreateInsertValue (rng, nelem, 3); | |
1563 fn.do_return (builder, rng); | |
1564 } | |
1565 make_range_fn.add_overload (fn); | |
1566 | |
1567 // paren_subsref | |
1568 jit_type *jit_int = intN (sizeof (int) * 8); | |
1569 llvm::Type *int_t = jit_int->to_llvm (); | |
1570 jit_function ginvalid_index | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1571 = 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
|
1572 jit_function gindex_range = create_external (JIT_FN (octave_jit_gindex_range), |
15016 | 1573 0, jit_int, jit_int, index, |
1574 index); | |
1575 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1576 fn = create_internal ("()subsref", scalar, matrix, scalar); |
15016 | 1577 fn.mark_can_error (); |
1578 | |
1579 body = fn.new_block (); | |
1580 builder.SetInsertPoint (body); | |
1581 { | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
1582 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
|
1583 llvm::Value *one_int = llvm::ConstantInt::get (int_t, 1); |
15016 | 1584 |
1585 llvm::Value *undef = llvm::UndefValue::get (scalar_t); | |
1586 llvm::Value *mat = fn.argument (builder, 0); | |
1587 llvm::Value *idx = fn.argument (builder, 1); | |
1588 | |
1589 // convert index to scalar to integer, and check index >= 1 | |
1590 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); | |
1591 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); | |
1592 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
|
1593 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one_idx); |
15016 | 1594 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
1595 | |
1596 llvm::BasicBlock *done = fn.new_block ("done"); | |
1597 llvm::BasicBlock *conv_error = fn.new_block ("conv_error", done); | |
1598 llvm::BasicBlock *normal = fn.new_block ("normal", done); | |
1599 builder.CreateCondBr (cond, conv_error, normal); | |
1600 | |
1601 builder.SetInsertPoint (conv_error); | |
1602 ginvalid_index.call (builder); | |
1603 builder.CreateBr (done); | |
1604 | |
1605 builder.SetInsertPoint (normal); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1606 llvm::Value *len |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1607 = builder.CreateExtractValue (mat, llvm::ArrayRef<unsigned> (2)); |
15016 | 1608 cond = builder.CreateICmpSGT (int_idx, len); |
1609 | |
1610 llvm::BasicBlock *bounds_error = fn.new_block ("bounds_error", done); | |
1611 llvm::BasicBlock *success = fn.new_block ("success", done); | |
1612 builder.CreateCondBr (cond, bounds_error, success); | |
1613 | |
1614 builder.SetInsertPoint (bounds_error); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
1615 gindex_range.call (builder, one_int, one_int, int_idx, len); |
15016 | 1616 builder.CreateBr (done); |
1617 | |
1618 builder.SetInsertPoint (success); | |
1619 llvm::Value *data = builder.CreateExtractValue (mat, | |
1620 llvm::ArrayRef<unsigned> (1)); | |
1621 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); | |
1622 llvm::Value *ret = builder.CreateLoad (gep); | |
1623 builder.CreateBr (done); | |
1624 | |
1625 builder.SetInsertPoint (done); | |
1626 | |
1627 llvm::PHINode *merge = llvm::PHINode::Create (scalar_t, 3); | |
1628 builder.Insert (merge); | |
1629 merge->addIncoming (undef, conv_error); | |
1630 merge->addIncoming (undef, bounds_error); | |
1631 merge->addIncoming (ret, success); | |
1632 fn.do_return (builder, merge); | |
1633 } | |
1634 paren_subsref_fn.add_overload (fn); | |
1635 | |
1636 // paren subsasgn | |
1637 paren_subsasgn_fn.stash_name ("()subsasgn"); | |
1638 | |
1639 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
|
1640 = 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
|
1641 index, scalar); |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1642 |
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1643 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
|
1644 scalar); |
15016 | 1645 fn.mark_can_error (); |
1646 body = fn.new_block (); | |
1647 builder.SetInsertPoint (body); | |
1648 { | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
1649 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
|
1650 llvm::Value *one_int = llvm::ConstantInt::get (int_t, 1); |
15016 | 1651 |
1652 llvm::Value *mat = fn.argument (builder, 0); | |
1653 llvm::Value *idx = fn.argument (builder, 1); | |
1654 llvm::Value *value = fn.argument (builder, 2); | |
1655 | |
1656 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); | |
1657 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); | |
1658 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
|
1659 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one_idx); |
15016 | 1660 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
1661 | |
1662 llvm::BasicBlock *done = fn.new_block ("done"); | |
1663 | |
1664 llvm::BasicBlock *conv_error = fn.new_block ("conv_error", done); | |
1665 llvm::BasicBlock *normal = fn.new_block ("normal", done); | |
1666 builder.CreateCondBr (cond, conv_error, normal); | |
1667 builder.SetInsertPoint (conv_error); | |
1668 ginvalid_index.call (builder); | |
1669 builder.CreateBr (done); | |
1670 | |
1671 builder.SetInsertPoint (normal); | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1672 llvm::Value *len = builder.CreateExtractValue (mat, 2); |
15016 | 1673 cond0 = builder.CreateICmpSGT (int_idx, len); |
1674 | |
1675 llvm::Value *rcount = builder.CreateExtractValue (mat, 0); | |
1676 rcount = builder.CreateLoad (rcount); | |
18274
e243b705a726
Fix building JIT with 64-bit indexing (bug #41163).
Lasse Schuirmann <lasse@schuirmann.net>
parents:
17787
diff
changeset
|
1677 cond1 = builder.CreateICmpSGT (rcount, one_int); |
15016 | 1678 cond = builder.CreateOr (cond0, cond1); |
1679 | |
1680 llvm::BasicBlock *bounds_error = fn.new_block ("bounds_error", done); | |
1681 llvm::BasicBlock *success = fn.new_block ("success", done); | |
1682 builder.CreateCondBr (cond, bounds_error, success); | |
1683 | |
1684 // resize on out of bounds access | |
1685 builder.SetInsertPoint (bounds_error); | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
1686 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
|
1687 int_idx, value); |
15016 | 1688 builder.CreateBr (done); |
1689 | |
1690 builder.SetInsertPoint (success); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1691 llvm::Value *data |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1692 = builder.CreateExtractValue (mat, llvm::ArrayRef<unsigned> (1)); |
15016 | 1693 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); |
1694 builder.CreateStore (value, gep); | |
1695 builder.CreateBr (done); | |
1696 | |
1697 builder.SetInsertPoint (done); | |
1698 | |
1699 llvm::PHINode *merge = llvm::PHINode::Create (matrix_t, 3); | |
1700 builder.Insert (merge); | |
1701 merge->addIncoming (mat, conv_error); | |
1702 merge->addIncoming (resize_result, bounds_error); | |
1703 merge->addIncoming (mat, success); | |
1704 fn.do_return (builder, merge); | |
1705 } | |
1706 paren_subsasgn_fn.add_overload (fn); | |
1707 | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1708 fn = create_external (JIT_FN (octave_jit_paren_subsasgn_matrix_range), matrix, |
15016 | 1709 matrix, range, scalar); |
1710 fn.mark_can_error (); | |
1711 paren_subsasgn_fn.add_overload (fn); | |
1712 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1713 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
|
1714 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
|
1715 body = fn.new_block (); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1716 builder.SetInsertPoint (body); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1717 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1718 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
|
1719 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
|
1720 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
|
1721 } |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1722 end1_fn.add_overload (fn); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1723 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1724 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
|
1725 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
|
1726 index); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15027
diff
changeset
|
1727 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
|
1728 |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1729 // -------------------- create_undef -------------------- |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1730 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
|
1731 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
|
1732 create_undef_fn.add_overload (fn); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15334
diff
changeset
|
1733 |
15016 | 1734 casts[any->type_id ()].stash_name ("(any)"); |
1735 casts[scalar->type_id ()].stash_name ("(scalar)"); | |
1736 casts[complex->type_id ()].stash_name ("(complex)"); | |
1737 casts[matrix->type_id ()].stash_name ("(matrix)"); | |
15603 | 1738 casts[range->type_id ()].stash_name ("(range)"); |
15016 | 1739 |
1740 // cast any <- matrix | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1741 fn = create_external (JIT_FN (octave_jit_cast_any_matrix), any, matrix); |
15016 | 1742 casts[any->type_id ()].add_overload (fn); |
1743 | |
1744 // cast matrix <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1745 fn = create_external (JIT_FN (octave_jit_cast_matrix_any), matrix, any); |
15016 | 1746 casts[matrix->type_id ()].add_overload (fn); |
1747 | |
15027
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
1748 // cast any <- range |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1749 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
|
1750 casts[any->type_id ()].add_overload (fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
1751 |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
1752 // cast range <- any |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1753 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
|
1754 casts[range->type_id ()].add_overload (fn); |
741d2dbcc117
Check trip count before compiling for loops.
Max Brister <max@2bass.com>
parents:
15019
diff
changeset
|
1755 |
15016 | 1756 // cast any <- scalar |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1757 fn = create_external (JIT_FN (octave_jit_cast_any_scalar), any, scalar); |
15016 | 1758 casts[any->type_id ()].add_overload (fn); |
1759 | |
1760 // cast scalar <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1761 fn = create_external (JIT_FN (octave_jit_cast_scalar_any), scalar, any); |
15016 | 1762 casts[scalar->type_id ()].add_overload (fn); |
1763 | |
1764 // cast any <- complex | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1765 fn = create_external (JIT_FN (octave_jit_cast_any_complex), any, complex); |
15016 | 1766 casts[any->type_id ()].add_overload (fn); |
1767 | |
1768 // cast complex <- any | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1769 fn = create_external (JIT_FN (octave_jit_cast_complex_any), complex, any); |
15016 | 1770 casts[complex->type_id ()].add_overload (fn); |
1771 | |
1772 // cast complex <- scalar | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1773 fn = create_internal ("octave_jit_cast_complex_scalar", complex, scalar); |
15016 | 1774 body = fn.new_block (); |
1775 builder.SetInsertPoint (body); | |
1776 { | |
1777 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); | |
1778 fn.do_return (builder, complex_new (fn.argument (builder, 0), zero)); | |
1779 } | |
1780 casts[complex->type_id ()].add_overload (fn); | |
1781 | |
1782 // cast scalar <- complex | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1783 fn = create_internal ("octave_jit_cast_scalar_complex", scalar, complex); |
15016 | 1784 body = fn.new_block (); |
1785 builder.SetInsertPoint (body); | |
1786 fn.do_return (builder, complex_real (fn.argument (builder, 0))); | |
1787 casts[scalar->type_id ()].add_overload (fn); | |
1788 | |
1789 // cast any <- any | |
1790 fn = create_identity (any); | |
1791 casts[any->type_id ()].add_overload (fn); | |
1792 | |
1793 // cast scalar <- scalar | |
1794 fn = create_identity (scalar); | |
1795 casts[scalar->type_id ()].add_overload (fn); | |
1796 | |
1797 // cast complex <- complex | |
1798 fn = create_identity (complex); | |
1799 casts[complex->type_id ()].add_overload (fn); | |
1800 | |
1801 // -------------------- builtin functions -------------------- | |
1802 add_builtin ("#unknown_function"); | |
1803 unknown_function = builtins["#unknown_function"]; | |
1804 | |
1805 add_builtin ("sin"); | |
1806 register_intrinsic ("sin", llvm::Intrinsic::sin, scalar, scalar); | |
1807 register_generic ("sin", matrix, matrix); | |
1808 | |
1809 add_builtin ("cos"); | |
1810 register_intrinsic ("cos", llvm::Intrinsic::cos, scalar, scalar); | |
1811 register_generic ("cos", matrix, matrix); | |
1812 | |
1813 add_builtin ("exp"); | |
18446
634d9989bf7b
Fix copy&paste typo when registering exp with JIT (bug #41560).
Rik <rik@octave.org>
parents:
18323
diff
changeset
|
1814 register_intrinsic ("exp", llvm::Intrinsic::exp, scalar, scalar); |
15016 | 1815 register_generic ("exp", matrix, matrix); |
1816 | |
15169
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1817 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
|
1818 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
|
1819 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1820 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
|
1821 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
|
1822 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1823 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
|
1824 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
|
1825 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1826 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
|
1827 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
|
1828 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1829 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
|
1830 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
|
1831 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
|
1832 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1833 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
|
1834 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
|
1835 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
|
1836 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1837 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
|
1838 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
|
1839 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
|
1840 |
6242904370bd
Support balance, cond, det, norm, rand, magic, eye, and mod in JIT
Max Brister <max@2bass.com>
parents:
15148
diff
changeset
|
1841 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
|
1842 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
|
1843 |
15016 | 1844 casts.resize (next_id + 1); |
1845 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
|
1846 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
|
1847 any, any); |
15016 | 1848 jit_function release_any = get_release (any); |
1849 std::vector<jit_type *> args; | |
1850 args.resize (1); | |
1851 | |
1852 for (std::map<std::string, jit_type *>::iterator iter = builtins.begin (); | |
1853 iter != builtins.end (); ++iter) | |
1854 { | |
1855 jit_type *btype = iter->second; | |
1856 args[0] = btype; | |
1857 | |
15334
8125773322d4
Error on undefined an unused variables in JIT
Max Brister <max@2bass.com>
parents:
15311
diff
changeset
|
1858 grab_fn.add_overload (jit_function (grab_any, btype, args)); |
15016 | 1859 release_fn.add_overload (jit_function (release_any, 0, args)); |
1860 casts[any->type_id ()].add_overload (jit_function (any_id, any, args)); | |
1861 | |
1862 args[0] = any; | |
1863 casts[btype->type_id ()].add_overload (jit_function (any_id, btype, | |
1864 args)); | |
1865 } | |
1866 } | |
1867 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1868 const jit_function& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1869 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
|
1870 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1871 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
|
1872 if (ccount && ccount->value () == 1) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1873 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
|
1874 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1875 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
|
1876 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1877 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1878 jit_type* |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1879 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
|
1880 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
|
1881 { |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1882 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
|
1883 id_to_type.push_back (ret); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1884 return ret; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1885 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1886 |
15016 | 1887 void |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1888 jit_typeinfo::add_print (jit_type *ty, void *fptr) |
15016 | 1889 { |
1890 std::stringstream name; | |
1891 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
|
1892 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
|
1893 0, intN (8), ty); |
15016 | 1894 print_fn.add_overload (fn); |
1895 } | |
1896 | |
1897 // FIXME: cp between add_binary_op, add_binary_icmp, and add_binary_fcmp | |
1898 void | |
1899 jit_typeinfo::add_binary_op (jit_type *ty, int op, int llvm_op) | |
1900 { | |
1901 std::stringstream fname; | |
1902 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
1903 fname << "octave_jit_" << octave_value::binary_op_as_string (ov_op) | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1904 << '_' << ty->name (); |
15016 | 1905 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1906 jit_function fn = create_internal (fname.str (), ty, ty, ty); |
15016 | 1907 llvm::BasicBlock *block = fn.new_block (); |
1908 builder.SetInsertPoint (block); | |
1909 llvm::Instruction::BinaryOps temp | |
1910 = static_cast<llvm::Instruction::BinaryOps>(llvm_op); | |
1911 | |
1912 llvm::Value *ret = builder.CreateBinOp (temp, fn.argument (builder, 0), | |
1913 fn.argument (builder, 1)); | |
1914 fn.do_return (builder, ret); | |
1915 binary_ops[op].add_overload (fn); | |
1916 } | |
1917 | |
1918 void | |
1919 jit_typeinfo::add_binary_icmp (jit_type *ty, int op, int llvm_op) | |
1920 { | |
1921 std::stringstream fname; | |
1922 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
1923 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1924 << '_' << ty->name (); |
15016 | 1925 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1926 jit_function fn = create_internal (fname.str (), boolean, ty, ty); |
15016 | 1927 llvm::BasicBlock *block = fn.new_block (); |
1928 builder.SetInsertPoint (block); | |
1929 llvm::CmpInst::Predicate temp | |
1930 = static_cast<llvm::CmpInst::Predicate>(llvm_op); | |
1931 llvm::Value *ret = builder.CreateICmp (temp, fn.argument (builder, 0), | |
1932 fn.argument (builder, 1)); | |
1933 fn.do_return (builder, ret); | |
1934 binary_ops[op].add_overload (fn); | |
1935 } | |
1936 | |
1937 void | |
1938 jit_typeinfo::add_binary_fcmp (jit_type *ty, int op, int llvm_op) | |
1939 { | |
1940 std::stringstream fname; | |
1941 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
1942 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1943 << '_' << ty->name (); |
15016 | 1944 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1945 jit_function fn = create_internal (fname.str (), boolean, ty, ty); |
15016 | 1946 llvm::BasicBlock *block = fn.new_block (); |
1947 builder.SetInsertPoint (block); | |
1948 llvm::CmpInst::Predicate temp | |
1949 = static_cast<llvm::CmpInst::Predicate>(llvm_op); | |
1950 llvm::Value *ret = builder.CreateFCmp (temp, fn.argument (builder, 0), | |
1951 fn.argument (builder, 1)); | |
1952 fn.do_return (builder, ret); | |
1953 binary_ops[op].add_overload (fn); | |
1954 } | |
1955 | |
1956 jit_function | |
1957 jit_typeinfo::create_function (jit_convention::type cc, const llvm::Twine& name, | |
1958 jit_type *ret, | |
1959 const std::vector<jit_type *>& args) | |
1960 { | |
1961 jit_function result (module, cc, name, ret, args); | |
1962 return result; | |
1963 } | |
1964 | |
1965 jit_function | |
1966 jit_typeinfo::create_identity (jit_type *type) | |
1967 { | |
1968 size_t id = type->type_id (); | |
1969 if (id >= identities.size ()) | |
1970 identities.resize (id + 1); | |
1971 | |
1972 if (! identities[id].valid ()) | |
1973 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1974 std::stringstream name; |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1975 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
|
1976 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
1977 jit_function fn = create_internal (name.str (), type, type); |
15016 | 1978 llvm::BasicBlock *body = fn.new_block (); |
1979 builder.SetInsertPoint (body); | |
1980 fn.do_return (builder, fn.argument (builder, 0)); | |
1981 return identities[id] = fn; | |
1982 } | |
1983 | |
1984 return identities[id]; | |
1985 } | |
1986 | |
1987 llvm::Value * | |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1988 jit_typeinfo::do_insert_error_check (llvm::IRBuilderD& abuilder) |
15016 | 1989 { |
15019
ae3670d4df29
Update the execution engine's global mapping for external functions
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1990 return abuilder.CreateLoad (lerror_state); |
15016 | 1991 } |
1992 | |
15603 | 1993 llvm::Value * |
1994 jit_typeinfo::do_insert_interrupt_check (llvm::IRBuilderD& abuilder) | |
1995 { | |
1996 llvm::LoadInst *val = abuilder.CreateLoad (loctave_interrupt_state); | |
1997 val->setVolatile (true); | |
1998 return abuilder.CreateICmpSGT (val, abuilder.getInt32 (0)); | |
1999 } | |
2000 | |
15016 | 2001 void |
2002 jit_typeinfo::add_builtin (const std::string& name) | |
2003 { | |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
2004 jit_type *btype = new_type (name, any, any->to_llvm (), true); |
15016 | 2005 builtins[name] = btype; |
2006 | |
2007 octave_builtin *ov_builtin = find_builtin (name); | |
2008 if (ov_builtin) | |
2009 ov_builtin->stash_jit (*btype); | |
2010 } | |
2011 | |
2012 void | |
2013 jit_typeinfo::register_intrinsic (const std::string& name, size_t iid, | |
2014 jit_type *result, | |
2015 const std::vector<jit_type *>& args) | |
2016 { | |
2017 jit_type *builtin_type = builtins[name]; | |
2018 size_t nargs = args.size (); | |
2019 llvm::SmallVector<llvm::Type *, 5> llvm_args (nargs); | |
2020 for (size_t i = 0; i < nargs; ++i) | |
2021 llvm_args[i] = args[i]->to_llvm (); | |
2022 | |
2023 llvm::Intrinsic::ID id = static_cast<llvm::Intrinsic::ID> (iid); | |
2024 llvm::Function *ifun = llvm::Intrinsic::getDeclaration (module, id, | |
2025 llvm_args); | |
2026 std::stringstream fn_name; | |
2027 fn_name << "octave_jit_" << name; | |
2028 | |
2029 std::vector<jit_type *> args1 (nargs + 1); | |
2030 args1[0] = builtin_type; | |
2031 std::copy (args.begin (), args.end (), args1.begin () + 1); | |
2032 | |
2033 // The first argument will be the Octave function, but we already know that | |
2034 // the function call is the equivalent of the intrinsic, so we ignore it and | |
2035 // 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
|
2036 jit_function fn = create_internal (fn_name.str (), result, args1); |
15016 | 2037 llvm::BasicBlock *body = fn.new_block (); |
2038 builder.SetInsertPoint (body); | |
2039 | |
2040 llvm::SmallVector<llvm::Value *, 5> fargs (nargs); | |
2041 for (size_t i = 0; i < nargs; ++i) | |
2042 fargs[i] = fn.argument (builder, i + 1); | |
2043 | |
2044 llvm::Value *ret = builder.CreateCall (ifun, fargs); | |
2045 fn.do_return (builder, ret); | |
2046 paren_subsref_fn.add_overload (fn); | |
2047 } | |
2048 | |
2049 octave_builtin * | |
2050 jit_typeinfo::find_builtin (const std::string& name) | |
2051 { | |
23693
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
2052 octave::symbol_table& symtab |
b9378eff6d13
move symbol_table class inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
2053 = octave::__get_symbol_table__ ("jit_typeinfo::find_builtin"); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
2054 |
15016 | 2055 // FIXME: Finalize what we want to store in octave_builtin, then add functions |
2056 // to access these values in octave_value | |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23581
diff
changeset
|
2057 octave_value ov_builtin = symtab.find (name); |
15016 | 2058 return dynamic_cast<octave_builtin *> (ov_builtin.internal_rep ()); |
2059 } | |
2060 | |
2061 void | |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2062 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
|
2063 const std::vector<jit_type *>& args) |
15016 | 2064 { |
15135
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2065 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
|
2066 if (! builtin) |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2067 return; |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2068 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2069 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
|
2070 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
|
2071 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
|
2072 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
|
2073 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
|
2074 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
|
2075 builder.SetInsertPoint (block); |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2076 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
|
2077 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
|
2078 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
|
2079 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
|
2080 { |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2081 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
|
2082 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
|
2083 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
|
2084 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
|
2085 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
|
2086 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
|
2087 } |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2088 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2089 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
|
2090 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
|
2091 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
|
2092 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2093 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
|
2094 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
|
2095 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
|
2096 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
|
2097 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
|
2098 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
|
2099 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
|
2100 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
|
2101 |
bd6bb87e2bea
Support sin, cos, and exp with matrix arguments in JIT
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
2102 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
|
2103 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
|
2104 paren_subsref_fn.add_overload (fn); |
15016 | 2105 } |
2106 | |
2107 jit_function | |
2108 jit_typeinfo::mirror_binary (const jit_function& fn) | |
2109 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2110 jit_function ret = create_internal (fn.name () + "_reverse", |
15016 | 2111 fn.result (), fn.argument_type (1), |
2112 fn.argument_type (0)); | |
2113 if (fn.can_error ()) | |
2114 ret.mark_can_error (); | |
2115 | |
2116 llvm::BasicBlock *body = ret.new_block (); | |
2117 builder.SetInsertPoint (body); | |
2118 llvm::Value *result = fn.call (builder, ret.argument (builder, 1), | |
2119 ret.argument (builder, 0)); | |
2120 if (ret.result ()) | |
2121 ret.do_return (builder, result); | |
2122 else | |
2123 ret.do_return (builder); | |
2124 | |
2125 return ret; | |
2126 } | |
2127 | |
2128 llvm::Value * | |
2129 jit_typeinfo::pack_complex (llvm::IRBuilderD& bld, llvm::Value *cplx) | |
2130 { | |
2131 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
|
2132 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
|
2133 llvm::Value *imag = bld.CreateExtractValue (cplx, 1); |
15016 | 2134 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
|
2135 |
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2136 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
|
2137 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
|
2138 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
|
2139 return bld.CreateInsertValue (ret, imag, im_idx); |
15016 | 2140 } |
2141 | |
2142 llvm::Value * | |
2143 jit_typeinfo::unpack_complex (llvm::IRBuilderD& bld, llvm::Value *result) | |
2144 { | |
15370
8355fddce815
Use sret and do not use save/restore stack (bug #37308)
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
2145 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
|
2146 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
|
2147 |
15016 | 2148 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
|
2149 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
|
2150 llvm::Value *imag = bld.CreateExtractValue (result, im_idx); |
15016 | 2151 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
|
2152 |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2153 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
|
2154 return bld.CreateInsertValue (ret, imag, 1); |
15016 | 2155 } |
2156 | |
2157 llvm::Value * | |
2158 jit_typeinfo::complex_real (llvm::Value *cx) | |
2159 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2160 return builder.CreateExtractValue (cx, 0); |
15016 | 2161 } |
2162 | |
2163 llvm::Value * | |
2164 jit_typeinfo::complex_real (llvm::Value *cx, llvm::Value *real) | |
2165 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2166 return builder.CreateInsertValue (cx, real, 0); |
15016 | 2167 } |
2168 | |
2169 llvm::Value * | |
2170 jit_typeinfo::complex_imag (llvm::Value *cx) | |
2171 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2172 return builder.CreateExtractValue (cx, 1); |
15016 | 2173 } |
2174 | |
2175 llvm::Value * | |
2176 jit_typeinfo::complex_imag (llvm::Value *cx, llvm::Value *imag) | |
2177 { | |
15893
1f076c40c133
Do not use vectorized llvm commands for complex numbers
Max Brister <max@2bass.com>
parents:
15603
diff
changeset
|
2178 return builder.CreateInsertValue (cx, imag, 1); |
15016 | 2179 } |
2180 | |
2181 llvm::Value * | |
2182 jit_typeinfo::complex_new (llvm::Value *real, llvm::Value *imag) | |
2183 { | |
2184 llvm::Value *ret = llvm::UndefValue::get (complex->to_llvm ()); | |
2185 ret = complex_real (ret, real); | |
2186 return complex_imag (ret, imag); | |
2187 } | |
2188 | |
2189 void | |
2190 jit_typeinfo::create_int (size_t nbits) | |
2191 { | |
2192 std::stringstream tname; | |
2193 tname << "int" << nbits; | |
2194 ints[nbits] = new_type (tname.str (), any, llvm::Type::getIntNTy (context, | |
2195 nbits)); | |
2196 } | |
2197 | |
2198 jit_type * | |
2199 jit_typeinfo::intN (size_t nbits) const | |
2200 { | |
2201 std::map<size_t, jit_type *>::const_iterator iter = ints.find (nbits); | |
2202 if (iter != ints.end ()) | |
2203 return iter->second; | |
2204 | |
2205 throw jit_fail_exception ("No such integer type"); | |
2206 } | |
2207 | |
2208 jit_type * | |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23247
diff
changeset
|
2209 jit_typeinfo::do_type_of (const octave_value& ov) const |
15016 | 2210 { |
2211 if (ov.is_function ()) | |
2212 { | |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22022
diff
changeset
|
2213 // FIXME: This is ugly, we need to finalize how we want to do this, then |
15016 | 2214 // have octave_value fully support the needed functionality |
2215 octave_builtin *builtin | |
2216 = dynamic_cast<octave_builtin *> (ov.internal_rep ()); | |
2217 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
|
2218 : unknown_function; |
15016 | 2219 } |
2220 | |
2221 if (ov.is_range ()) | |
2222 return get_range (); | |
2223 | |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
2224 if (ov.is_double_type () && ! ov.iscomplex ()) |
15016 | 2225 { |
2226 if (ov.is_real_scalar ()) | |
2227 return get_scalar (); | |
2228 | |
2229 if (ov.is_matrix_type ()) | |
2230 return get_matrix (); | |
2231 } | |
2232 | |
2233 if (ov.is_complex_scalar ()) | |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2234 { |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2235 Complex cv = ov.complex_value (); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2236 |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2237 // We don't really represent complex values, instead we represent |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
2238 // 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
|
2239 if (cv.imag () != 0) |
15583
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2240 return get_complex (); |
0754bdfbc8fe
Correct multiplication complex multiplication with NaN in JIT
Max Brister <max@2bass.com>
parents:
15385
diff
changeset
|
2241 } |
15016 | 2242 |
2243 return get_any (); | |
2244 } | |
2245 | |
2246 #endif |