Mercurial > octave-nkf
annotate src/pt-jit.cc @ 14985:f5925478bc15
More support for complex numbers in JIT
* src/pt-jit.cc (octave_jit_cast_complex_any): Return result directly.
(octave_jit_complex_div, jit_typeinfo::wrap_complex,
jit_typeinfo::pack_complex, jit_typeinfo::unpack_complex): New function.
(jit_typeinfo::jit_typeinfo): Support more complex functionality.
(tree_jit::optimize): Write llvm bytecode to a file when debugging.
* src/pt-jit.h (jit_typeinfo::wrap_complex, jit_typeinfo::pack_complex,
jit_typeinfo): New declarations.
author | Max Brister <max@2bass.com> |
---|---|
date | Tue, 10 Jul 2012 15:55:05 -0500 |
parents | 561aad6a9e4b |
children | 70ff15b6d996 |
rev | line source |
---|---|
14899 | 1 /* |
2 | |
14901
516b4a15b775
doc: Copyright fix in pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14899
diff
changeset
|
3 Copyright (C) 2012 Max Brister <max@2bass.com> |
14899 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 | |
23 #define __STDC_LIMIT_MACROS | |
24 #define __STDC_CONSTANT_MACROS | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include <config.h> | |
28 #endif | |
29 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
30 #ifdef HAVE_LLVM |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
31 |
14899 | 32 #include "pt-jit.h" |
33 | |
34 #include <typeinfo> | |
35 | |
36 #include <llvm/LLVMContext.h> | |
37 #include <llvm/Module.h> | |
38 #include <llvm/Function.h> | |
39 #include <llvm/BasicBlock.h> | |
14973 | 40 #include <llvm/Intrinsics.h> |
14899 | 41 #include <llvm/Support/IRBuilder.h> |
42 #include <llvm/ExecutionEngine/ExecutionEngine.h> | |
43 #include <llvm/ExecutionEngine/JIT.h> | |
44 #include <llvm/PassManager.h> | |
45 #include <llvm/Analysis/Verifier.h> | |
14903 | 46 #include <llvm/Analysis/CallGraph.h> |
14899 | 47 #include <llvm/Analysis/Passes.h> |
48 #include <llvm/Target/TargetData.h> | |
49 #include <llvm/Transforms/Scalar.h> | |
14903 | 50 #include <llvm/Transforms/IPO.h> |
14899 | 51 #include <llvm/Support/TargetSelect.h> |
52 #include <llvm/Support/raw_os_ostream.h> | |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
53 #include <llvm/Support/FormattedStream.h> |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
54 #include <llvm/Bitcode/ReaderWriter.h> |
14899 | 55 |
14903 | 56 #include "octave.h" |
14899 | 57 #include "ov-fcn-handle.h" |
58 #include "ov-usr-fcn.h" | |
14973 | 59 #include "ov-builtin.h" |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
60 #include "ov-scalar.h" |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
61 #include "ov-complex.h" |
14899 | 62 #include "pt-all.h" |
63 | |
14903 | 64 static llvm::IRBuilder<> builder (llvm::getGlobalContext ()); |
65 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
66 static llvm::LLVMContext& context = llvm::getGlobalContext (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
67 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
68 jit_typeinfo *jit_typeinfo::instance; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
69 |
14906 | 70 // thrown when we should give up on JIT and interpret |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
71 class jit_fail_exception : public std::runtime_error |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
72 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
73 public: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
74 jit_fail_exception (void) : std::runtime_error ("unknown"), mknown (false) {} |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
75 jit_fail_exception (const std::string& reason) : std::runtime_error (reason), |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
76 mknown (true) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
77 {} |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
78 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
79 bool known (void) const { return mknown; } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
80 private: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
81 bool mknown; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
82 }; |
14906 | 83 |
14940
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
84 static void fail (void) GCC_ATTR_NORETURN; |
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
85 static void fail (const std::string&) GCC_ATTR_NORETURN; |
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
86 |
14906 | 87 static void |
88 fail (void) | |
89 { | |
90 throw jit_fail_exception (); | |
91 } | |
92 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
93 #ifdef OCTAVE_JIT_DEBUG |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
94 static void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
95 fail (const std::string& reason) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
96 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
97 throw jit_fail_exception (reason); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
98 } |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
99 #else |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
100 static void |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
101 fail (const std::string&) |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
102 { |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
103 throw jit_fail_exception (); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
104 } |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
105 #endif // OCTAVE_JIT_DEBUG |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
106 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
107 std::ostream& jit_print (std::ostream& os, jit_type *atype) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
108 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
109 if (! atype) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
110 return os << "null"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
111 return os << atype->name (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
112 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
113 |
14903 | 114 // function that jit code calls |
115 extern "C" void | |
116 octave_jit_print_any (const char *name, octave_base_value *obv) | |
117 { | |
118 obv->print_with_name (octave_stdout, name, true); | |
119 } | |
14899 | 120 |
121 extern "C" void | |
14903 | 122 octave_jit_print_double (const char *name, double value) |
14899 | 123 { |
124 // FIXME: We should avoid allocating a new octave_scalar each time | |
125 octave_value ov (value); | |
126 ov.print_with_name (octave_stdout, name); | |
127 } | |
128 | |
14903 | 129 extern "C" octave_base_value* |
130 octave_jit_binary_any_any (octave_value::binary_op op, octave_base_value *lhs, | |
131 octave_base_value *rhs) | |
132 { | |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
133 octave_value olhs (lhs, true); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
134 octave_value orhs (rhs, true); |
14903 | 135 octave_value result = do_binary_op (op, olhs, orhs); |
136 octave_base_value *rep = result.internal_rep (); | |
137 rep->grab (); | |
138 return rep; | |
139 } | |
140 | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
141 extern "C" octave_idx_type |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
142 octave_jit_compute_nelem (double base, double limit, double inc) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
143 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
144 Range rng = Range (base, limit, inc); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
145 return rng.nelem (); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
146 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
147 |
14903 | 148 extern "C" void |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
149 octave_jit_release_any (octave_base_value *obv) |
14903 | 150 { |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
151 obv->release (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
152 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
153 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
154 extern "C" void |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
155 octave_jit_release_matrix (jit_matrix *m) |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
156 { |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
157 delete m->array; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
158 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
159 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
160 extern "C" octave_base_value * |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
161 octave_jit_grab_any (octave_base_value *obv) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
162 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
163 obv->grab (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
164 return obv; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
165 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
166 |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
167 extern "C" void |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
168 octave_jit_grab_matrix (jit_matrix *result, jit_matrix *m) |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
169 { |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
170 *result = *m->array; |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
171 } |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
172 |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
173 extern "C" octave_base_value * |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
174 octave_jit_cast_any_matrix (jit_matrix *m) |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
175 { |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
176 octave_value ret (*m->array); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
177 octave_base_value *rep = ret.internal_rep (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
178 rep->grab (); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
179 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
180 return rep; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
181 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
182 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
183 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
184 octave_jit_cast_matrix_any (jit_matrix *ret, octave_base_value *obv) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
185 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
186 NDArray m = obv->array_value (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
187 *ret = m; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
188 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
189 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
190 extern "C" double |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
191 octave_jit_cast_scalar_any (octave_base_value *obv) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
192 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
193 double ret = obv->double_value (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
194 obv->release (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
195 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
196 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
197 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
198 extern "C" octave_base_value * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
199 octave_jit_cast_any_scalar (double value) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
200 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
201 return new octave_scalar (value); |
14903 | 202 } |
203 | |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
204 extern "C" Complex |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
205 octave_jit_cast_complex_any (octave_base_value *obv) |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
206 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
207 Complex ret = obv->complex_value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
208 obv->release (); |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
209 return ret; |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
210 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
211 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
212 extern "C" octave_base_value * |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
213 octave_jit_cast_any_complex (Complex c) |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
214 { |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
215 if (c.imag () == 0) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
216 return new octave_scalar (c.real ()); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
217 else |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
218 return new octave_complex (c); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
219 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
220 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
221 extern "C" void |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
222 octave_jit_gripe_nan_to_logical_conversion (void) |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
223 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
224 try |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
225 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
226 gripe_nan_to_logical_conversion (); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
227 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
228 catch (const octave_execution_exception&) |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
229 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
230 gripe_library_execution_error (); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
231 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
232 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
233 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
234 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
235 octave_jit_ginvalid_index (void) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
236 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
237 try |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
238 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
239 gripe_invalid_index (); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
240 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
241 catch (const octave_execution_exception&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
242 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
243 gripe_library_execution_error (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
244 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
245 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
246 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
247 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
248 octave_jit_gindex_range (int nd, int dim, octave_idx_type iext, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
249 octave_idx_type ext) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
250 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
251 try |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
252 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
253 gripe_index_out_of_range (nd, dim, iext, ext); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
254 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
255 catch (const octave_execution_exception&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
256 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
257 gripe_library_execution_error (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
258 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
259 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
260 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
261 extern "C" void |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
262 octave_jit_paren_subsasgn_impl (jit_matrix *mat, octave_idx_type index, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
263 double value) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
264 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
265 NDArray *array = mat->array; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
266 if (array->nelem () < index) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
267 array->resize1 (index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
268 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
269 double *data = array->fortran_vec (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
270 data[index - 1] = value; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
271 |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
272 mat->update (); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
273 } |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
274 |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
275 extern "C" void |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
276 octave_jit_paren_subsasgn_matrix_range (jit_matrix *result, jit_matrix *mat, |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
277 jit_range *index, double value) |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
278 { |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
279 NDArray *array = mat->array; |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
280 bool done = false; |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
281 |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
282 // optimize for the simple case (no resizing and no errors) |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
283 if (*array->jit_ref_count () == 1 |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
284 && index->all_elements_are_ints ()) |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
285 { |
14977
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
286 // this code is similar to idx_vector::fill, but we avoid allocating an |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
287 // idx_vector and its associated rep |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
288 octave_idx_type start = static_cast<octave_idx_type> (index->base) - 1; |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
289 octave_idx_type step = static_cast<octave_idx_type> (index->inc); |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
290 octave_idx_type nelem = index->nelem; |
14977
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
291 octave_idx_type final = start + nelem * step; |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
292 if (step < 0) |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
293 { |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
294 step = -step; |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
295 std::swap (final, start); |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
296 } |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
297 |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
298 if (start >= 0 && final < mat->slice_len) |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
299 { |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
300 done = true; |
14977
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
301 |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
302 double *data = array->jit_slice_data (); |
14977
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
303 if (step == 1) |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
304 std::fill (data + start, data + start + nelem, value); |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
305 else |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
306 { |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
307 for (octave_idx_type i = start; i < final; i += step) |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
308 data[i] = value; |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
309 } |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
310 } |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
311 } |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
312 |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
313 if (! done) |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
314 { |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
315 idx_vector idx (*index); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
316 NDArray avalue (dim_vector (1, 1)); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
317 avalue.xelem (0) = value; |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
318 array->assign (idx, avalue); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
319 } |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
320 |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
321 result->update (array); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
322 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
323 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
324 extern "C" Complex |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
325 octave_jit_complex_div (Complex lhs, Complex rhs) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
326 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
327 // see src/OPERATORS/op-cs-cs.cc |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
328 if (rhs == 0.0) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
329 gripe_divide_by_zero (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
330 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
331 return lhs / rhs; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
332 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
333 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
334 extern "C" void |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
335 octave_jit_print_matrix (jit_matrix *m) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
336 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
337 std::cout << *m << std::endl; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
338 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
339 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
340 static void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
341 gripe_bad_result (void) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
342 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
343 error ("incorrect type information given to the JIT compiler"); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
344 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
345 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
346 // FIXME: Add support for multiple outputs |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
347 extern "C" octave_base_value * |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
348 octave_jit_call (octave_builtin::fcn fn, size_t nargin, |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
349 octave_base_value **argin, jit_type *result_type) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
350 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
351 octave_value_list ovl (nargin); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
352 for (size_t i = 0; i < nargin; ++i) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
353 ovl.xelem (i) = octave_value (argin[i]); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
354 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
355 ovl = fn (ovl, 1); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
356 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
357 // These type checks are not strictly required, but I'm guessing that |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
358 // incorrect types will be entered on occasion. This will be very difficult to |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
359 // debug unless we do the sanity check here. |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
360 if (result_type) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
361 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
362 if (ovl.length () != 1) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
363 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
364 gripe_bad_result (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
365 return 0; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
366 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
367 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
368 octave_value& result = ovl.xelem (0); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
369 jit_type *jtype = jit_typeinfo::join (jit_typeinfo::type_of (result), |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
370 result_type); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
371 if (jtype != result_type) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
372 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
373 gripe_bad_result (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
374 return 0; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
375 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
376 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
377 octave_base_value *ret = result.internal_rep (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
378 ret->grab (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
379 return ret; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
380 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
381 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
382 if (! (ovl.length () == 0 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
383 || (ovl.length () == 1 && ovl.xelem (0).is_undefined ()))) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
384 gripe_bad_result (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
385 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
386 return 0; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
387 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
388 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
389 // -------------------- jit_range -------------------- |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
390 bool |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
391 jit_range::all_elements_are_ints () const |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
392 { |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
393 Range r (*this); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
394 return r.all_elements_are_ints (); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
395 } |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
396 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
397 std::ostream& |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
398 operator<< (std::ostream& os, const jit_range& rng) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
399 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
400 return os << "Range[" << rng.base << ", " << rng.limit << ", " << rng.inc |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
401 << ", " << rng.nelem << "]"; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
402 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
403 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
404 // -------------------- jit_matrix -------------------- |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
405 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
406 std::ostream& |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
407 operator<< (std::ostream& os, const jit_matrix& mat) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
408 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
409 return os << "Matrix[" << mat.ref_count << ", " << mat.slice_data << ", " |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
410 << mat.slice_len << ", " << mat.dimensions << ", " |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
411 << mat.array << "]"; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
412 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
413 |
14903 | 414 // -------------------- jit_type -------------------- |
415 llvm::Type * | |
416 jit_type::to_llvm_arg (void) const | |
417 { | |
418 return llvm_type ? llvm_type->getPointerTo () : 0; | |
419 } | |
420 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
421 // -------------------- jit_operation -------------------- |
14903 | 422 void |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
423 jit_operation::add_overload (const overload& func, |
14903 | 424 const std::vector<jit_type*>& args) |
425 { | |
426 if (args.size () >= overloads.size ()) | |
427 overloads.resize (args.size () + 1); | |
428 | |
429 Array<overload>& over = overloads[args.size ()]; | |
430 dim_vector dv (over.dims ()); | |
431 Array<octave_idx_type> idx = to_idx (args); | |
432 bool must_resize = false; | |
433 | |
434 if (dv.length () != idx.numel ()) | |
435 { | |
436 dv.resize (idx.numel ()); | |
437 must_resize = true; | |
438 } | |
439 | |
440 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
441 if (dv(i) <= idx(i)) | |
442 { | |
443 must_resize = true; | |
444 dv(i) = idx(i) + 1; | |
445 } | |
446 | |
447 if (must_resize) | |
448 over.resize (dv); | |
449 | |
450 over(idx) = func; | |
451 } | |
452 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
453 const jit_operation::overload& |
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
454 jit_operation::get_overload (const std::vector<jit_type*>& types) const |
14903 | 455 { |
456 // FIXME: We should search for the next best overload on failure | |
457 static overload null_overload; | |
458 if (types.size () >= overloads.size ()) | |
459 return null_overload; | |
460 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
461 for (size_t i =0; i < types.size (); ++i) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
462 if (! types[i]) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
463 return null_overload; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
464 |
14903 | 465 const Array<overload>& over = overloads[types.size ()]; |
466 dim_vector dv (over.dims ()); | |
467 Array<octave_idx_type> idx = to_idx (types); | |
468 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
469 if (idx(i) >= dv(i)) | |
470 return null_overload; | |
471 | |
472 return over(idx); | |
473 } | |
474 | |
475 Array<octave_idx_type> | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
476 jit_operation::to_idx (const std::vector<jit_type*>& types) const |
14903 | 477 { |
478 octave_idx_type numel = types.size (); | |
479 if (numel == 1) | |
480 numel = 2; | |
481 | |
482 Array<octave_idx_type> idx (dim_vector (1, numel)); | |
483 for (octave_idx_type i = 0; i < static_cast<octave_idx_type> (types.size ()); | |
484 ++i) | |
485 idx(i) = types[i]->type_id (); | |
486 | |
487 if (types.size () == 1) | |
488 { | |
489 idx(1) = idx(0); | |
490 idx(0) = 0; | |
491 } | |
492 | |
493 return idx; | |
494 } | |
495 | |
496 // -------------------- jit_typeinfo -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
497 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
498 jit_typeinfo::initialize (llvm::Module *m, llvm::ExecutionEngine *e) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
499 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
500 instance = new jit_typeinfo (m, e); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
501 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
502 |
14906 | 503 jit_typeinfo::jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e) |
504 : module (m), engine (e), next_id (0) | |
14899 | 505 { |
14903 | 506 // FIXME: We should be registering types like in octave_value_typeinfo |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
507 llvm::Type *any_t = llvm::StructType::create (context, "octave_base_value"); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
508 any_t = any_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
509 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
510 llvm::Type *scalar_t = llvm::Type::getDoubleTy (context); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
511 llvm::Type *bool_t = llvm::Type::getInt1Ty (context); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
512 llvm::Type *string_t = llvm::Type::getInt8Ty (context); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
513 string_t = string_t->getPointerTo (); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
514 llvm::Type *index_t = llvm::Type::getIntNTy (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
515 sizeof(octave_idx_type) * 8); |
14906 | 516 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
517 llvm::StructType *range_t = llvm::StructType::create (context, "range"); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
518 std::vector<llvm::Type *> range_contents (4, scalar_t); |
14906 | 519 range_contents[3] = index_t; |
520 range_t->setBody (range_contents); | |
521 | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
522 llvm::Type *refcount_t = llvm::Type::getIntNTy (context, sizeof(int) * 8); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
523 llvm::Type *int_t = refcount_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
524 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
525 llvm::StructType *matrix_t = llvm::StructType::create (context, "matrix"); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
526 llvm::Type *matrix_contents[5]; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
527 matrix_contents[0] = refcount_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
528 matrix_contents[1] = scalar_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
529 matrix_contents[2] = index_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
530 matrix_contents[3] = index_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
531 matrix_contents[4] = string_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
532 matrix_t->setBody (llvm::makeArrayRef (matrix_contents, 5)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
533 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
534 llvm::Type *complex_t = llvm::VectorType::get (scalar_t, 2); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
535 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
536 // this is the structure that C functions return. Use this in order to get calling |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
537 // conventions right. |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
538 complex_ret = llvm::StructType::create (context, "complex_ret"); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
539 llvm::Type *complex_ret_contents[] = {scalar_t, scalar_t}; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
540 complex_ret->setBody (complex_ret_contents); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
541 |
14903 | 542 // create types |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
543 any = new_type ("any", 0, any_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
544 matrix = new_type ("matrix", any, matrix_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
545 scalar = new_type ("scalar", any, scalar_t); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
546 range = new_type ("range", any, range_t); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
547 string = new_type ("string", any, string_t); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
548 boolean = new_type ("bool", any, bool_t); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
549 index = new_type ("index", any, index_t); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
550 complex = new_type ("complex", any, complex_t); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
551 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
552 casts.resize (next_id + 1); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
553 identities.resize (next_id + 1, 0); |
14903 | 554 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
555 // bind global variables |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
556 lerror_state = new llvm::GlobalVariable (*module, bool_t, false, |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
557 llvm::GlobalValue::ExternalLinkage, |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
558 0, "error_state"); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
559 engine->addGlobalMapping (lerror_state, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
560 reinterpret_cast<void *> (&error_state)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
561 |
14903 | 562 // any with anything is an any op |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
563 llvm::Function *fn; |
14903 | 564 llvm::Type *binary_op_type |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
565 = llvm::Type::getIntNTy (context, sizeof (octave_value::binary_op)); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
566 llvm::Function *any_binary = create_function ("octave_jit_binary_any_any", |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
567 any_t, binary_op_type, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
568 any_t, any_t); |
14903 | 569 engine->addGlobalMapping (any_binary, |
570 reinterpret_cast<void*>(&octave_jit_binary_any_any)); | |
571 | |
572 binary_ops.resize (octave_value::num_binary_ops); | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
573 for (size_t i = 0; i < octave_value::num_binary_ops; ++i) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
574 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
575 octave_value::binary_op op = static_cast<octave_value::binary_op> (i); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
576 std::string op_name = octave_value::binary_op_as_string (op); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
577 binary_ops[i].stash_name ("binary" + op_name); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
578 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
579 |
14903 | 580 for (int op = 0; op < octave_value::num_binary_ops; ++op) |
581 { | |
582 llvm::Twine fn_name ("octave_jit_binary_any_any_"); | |
583 fn_name = fn_name + llvm::Twine (op); | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
584 fn = create_function (fn_name, any, any, any); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
585 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 586 builder.SetInsertPoint (block); |
14903 | 587 llvm::APInt op_int(sizeof (octave_value::binary_op), op, |
588 std::numeric_limits<octave_value::binary_op>::is_signed); | |
589 llvm::Value *op_as_llvm = llvm::ConstantInt::get (binary_op_type, op_int); | |
14906 | 590 llvm::Value *ret = builder.CreateCall3 (any_binary, |
14903 | 591 op_as_llvm, |
592 fn->arg_begin (), | |
593 ++fn->arg_begin ()); | |
14906 | 594 builder.CreateRet (ret); |
14945 | 595 binary_ops[op].add_overload (fn, true, any, any, any); |
14903 | 596 } |
597 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
598 llvm::Type *void_t = llvm::Type::getVoidTy (context); |
14903 | 599 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
600 // grab any |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
601 fn = create_function ("octave_jit_grab_any", any, any); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
602 engine->addGlobalMapping (fn, reinterpret_cast<void*>(&octave_jit_grab_any)); |
14945 | 603 grab_fn.add_overload (fn, false, any, any); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
604 grab_fn.stash_name ("grab"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
605 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
606 // grab matrix |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
607 llvm::Function *print_matrix = create_function ("octave_jit_print_matrix", |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
608 void_t, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
609 matrix_t->getPointerTo ()); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
610 engine->addGlobalMapping (print_matrix, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
611 reinterpret_cast<void*>(&octave_jit_print_matrix)); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
612 fn = create_function ("octave_jit_grab_matrix", void_t, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
613 matrix_t->getPointerTo (), matrix_t->getPointerTo ()); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
614 engine->addGlobalMapping (fn, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
615 reinterpret_cast<void *> (&octave_jit_grab_matrix)); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
616 grab_fn.add_overload (fn, false, matrix, matrix); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
617 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
618 // release any |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
619 fn = create_function ("octave_jit_release_any", void_t, any_t); |
14973 | 620 llvm::Function *release_any = fn; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
621 engine->addGlobalMapping (fn, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
622 reinterpret_cast<void*>(&octave_jit_release_any)); |
14945 | 623 release_fn.add_overload (fn, false, 0, any); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
624 release_fn.stash_name ("release"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
625 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
626 // release matrix |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
627 fn = create_function ("octave_jit_release_matrix", void_t, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
628 matrix_t->getPointerTo ()); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
629 engine->addGlobalMapping (fn, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
630 reinterpret_cast<void *> (&octave_jit_release_matrix)); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
631 release_fn.add_overload (fn, false, 0, matrix); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
632 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
633 // release scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
634 fn = create_identity (scalar); |
14945 | 635 release_fn.add_overload (fn, false, 0, scalar); |
14903 | 636 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
637 // release complex |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
638 fn = create_identity (complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
639 release_fn.add_overload (fn, false, 0, complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
640 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
641 // release index |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
642 fn = create_identity (index); |
14945 | 643 release_fn.add_overload (fn, false, 0, index); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
644 |
14903 | 645 // now for binary scalar operations |
646 // FIXME: Finish all operations | |
647 add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); | |
648 add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); | |
649 add_binary_op (scalar, octave_value::op_mul, llvm::Instruction::FMul); | |
650 add_binary_op (scalar, octave_value::op_el_mul, llvm::Instruction::FMul); | |
651 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
652 add_binary_fcmp (scalar, octave_value::op_lt, llvm::CmpInst::FCMP_ULT); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
653 add_binary_fcmp (scalar, octave_value::op_le, llvm::CmpInst::FCMP_ULE); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
654 add_binary_fcmp (scalar, octave_value::op_eq, llvm::CmpInst::FCMP_UEQ); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
655 add_binary_fcmp (scalar, octave_value::op_ge, llvm::CmpInst::FCMP_UGE); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
656 add_binary_fcmp (scalar, octave_value::op_gt, llvm::CmpInst::FCMP_UGT); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
657 add_binary_fcmp (scalar, octave_value::op_ne, llvm::CmpInst::FCMP_UNE); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
658 |
14941 | 659 llvm::Function *gripe_div0 = create_function ("gripe_divide_by_zero", void_t); |
660 engine->addGlobalMapping (gripe_div0, | |
661 reinterpret_cast<void *> (&gripe_divide_by_zero)); | |
662 | |
663 // divide is annoying because it might error | |
664 fn = create_function ("octave_jit_div_scalar_scalar", scalar, scalar, scalar); | |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
665 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); |
14941 | 666 builder.SetInsertPoint (body); |
667 { | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
668 llvm::BasicBlock *warn_block = llvm::BasicBlock::Create (context, "warn", |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
669 fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
670 llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
671 "normal", fn); |
14941 | 672 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
673 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); |
14941 | 674 llvm::Value *check = builder.CreateFCmpUEQ (zero, ++fn->arg_begin ()); |
675 builder.CreateCondBr (check, warn_block, normal_block); | |
676 | |
677 builder.SetInsertPoint (warn_block); | |
678 builder.CreateCall (gripe_div0); | |
679 builder.CreateBr (normal_block); | |
680 | |
681 builder.SetInsertPoint (normal_block); | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
682 llvm::Value *ret = builder.CreateFDiv (fn->arg_begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
683 ++fn->arg_begin ()); |
14941 | 684 builder.CreateRet (ret); |
685 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
686 jit_operation::overload ol (fn, true, scalar, scalar, scalar); |
14941 | 687 binary_ops[octave_value::op_div].add_overload (ol); |
688 binary_ops[octave_value::op_el_div].add_overload (ol); | |
689 } | |
690 llvm::verifyFunction (*fn); | |
691 | |
692 // ldiv is the same as div with the operators reversed | |
693 llvm::Function *div = fn; | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
694 fn = create_function ("octave_jit_ldiv_scalar_scalar", scalar, scalar, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
695 scalar); |
14941 | 696 body = llvm::BasicBlock::Create (context, "body", fn); |
697 builder.SetInsertPoint (body); | |
698 { | |
699 llvm::Value *ret = builder.CreateCall2 (div, ++fn->arg_begin (), | |
700 fn->arg_begin ()); | |
701 builder.CreateRet (ret); | |
702 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
703 jit_operation::overload ol (fn, true, scalar, scalar, scalar); |
14941 | 704 binary_ops[octave_value::op_ldiv].add_overload (ol); |
705 binary_ops[octave_value::op_el_ldiv].add_overload (ol); | |
706 } | |
707 llvm::verifyFunction (*fn); | |
708 | |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
709 // now for binary complex operations |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
710 add_binary_op (complex, octave_value::op_add, llvm::Instruction::FAdd); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
711 add_binary_op (complex, octave_value::op_sub, llvm::Instruction::FSub); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
712 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
713 fn = create_function ("octave_jit_*_complex_complex", complex, complex, |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
714 complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
715 body = llvm::BasicBlock::Create (context, "body", fn); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
716 builder.SetInsertPoint (body); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
717 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
718 // (x0*x1 - y0*y1, x0*y1 + y0*x1) = (x0,y0) * (x1,y1) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
719 // We compute this in one vectorized multiplication, a subtraction, and an |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
720 // addition. |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
721 llvm::Value *lhs = fn->arg_begin (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
722 llvm::Value *rhs = ++fn->arg_begin (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
723 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
724 // FIXME: We need a better way of doing this, working with llvm's IR |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
725 // directly is sort of a pain. |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
726 llvm::Value *zero = builder.getInt32 (0); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
727 llvm::Value *one = builder.getInt32 (1); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
728 llvm::Value *two = builder.getInt32 (2); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
729 llvm::Value *three = builder.getInt32 (3); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
730 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
731 llvm::Type *vec4 = llvm::VectorType::get (scalar_t, 4); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
732 llvm::Value *mlhs = llvm::UndefValue::get (vec4); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
733 llvm::Value *mrhs = mlhs; |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
734 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
735 llvm::Value *temp = builder.CreateExtractElement (lhs, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
736 mlhs = builder.CreateInsertElement (mlhs, temp, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
737 mlhs = builder.CreateInsertElement (mlhs, temp, two); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
738 temp = builder.CreateExtractElement (lhs, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
739 mlhs = builder.CreateInsertElement (mlhs, temp, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
740 mlhs = builder.CreateInsertElement (mlhs, temp, three); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
741 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
742 temp = builder.CreateExtractElement (rhs, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
743 mrhs = builder.CreateInsertElement (mrhs, temp, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
744 mrhs = builder.CreateInsertElement (mrhs, temp, three); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
745 temp = builder.CreateExtractElement (rhs, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
746 mrhs = builder.CreateInsertElement (mrhs, temp, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
747 mrhs = builder.CreateInsertElement (mrhs, temp, two); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
748 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
749 llvm::Value *mres = builder.CreateFMul (mlhs, mrhs); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
750 llvm::Value *ret = llvm::UndefValue::get (complex_t); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
751 llvm::Value *tlhs = builder.CreateExtractElement (mres, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
752 llvm::Value *trhs = builder.CreateExtractElement (mres, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
753 temp = builder.CreateFSub (tlhs, trhs); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
754 ret = builder.CreateInsertElement (ret, temp, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
755 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
756 tlhs = builder.CreateExtractElement (mres, two); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
757 trhs = builder.CreateExtractElement (mres, three); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
758 temp = builder.CreateFAdd (tlhs, trhs); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
759 ret = builder.CreateInsertElement (ret, temp, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
760 builder.CreateRet (ret); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
761 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
762 jit_operation::overload ol (fn, false, complex, complex, complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
763 binary_ops[octave_value::op_mul].add_overload (ol); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
764 binary_ops[octave_value::op_el_mul].add_overload (ol); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
765 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
766 llvm::verifyFunction (*fn); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
767 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
768 fn = create_function ("octave_jit_*_scalar_complex", complex, scalar, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
769 complex); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
770 llvm::Function *mul_scalar_complex = fn; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
771 body = llvm::BasicBlock::Create (context, "body", fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
772 builder.SetInsertPoint (body); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
773 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
774 llvm::Value *lhs = fn->arg_begin (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
775 llvm::Value *tlhs = llvm::UndefValue::get (complex_t); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
776 tlhs = builder.CreateInsertElement (tlhs, lhs, builder.getInt32 (0)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
777 tlhs = builder.CreateInsertElement (tlhs, lhs, builder.getInt32 (1)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
778 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
779 llvm::Value *rhs = ++fn->arg_begin (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
780 builder.CreateRet (builder.CreateFMul (tlhs, rhs)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
781 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
782 jit_operation::overload ol (fn, false, complex, scalar, complex); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
783 binary_ops[octave_value::op_mul].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
784 binary_ops[octave_value::op_el_mul].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
785 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
786 llvm::verifyFunction (*fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
787 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
788 fn = create_function ("octave_jit_*_complex_scalar", complex, complex, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
789 scalar); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
790 body = llvm::BasicBlock::Create (context, "body", fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
791 builder.SetInsertPoint (body); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
792 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
793 llvm::Value *ret = builder.CreateCall2 (mul_scalar_complex, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
794 ++fn->arg_begin (), |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
795 fn->arg_begin ()); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
796 builder.CreateRet (ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
797 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
798 jit_operation::overload ol (fn, false, complex, complex, scalar); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
799 binary_ops[octave_value::op_mul].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
800 binary_ops[octave_value::op_el_mul].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
801 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
802 llvm::verifyFunction (*fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
803 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
804 llvm::Function *complex_div = create_function ("octave_jit_complex_div", |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
805 complex_ret, complex_ret, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
806 complex_ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
807 engine->addGlobalMapping (complex_div, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
808 reinterpret_cast<void *> (&octave_jit_complex_div)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
809 complex_div = wrap_complex (complex_div); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
810 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
811 jit_operation::overload ol (complex_div, true, complex, complex, complex); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
812 binary_ops[octave_value::op_div].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
813 binary_ops[octave_value::op_ldiv].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
814 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
815 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
816 fn = create_function ("octave_jit_\\_complex_complex", complex, complex, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
817 complex); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
818 body = llvm::BasicBlock::Create (context, "body", fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
819 builder.SetInsertPoint (body); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
820 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
821 builder.CreateRet (builder.CreateCall2 (complex_div, ++fn->arg_begin (), |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
822 fn->arg_begin ())); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
823 jit_operation::overload ol (fn, true, complex, complex, complex); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
824 binary_ops[octave_value::op_ldiv].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
825 binary_ops[octave_value::op_el_ldiv].add_overload (ol); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
826 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
827 llvm::verifyFunction (*fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
828 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
829 // now for binary index operators |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
830 add_binary_op (index, octave_value::op_add, llvm::Instruction::Add); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
831 |
14975
95bfd032f4c7
Add element wise boolean And and Or in JIT
Max Brister <max@2bass.com>
parents:
14974
diff
changeset
|
832 // and binary bool operators |
95bfd032f4c7
Add element wise boolean And and Or in JIT
Max Brister <max@2bass.com>
parents:
14974
diff
changeset
|
833 add_binary_op (boolean, octave_value::op_el_or, llvm::Instruction::Or); |
95bfd032f4c7
Add element wise boolean And and Or in JIT
Max Brister <max@2bass.com>
parents:
14974
diff
changeset
|
834 add_binary_op (boolean, octave_value::op_el_and, llvm::Instruction::And); |
95bfd032f4c7
Add element wise boolean And and Or in JIT
Max Brister <max@2bass.com>
parents:
14974
diff
changeset
|
835 |
14903 | 836 // now for printing functions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
837 print_fn.stash_name ("print"); |
14903 | 838 add_print (any, reinterpret_cast<void*> (&octave_jit_print_any)); |
839 add_print (scalar, reinterpret_cast<void*> (&octave_jit_print_double)); | |
14906 | 840 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
841 // initialize for loop |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
842 for_init_fn.stash_name ("for_init"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
843 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
844 fn = create_function ("octave_jit_for_range_init", index, range); |
14941 | 845 body = llvm::BasicBlock::Create (context, "body", fn); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
846 builder.SetInsertPoint (body); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
847 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
848 llvm::Value *zero = llvm::ConstantInt::get (index_t, 0); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
849 builder.CreateRet (zero); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
850 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
851 llvm::verifyFunction (*fn); |
14945 | 852 for_init_fn.add_overload (fn, false, index, range); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
853 |
14906 | 854 // bounds check for for loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
855 for_check_fn.stash_name ("for_check"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
856 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
857 fn = create_function ("octave_jit_for_range_check", boolean, range, index); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
858 body = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 859 builder.SetInsertPoint (body); |
860 { | |
861 llvm::Value *nelem | |
862 = builder.CreateExtractValue (fn->arg_begin (), 3); | |
863 llvm::Value *idx = ++fn->arg_begin (); | |
864 llvm::Value *ret = builder.CreateICmpULT (idx, nelem); | |
865 builder.CreateRet (ret); | |
866 } | |
867 llvm::verifyFunction (*fn); | |
14945 | 868 for_check_fn.add_overload (fn, false, boolean, range, index); |
14906 | 869 |
870 // index variabe for for loop | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
871 for_index_fn.stash_name ("for_index"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
872 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
873 fn = create_function ("octave_jit_for_range_idx", scalar, range, index); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
874 body = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 875 builder.SetInsertPoint (body); |
876 { | |
877 llvm::Value *idx = ++fn->arg_begin (); | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
878 llvm::Value *didx = builder.CreateSIToFP (idx, scalar_t); |
14906 | 879 llvm::Value *rng = fn->arg_begin (); |
880 llvm::Value *base = builder.CreateExtractValue (rng, 0); | |
881 llvm::Value *inc = builder.CreateExtractValue (rng, 2); | |
882 | |
883 llvm::Value *ret = builder.CreateFMul (didx, inc); | |
884 ret = builder.CreateFAdd (base, ret); | |
885 builder.CreateRet (ret); | |
886 } | |
887 llvm::verifyFunction (*fn); | |
14945 | 888 for_index_fn.add_overload (fn, false, scalar, range, index); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
889 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
890 // logically true |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
891 logically_true_fn.stash_name ("logically_true"); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
892 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
893 llvm::Function *gripe_nantl |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
894 = create_function ("octave_jit_gripe_nan_to_logical_conversion", void_t); |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
895 engine->addGlobalMapping (gripe_nantl, reinterpret_cast<void *> (&octave_jit_gripe_nan_to_logical_conversion)); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
896 |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
897 fn = create_function ("octave_jit_logically_true_scalar", boolean, scalar); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
898 body = llvm::BasicBlock::Create (context, "body", fn); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
899 builder.SetInsertPoint (body); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
900 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
901 llvm::BasicBlock *error_block = llvm::BasicBlock::Create (context, "error", |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
902 fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
903 llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
904 "normal", fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
905 |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
906 llvm::Value *check = builder.CreateFCmpUNE (fn->arg_begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
907 fn->arg_begin ()); |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
908 builder.CreateCondBr (check, error_block, normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
909 |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
910 builder.SetInsertPoint (error_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
911 builder.CreateCall (gripe_nantl); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
912 builder.CreateBr (normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
913 builder.SetInsertPoint (normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
914 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
915 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
916 llvm::Value *ret = builder.CreateFCmpONE (fn->arg_begin (), zero); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
917 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
918 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
919 llvm::verifyFunction (*fn); |
14945 | 920 logically_true_fn.add_overload (fn, true, boolean, scalar); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
921 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
922 fn = create_function ("octave_logically_true_bool", boolean, boolean); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
923 body = llvm::BasicBlock::Create (context, "body", fn); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
924 builder.SetInsertPoint (body); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
925 builder.CreateRet (fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
926 llvm::verifyFunction (*fn); |
14945 | 927 logically_true_fn.add_overload (fn, false, boolean, boolean); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
928 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
929 // make_range |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
930 // FIXME: May be benificial to implement all in LLVM |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
931 make_range_fn.stash_name ("make_range"); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
932 llvm::Function *compute_nelem |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
933 = create_function ("octave_jit_compute_nelem", index, scalar, scalar, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
934 scalar); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
935 engine->addGlobalMapping (compute_nelem, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
936 reinterpret_cast<void*> (&octave_jit_compute_nelem)); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
937 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
938 fn = create_function ("octave_jit_make_range", range, scalar, scalar, scalar); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
939 body = llvm::BasicBlock::Create (context, "body", fn); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
940 builder.SetInsertPoint (body); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
941 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
942 llvm::Function::arg_iterator args = fn->arg_begin (); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
943 llvm::Value *base = args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
944 llvm::Value *limit = ++args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
945 llvm::Value *inc = ++args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
946 llvm::Value *nelem = builder.CreateCall3 (compute_nelem, base, limit, inc); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
947 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
948 llvm::Value *dzero = llvm::ConstantFP::get (scalar_t, 0); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
949 llvm::Value *izero = llvm::ConstantInt::get (index_t, 0); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
950 llvm::Value *rng = llvm::ConstantStruct::get (range_t, dzero, dzero, dzero, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
951 izero, NULL); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
952 rng = builder.CreateInsertValue (rng, base, 0); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
953 rng = builder.CreateInsertValue (rng, limit, 1); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
954 rng = builder.CreateInsertValue (rng, inc, 2); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
955 rng = builder.CreateInsertValue (rng, nelem, 3); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
956 builder.CreateRet (rng); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
957 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
958 llvm::verifyFunction (*fn); |
14945 | 959 make_range_fn.add_overload (fn, false, range, scalar, scalar, scalar); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
960 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
961 // paren_subsref |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
962 llvm::Function *ginvalid_index = create_function ("gipe_invalid_index", |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
963 void_t); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
964 engine->addGlobalMapping (ginvalid_index, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
965 reinterpret_cast<void*> (&octave_jit_ginvalid_index)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
966 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
967 llvm::Function *gindex_range = create_function ("gripe_index_out_of_range", |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
968 void_t, int_t, int_t, index_t, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
969 index_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
970 engine->addGlobalMapping (gindex_range, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
971 reinterpret_cast<void*> (&octave_jit_gindex_range)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
972 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
973 fn = create_function ("()subsref", scalar, matrix, scalar); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
974 body = llvm::BasicBlock::Create (context, "body", fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
975 builder.SetInsertPoint (body); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
976 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
977 llvm::Value *one = llvm::ConstantInt::get (index_t, 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
978 llvm::Value *ione; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
979 if (index_t == int_t) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
980 ione = one; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
981 else |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
982 ione = llvm::ConstantInt::get (int_t, 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
983 |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
984 llvm::Value *undef = llvm::UndefValue::get (scalar_t); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
985 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
986 llvm::Function::arg_iterator args = fn->arg_begin (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
987 llvm::Value *mat = args++; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
988 llvm::Value *idx = args; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
989 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
990 // convert index to scalar to integer, and check index >= 1 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
991 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
992 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
993 llvm::Value *cond0 = builder.CreateFCmpUNE (idx, check_idx); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
994 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
995 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
996 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
997 llvm::BasicBlock *done = llvm::BasicBlock::Create (context, "done", fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
998 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
999 llvm::BasicBlock *conv_error = llvm::BasicBlock::Create (context, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1000 "conv_error", fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1001 done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1002 llvm::BasicBlock *normal = llvm::BasicBlock::Create (context, "normal", fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1003 done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1004 builder.CreateCondBr (cond, conv_error, normal); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1005 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1006 builder.SetInsertPoint (conv_error); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1007 builder.CreateCall (ginvalid_index); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1008 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1009 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1010 builder.SetInsertPoint (normal); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1011 llvm::Value *len = builder.CreateExtractValue (mat, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1012 llvm::ArrayRef<unsigned> (2)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1013 cond = builder.CreateICmpSGT (int_idx, len); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1014 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1015 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1016 llvm::BasicBlock *bounds_error = llvm::BasicBlock::Create (context, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1017 "bounds_error", |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1018 fn, done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1019 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1020 llvm::BasicBlock *success = llvm::BasicBlock::Create (context, "success", |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1021 fn, done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1022 builder.CreateCondBr (cond, bounds_error, success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1023 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1024 builder.SetInsertPoint (bounds_error); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1025 builder.CreateCall4 (gindex_range, ione, ione, int_idx, len); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1026 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1027 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1028 builder.SetInsertPoint (success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1029 llvm::Value *data = builder.CreateExtractValue (mat, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1030 llvm::ArrayRef<unsigned> (1)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1031 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1032 llvm::Value *ret = builder.CreateLoad (gep); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1033 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1034 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1035 builder.SetInsertPoint (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1036 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1037 llvm::PHINode *merge = llvm::PHINode::Create (scalar_t, 3); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1038 builder.Insert (merge); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
1039 merge->addIncoming (undef, conv_error); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
1040 merge->addIncoming (undef, bounds_error); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1041 merge->addIncoming (ret, success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1042 builder.CreateRet (merge); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1043 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1044 llvm::verifyFunction (*fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1045 paren_subsref_fn.add_overload (fn, true, scalar, matrix, scalar); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1046 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1047 // paren subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1048 paren_subsasgn_fn.stash_name ("()subsasgn"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1049 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1050 llvm::Function *resize_paren_subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1051 = create_function ("octave_jit_paren_subsasgn_impl", void_t, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1052 matrix_t->getPointerTo (), index_t, scalar_t); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1053 engine->addGlobalMapping (resize_paren_subsasgn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1054 reinterpret_cast<void *> (&octave_jit_paren_subsasgn_impl)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1055 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1056 fn = create_function ("octave_jit_paren_subsasgn", matrix, matrix, scalar, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1057 scalar); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1058 body = llvm::BasicBlock::Create (context, "body", fn); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1059 builder.SetInsertPoint (body); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1060 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1061 llvm::Value *one = llvm::ConstantInt::get (index_t, 1); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1062 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1063 llvm::Function::arg_iterator args = fn->arg_begin (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1064 llvm::Value *mat = args++; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1065 llvm::Value *idx = args++; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1066 llvm::Value *value = args; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1067 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1068 llvm::Value *int_idx = builder.CreateFPToSI (idx, index_t); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1069 llvm::Value *check_idx = builder.CreateSIToFP (int_idx, scalar_t); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1070 llvm::Value *cond0 = builder.CreateFCmpUNE (idx, check_idx); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1071 llvm::Value *cond1 = builder.CreateICmpSLT (int_idx, one); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1072 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1073 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1074 llvm::BasicBlock *done = llvm::BasicBlock::Create (context, "done", fn); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1075 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1076 llvm::BasicBlock *conv_error = llvm::BasicBlock::Create (context, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1077 "conv_error", fn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1078 done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1079 llvm::BasicBlock *normal = llvm::BasicBlock::Create (context, "normal", fn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1080 done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1081 builder.CreateCondBr (cond, conv_error, normal); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1082 builder.SetInsertPoint (conv_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1083 builder.CreateCall (ginvalid_index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1084 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1085 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1086 builder.SetInsertPoint (normal); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1087 llvm::Value *len = builder.CreateExtractValue (mat, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1088 llvm::ArrayRef<unsigned> (2)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1089 cond0 = builder.CreateICmpSGT (int_idx, len); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1090 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1091 llvm::Value *rcount = builder.CreateExtractValue (mat, 0); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1092 rcount = builder.CreateLoad (rcount); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1093 cond1 = builder.CreateICmpSGT (rcount, one); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1094 cond = builder.CreateOr (cond0, cond1); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1095 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1096 llvm::BasicBlock *bounds_error = llvm::BasicBlock::Create (context, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1097 "bounds_error", |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1098 fn, done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1099 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1100 llvm::BasicBlock *success = llvm::BasicBlock::Create (context, "success", |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1101 fn, done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1102 builder.CreateCondBr (cond, bounds_error, success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1103 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1104 // resize on out of bounds access |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1105 builder.SetInsertPoint (bounds_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1106 llvm::Value *resize_result = builder.CreateAlloca (matrix_t); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1107 builder.CreateStore (mat, resize_result); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1108 builder.CreateCall3 (resize_paren_subsasgn, resize_result, int_idx, value); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1109 resize_result = builder.CreateLoad (resize_result); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1110 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1111 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1112 builder.SetInsertPoint (success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1113 llvm::Value *data = builder.CreateExtractValue (mat, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1114 llvm::ArrayRef<unsigned> (1)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1115 llvm::Value *gep = builder.CreateInBoundsGEP (data, int_idx); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1116 builder.CreateStore (value, gep); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1117 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1118 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1119 builder.SetInsertPoint (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1120 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1121 llvm::PHINode *merge = llvm::PHINode::Create (matrix_t, 3); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1122 builder.Insert (merge); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1123 merge->addIncoming (mat, conv_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1124 merge->addIncoming (resize_result, bounds_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1125 merge->addIncoming (mat, success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1126 builder.CreateRet (merge); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1127 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1128 llvm::verifyFunction (*fn); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1129 paren_subsasgn_fn.add_overload (fn, true, matrix, matrix, scalar, scalar); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1130 |
14976
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
1131 fn = create_function ("octave_jit_paren_subsasgn_matrix_range", void_t, |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
1132 matrix_t->getPointerTo (), matrix_t->getPointerTo (), |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
1133 range_t->getPointerTo (), scalar_t); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
1134 engine->addGlobalMapping (fn, |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
1135 reinterpret_cast<void *> (&octave_jit_paren_subsasgn_matrix_range)); |
2d7c0c86e712
In jit support A(idx) = v; where A is matrix, idx is a range, and v is a scalar
Max Brister <max@2bass.com>
parents:
14975
diff
changeset
|
1136 paren_subsasgn_fn.add_overload (fn, true, matrix, matrix, range, scalar); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1137 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1138 casts[any->type_id ()].stash_name ("(any)"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1139 casts[scalar->type_id ()].stash_name ("(scalar)"); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1140 casts[complex->type_id ()].stash_name ("(complex)"); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1141 casts[matrix->type_id ()].stash_name ("(matrix)"); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1142 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1143 // cast any <- matrix |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1144 fn = create_function ("octave_jit_cast_any_matrix", any_t, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1145 matrix_t->getPointerTo ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1146 engine->addGlobalMapping (fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1147 reinterpret_cast<void*> (&octave_jit_cast_any_matrix)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1148 casts[any->type_id ()].add_overload (fn, false, any, matrix); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1149 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1150 // cast matrix <- any |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1151 fn = create_function ("octave_jit_cast_matrix_any", void_t, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1152 matrix_t->getPointerTo (), any_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1153 engine->addGlobalMapping (fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1154 reinterpret_cast<void*> (&octave_jit_cast_matrix_any)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1155 casts[matrix->type_id ()].add_overload (fn, false, matrix, any); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1156 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1157 // cast any <- scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1158 fn = create_function ("octave_jit_cast_any_scalar", any, scalar); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1159 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_any_scalar)); |
14945 | 1160 casts[any->type_id ()].add_overload (fn, false, any, scalar); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1161 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1162 // cast scalar <- any |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1163 fn = create_function ("octave_jit_cast_scalar_any", scalar, any); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1164 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_scalar_any)); |
14945 | 1165 casts[scalar->type_id ()].add_overload (fn, false, scalar, any); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1166 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1167 // cast any <- complex |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1168 fn = create_function ("octave_jit_cast_any_complex", any_t, complex_ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1169 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_any_complex)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1170 casts[any->type_id ()].add_overload (wrap_complex (fn), false, any, complex); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1171 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1172 // cast complex <- any |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1173 fn = create_function ("octave_jit_cast_complex_any", complex_ret, any_t); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1174 engine->addGlobalMapping (fn, reinterpret_cast<void *> (&octave_jit_cast_complex_any)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1175 casts[complex->type_id ()].add_overload (wrap_complex (fn), false, complex, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1176 any); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1177 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1178 // cast any <- any |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1179 fn = create_identity (any); |
14945 | 1180 casts[any->type_id ()].add_overload (fn, false, any, any); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1181 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1182 // cast scalar <- scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1183 fn = create_identity (scalar); |
14945 | 1184 casts[scalar->type_id ()].add_overload (fn, false, scalar, scalar); |
14973 | 1185 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1186 // cast complex <- complex |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1187 fn = create_identity (complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1188 casts[complex->type_id ()].add_overload (fn, false, complex, complex); |
14973 | 1189 |
1190 // -------------------- builtin functions -------------------- | |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1191 add_builtin ("sin"); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1192 register_intrinsic ("sin", llvm::Intrinsic::sin, scalar, scalar); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1193 register_generic ("sin", matrix, matrix); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1194 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1195 add_builtin ("cos"); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1196 register_intrinsic ("cos", llvm::Intrinsic::cos, scalar, scalar); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1197 register_generic ("cos", matrix, matrix); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1198 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1199 add_builtin ("exp"); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1200 register_intrinsic ("exp", llvm::Intrinsic::cos, scalar, scalar); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1201 register_generic ("exp", matrix, matrix); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1202 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1203 casts.resize (next_id + 1); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1204 fn = create_identity (any); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1205 for (std::map<std::string, jit_type *>::iterator iter = builtins.begin (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1206 iter != builtins.end (); ++iter) |
14973 | 1207 { |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1208 jit_type *btype = iter->second; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1209 release_fn.add_overload (release_any, false, 0, btype); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1210 casts[any->type_id ()].add_overload (fn, false, any, btype); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1211 casts[btype->type_id ()].add_overload (fn, false, btype, any); |
14973 | 1212 } |
14903 | 1213 } |
1214 | |
1215 void | |
1216 jit_typeinfo::add_print (jit_type *ty, void *call) | |
1217 { | |
1218 std::stringstream name; | |
1219 name << "octave_jit_print_" << ty->name (); | |
1220 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1221 llvm::Type *void_t = llvm::Type::getVoidTy (context); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1222 llvm::Function *fn = create_function (name.str (), void_t, |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1223 llvm::Type::getInt8PtrTy (context), |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1224 ty->to_llvm ()); |
14903 | 1225 engine->addGlobalMapping (fn, call); |
1226 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1227 jit_operation::overload ol (fn, false, 0, string, ty); |
14903 | 1228 print_fn.add_overload (ol); |
1229 } | |
1230 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1231 // FIXME: cp between add_binary_op, add_binary_icmp, and add_binary_fcmp |
14903 | 1232 void |
1233 jit_typeinfo::add_binary_op (jit_type *ty, int op, int llvm_op) | |
1234 { | |
1235 std::stringstream fname; | |
1236 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
1237 fname << "octave_jit_" << octave_value::binary_op_as_string (ov_op) | |
1238 << "_" << ty->name (); | |
14906 | 1239 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1240 llvm::Function *fn = create_function (fname.str (), ty, ty, ty); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1241 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, "body", fn); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1242 builder.SetInsertPoint (block); |
14903 | 1243 llvm::Instruction::BinaryOps temp |
1244 = static_cast<llvm::Instruction::BinaryOps>(llvm_op); | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1245 llvm::Value *ret = builder.CreateBinOp (temp, fn->arg_begin (), |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1246 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1247 builder.CreateRet (ret); |
14903 | 1248 llvm::verifyFunction (*fn); |
1249 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1250 jit_operation::overload ol(fn, false, ty, ty, ty); |
14903 | 1251 binary_ops[op].add_overload (ol); |
1252 } | |
1253 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1254 void |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1255 jit_typeinfo::add_binary_icmp (jit_type *ty, int op, int llvm_op) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1256 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1257 std::stringstream fname; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1258 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1259 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1260 << "_" << ty->name (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1261 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1262 llvm::Function *fn = create_function (fname.str (), boolean, ty, ty); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1263 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, "body", fn); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1264 builder.SetInsertPoint (block); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1265 llvm::CmpInst::Predicate temp |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1266 = static_cast<llvm::CmpInst::Predicate>(llvm_op); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1267 llvm::Value *ret = builder.CreateICmp (temp, fn->arg_begin (), |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1268 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1269 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1270 llvm::verifyFunction (*fn); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1271 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1272 jit_operation::overload ol (fn, false, boolean, ty, ty); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1273 binary_ops[op].add_overload (ol); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1274 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1275 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1276 void |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1277 jit_typeinfo::add_binary_fcmp (jit_type *ty, int op, int llvm_op) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1278 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1279 std::stringstream fname; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1280 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1281 fname << "octave_jit" << octave_value::binary_op_as_string (ov_op) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1282 << "_" << ty->name (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1283 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1284 llvm::Function *fn = create_function (fname.str (), boolean, ty, ty); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1285 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, "body", fn); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1286 builder.SetInsertPoint (block); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1287 llvm::CmpInst::Predicate temp |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1288 = static_cast<llvm::CmpInst::Predicate>(llvm_op); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1289 llvm::Value *ret = builder.CreateFCmp (temp, fn->arg_begin (), |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1290 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1291 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1292 llvm::verifyFunction (*fn); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1293 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1294 jit_operation::overload ol (fn, false, boolean, ty, ty); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1295 binary_ops[op].add_overload (ol); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1296 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1297 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1298 llvm::Function * |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1299 jit_typeinfo::create_function (const llvm::Twine& name, jit_type *ret, |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1300 const std::vector<jit_type *>& args) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1301 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1302 llvm::Type *void_t = llvm::Type::getVoidTy (context); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1303 std::vector<llvm::Type *> llvm_args (args.size (), void_t); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1304 for (size_t i = 0; i < args.size (); ++i) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1305 if (args[i]) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1306 llvm_args[i] = args[i]->to_llvm (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1307 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1308 return create_function (name, ret ? ret->to_llvm () : void_t, llvm_args); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1309 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1310 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1311 llvm::Function * |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1312 jit_typeinfo::create_function (const llvm::Twine& name, llvm::Type *ret, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1313 const std::vector<llvm::Type *>& args) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1314 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1315 llvm::FunctionType *ft = llvm::FunctionType::get (ret, args, false); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1316 llvm::Function *fn = llvm::Function::Create (ft, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1317 llvm::Function::ExternalLinkage, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1318 name, module); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1319 fn->addFnAttr (llvm::Attribute::AlwaysInline); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1320 return fn; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1321 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1322 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1323 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1324 jit_typeinfo::create_identity (jit_type *type) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1325 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1326 size_t id = type->type_id (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1327 if (id >= identities.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1328 identities.resize (id + 1, 0); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1329 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1330 if (! identities[id]) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1331 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1332 llvm::Function *fn = create_function ("id", type, type); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1333 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1334 builder.SetInsertPoint (body); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1335 builder.CreateRet (fn->arg_begin ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1336 llvm::verifyFunction (*fn); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1337 identities[id] = fn; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1338 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1339 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1340 return identities[id]; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1341 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1342 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1343 llvm::Value * |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1344 jit_typeinfo::do_insert_error_check (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1345 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1346 return builder.CreateLoad (lerror_state); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1347 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1348 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1349 void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1350 jit_typeinfo::add_builtin (const std::string& name) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1351 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1352 jit_type *btype = new_type (name, any, any->to_llvm ()); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1353 builtins[name] = btype; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1354 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1355 octave_builtin *ov_builtin = find_builtin (name); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1356 if (ov_builtin) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1357 ov_builtin->stash_jit (*btype); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1358 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1359 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1360 void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1361 jit_typeinfo::register_intrinsic (const std::string& name, size_t iid, |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1362 jit_type *result, |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1363 const std::vector<jit_type *>& args) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1364 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1365 jit_type *builtin_type = builtins[name]; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1366 size_t nargs = args.size (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1367 llvm::SmallVector<llvm::Type *, 5> llvm_args (nargs); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1368 for (size_t i = 0; i < nargs; ++i) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1369 llvm_args[i] = args[i]->to_llvm (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1370 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1371 llvm::Intrinsic::ID id = static_cast<llvm::Intrinsic::ID> (iid); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1372 llvm::Function *ifun = llvm::Intrinsic::getDeclaration (module, id, |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1373 llvm_args); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1374 std::stringstream fn_name; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1375 fn_name << "octave_jit_" << name; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1376 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1377 std::vector<jit_type *> args1 (nargs + 1); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1378 args1[0] = builtin_type; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1379 std::copy (args.begin (), args.end (), args1.begin () + 1); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1380 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1381 // The first argument will be the Octave function, but we already know that |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1382 // the function call is the equivalent of the intrinsic, so we ignore it and |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1383 // call the intrinsic with the remaining arguments. |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1384 llvm::Function *fn = create_function (fn_name.str (), result, args1); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1385 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1386 builder.SetInsertPoint (body); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1387 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1388 llvm::SmallVector<llvm::Value *, 5> fargs (nargs); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1389 llvm::Function::arg_iterator iter = fn->arg_begin (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1390 ++iter; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1391 for (size_t i = 0; i < nargs; ++i, ++iter) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1392 fargs[i] = iter; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1393 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1394 llvm::Value *ret = builder.CreateCall (ifun, fargs); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1395 builder.CreateRet (ret); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1396 llvm::verifyFunction (*fn); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1397 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1398 paren_subsref_fn.add_overload (fn, false, result, args1); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1399 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1400 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1401 octave_builtin * |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1402 jit_typeinfo::find_builtin (const std::string& name) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1403 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1404 // FIXME: Finalize what we want to store in octave_builtin, then add functions |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1405 // to access these values in octave_value |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1406 octave_value ov_builtin = symbol_table::find (name); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1407 return dynamic_cast<octave_builtin *> (ov_builtin.internal_rep ()); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1408 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1409 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1410 void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1411 jit_typeinfo::register_generic (const std::string&, jit_type *, |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1412 const std::vector<jit_type *>&) |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1413 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1414 // FIXME: Implement |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1415 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1416 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1417 llvm::Function * |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1418 jit_typeinfo::wrap_complex (llvm::Function *wrap) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1419 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1420 llvm::SmallVector<llvm::Type *, 5> new_args; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1421 new_args.reserve (wrap->arg_size ()); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1422 llvm::Type *complex_t = complex->to_llvm (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1423 for (llvm::Function::arg_iterator iter = wrap->arg_begin (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1424 iter != wrap->arg_end (); ++iter) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1425 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1426 llvm::Value *value = iter; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1427 llvm::Type *type = value->getType (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1428 new_args.push_back (type == complex_ret ? complex_t : type); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1429 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1430 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1431 llvm::FunctionType *wrap_type = wrap->getFunctionType (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1432 bool convert_ret = wrap_type->getReturnType () == complex_ret; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1433 llvm::Type *rtype = convert_ret ? complex_t : wrap->getReturnType (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1434 llvm::FunctionType *ft = llvm::FunctionType::get (rtype, new_args, false); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1435 llvm::Function *fn = llvm::Function::Create (ft, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1436 llvm::Function::ExternalLinkage, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1437 wrap->getName () + "_wrap", |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1438 module); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1439 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1440 builder.SetInsertPoint (body); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1441 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1442 llvm::SmallVector<llvm::Value *, 5> converted (new_args.size ()); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1443 llvm::Function::arg_iterator witer = wrap->arg_begin (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1444 llvm::Function::arg_iterator fiter = fn->arg_begin (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1445 for (size_t i = 0; i < new_args.size (); ++i, ++witer, ++fiter) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1446 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1447 llvm::Value *warg = witer; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1448 llvm::Value *arg = fiter; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1449 converted[i] = warg->getType () == arg->getType () ? arg |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1450 : pack_complex (arg); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1451 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1452 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1453 llvm::Value *ret = builder.CreateCall (wrap, converted); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1454 if (wrap_type->getReturnType () != builder.getVoidTy ()) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1455 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1456 if (convert_ret) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1457 ret = unpack_complex (ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1458 builder.CreateRet (ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1459 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1460 else |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1461 builder.CreateRetVoid (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1462 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1463 llvm::verifyFunction (*fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1464 return fn; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1465 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1466 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1467 llvm::Value * |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1468 jit_typeinfo::pack_complex (llvm::Value *cplx) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1469 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1470 llvm::Value *real = builder.CreateExtractElement (cplx, builder.getInt32 (0)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1471 llvm::Value *imag = builder.CreateExtractElement (cplx, builder.getInt32 (1)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1472 llvm::Value *ret = llvm::UndefValue::get (complex_ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1473 ret = builder.CreateInsertValue (ret, real, 0); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1474 return builder.CreateInsertValue (ret, imag, 1); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1475 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1476 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1477 llvm::Value * |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1478 jit_typeinfo::unpack_complex (llvm::Value *result) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1479 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1480 llvm::Type *complex_t = complex->to_llvm (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1481 llvm::Value *real = builder.CreateExtractValue (result, 0); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1482 llvm::Value *imag = builder.CreateExtractValue (result, 1); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1483 llvm::Value *ret = llvm::UndefValue::get (complex_t); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1484 ret = builder.CreateInsertElement (ret, real, builder.getInt32 (0)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1485 return builder.CreateInsertElement (ret, imag, builder.getInt32 (1)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1486 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1487 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1488 jit_type * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1489 jit_typeinfo::do_type_of (const octave_value &ov) const |
14903 | 1490 { |
14924 | 1491 if (ov.is_function ()) |
14973 | 1492 { |
1493 // FIXME: This is ugly, we need to finalize how we want to to this, then | |
1494 // have octave_value fully support the needed functionality | |
1495 octave_builtin *builtin | |
1496 = dynamic_cast<octave_builtin *> (ov.internal_rep ()); | |
1497 return builtin ? builtin->to_jit () : 0; | |
1498 } | |
14903 | 1499 |
14906 | 1500 if (ov.is_range ()) |
1501 return get_range (); | |
1502 | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1503 if (ov.is_double_type ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1504 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1505 if (ov.is_real_scalar ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1506 return get_scalar (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1507 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1508 if (ov.is_matrix_type ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1509 return get_matrix (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1510 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1511 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1512 if (ov.is_complex_scalar ()) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1513 return get_complex (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1514 |
14903 | 1515 return get_any (); |
1516 } | |
1517 | |
1518 jit_type* | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1519 jit_typeinfo::new_type (const std::string& name, jit_type *parent, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1520 llvm::Type *llvm_type) |
14903 | 1521 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1522 jit_type *ret = new jit_type (name, parent, llvm_type, next_id++); |
14903 | 1523 id_to_type.push_back (ret); |
1524 return ret; | |
1525 } | |
1526 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1527 // -------------------- jit_use -------------------- |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1528 jit_block * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1529 jit_use::user_parent (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1530 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1531 return muser->parent (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1532 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1533 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1534 // -------------------- jit_value -------------------- |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1535 jit_value::~jit_value (void) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1536 {} |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1537 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1538 jit_block * |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1539 jit_value::first_use_block (void) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1540 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1541 jit_use *use = first_use (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1542 while (use) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1543 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1544 if (! isa<jit_error_check> (use->user ())) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1545 return use->user_parent (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1546 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1547 use = use->next (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1548 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1549 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1550 return 0; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1551 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1552 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1553 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1554 jit_value::replace_with (jit_value *value) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1555 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1556 while (first_use ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1557 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1558 jit_instruction *user = first_use ()->user (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1559 size_t idx = first_use ()->index (); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1560 user->stash_argument (idx, value); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1561 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1562 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1563 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1564 #define JIT_METH(clname) \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1565 void \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1566 jit_ ## clname::accept (jit_ir_walker& walker) \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1567 { \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1568 walker.visit (*this); \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1569 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1570 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1571 JIT_VISIT_IR_NOTEMPLATE |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1572 #undef JIT_METH |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1573 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1574 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1575 operator<< (std::ostream& os, const jit_value& value) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1576 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1577 return value.short_print (os); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1578 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1579 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1580 std::ostream& |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1581 jit_print (std::ostream& os, jit_value *avalue) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1582 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1583 if (avalue) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1584 return avalue->print (os); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1585 return os << "NULL"; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1586 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1587 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1588 // -------------------- jit_instruction -------------------- |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1589 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1590 jit_instruction::remove (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1591 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1592 if (mparent) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1593 mparent->remove (mlocation); |
14945 | 1594 resize_arguments (0); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1595 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1596 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1597 llvm::BasicBlock * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1598 jit_instruction::parent_llvm (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1599 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1600 return mparent->to_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1601 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1602 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1603 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1604 jit_instruction::short_print (std::ostream& os) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1605 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1606 if (type ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1607 jit_print (os, type ()) << ": "; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1608 return os << "#" << mid; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1609 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1610 |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1611 void |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1612 jit_instruction::do_construct_ssa (size_t start, size_t end) |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1613 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1614 for (size_t i = start; i < end; ++i) |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1615 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1616 jit_value *arg = argument (i); |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1617 jit_variable *var = dynamic_cast<jit_variable *> (arg); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1618 if (var && var->has_top ()) |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1619 stash_argument (i, var->top ()); |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1620 } |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1621 } |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1622 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1623 // -------------------- jit_block -------------------- |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1624 void |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1625 jit_block::replace_with (jit_value *value) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1626 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1627 assert (isa<jit_block> (value)); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1628 jit_block *block = static_cast<jit_block *> (value); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1629 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1630 jit_value::replace_with (block); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1631 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1632 while (ILIST_T::first_use ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1633 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1634 jit_phi_incomming *incomming = ILIST_T::first_use (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1635 incomming->stash_value (block); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1636 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1637 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1638 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1639 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1640 jit_block::replace_in_phi (jit_block *ablock, jit_block *with) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1641 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1642 jit_phi_incomming *node = ILIST_T::first_use (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1643 while (node) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1644 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1645 jit_phi_incomming *prev = node; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1646 node = node->next (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1647 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1648 if (prev->user_parent () == ablock) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1649 prev->stash_value (with); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1650 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1651 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1652 |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1653 jit_block * |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1654 jit_block::maybe_merge () |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1655 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1656 if (successor_count () == 1 && successor (0) != this |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1657 && (successor (0)->use_count () == 1 || instructions.size () == 1)) |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1658 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1659 jit_block *to_merge = successor (0); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1660 merge (*to_merge); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1661 return to_merge; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1662 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1663 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1664 return 0; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1665 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1666 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1667 void |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1668 jit_block::merge (jit_block& block) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1669 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1670 // the merge block will contain a new terminator |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1671 jit_terminator *old_term = terminator (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1672 if (old_term) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1673 old_term->remove (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1674 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1675 bool was_empty = end () == begin (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1676 iterator merge_begin = end (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1677 if (! was_empty) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1678 --merge_begin; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1679 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1680 instructions.splice (end (), block.instructions); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1681 if (was_empty) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1682 merge_begin = begin (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1683 else |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1684 ++merge_begin; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1685 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1686 // now merge_begin points to the start of the new instructions, we must |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1687 // update their parent information |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1688 for (iterator iter = merge_begin; iter != end (); ++iter) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1689 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1690 jit_instruction *instr = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1691 instr->stash_parent (this, iter); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1692 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1693 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1694 block.replace_with (this); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1695 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1696 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1697 jit_instruction * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1698 jit_block::prepend (jit_instruction *instr) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1699 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1700 instructions.push_front (instr); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1701 instr->stash_parent (this, instructions.begin ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1702 return instr; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1703 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1704 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1705 jit_instruction * |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1706 jit_block::prepend_after_phi (jit_instruction *instr) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1707 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1708 // FIXME: Make this O(1) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1709 for (iterator iter = begin (); iter != end (); ++iter) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1710 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1711 jit_instruction *temp = *iter; |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
1712 if (! isa<jit_phi> (temp)) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1713 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1714 insert_before (iter, instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1715 return instr; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1716 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1717 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1718 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1719 return append (instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1720 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1721 |
14945 | 1722 void |
1723 jit_block::internal_append (jit_instruction *instr) | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1724 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1725 instructions.push_back (instr); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1726 instr->stash_parent (this, --instructions.end ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1727 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1728 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1729 jit_instruction * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1730 jit_block::insert_before (iterator loc, jit_instruction *instr) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1731 { |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1732 iterator iloc = instructions.insert (loc, instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1733 instr->stash_parent (this, iloc); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1734 return instr; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1735 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1736 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1737 jit_instruction * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1738 jit_block::insert_after (iterator loc, jit_instruction *instr) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1739 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1740 ++loc; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1741 iterator iloc = instructions.insert (loc, instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1742 instr->stash_parent (this, iloc); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1743 return instr; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1744 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1745 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1746 jit_terminator * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1747 jit_block::terminator (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1748 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1749 assert (this); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1750 if (instructions.empty ()) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1751 return 0; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1752 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1753 jit_instruction *last = instructions.back (); |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
1754 return dynamic_cast<jit_terminator *> (last); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1755 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1756 |
14945 | 1757 bool |
1758 jit_block::branch_alive (jit_block *asucc) const | |
1759 { | |
1760 return terminator ()->alive (asucc); | |
1761 } | |
1762 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1763 jit_block * |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1764 jit_block::successor (size_t i) const |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1765 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1766 jit_terminator *term = terminator (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1767 return term->successor (i); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1768 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1769 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1770 size_t |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1771 jit_block::successor_count (void) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1772 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1773 jit_terminator *term = terminator (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1774 return term ? term->successor_count () : 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1775 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1776 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1777 llvm::BasicBlock * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1778 jit_block::to_llvm (void) const |
14903 | 1779 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1780 return llvm::cast<llvm::BasicBlock> (llvm_value); |
14903 | 1781 } |
1782 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1783 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1784 jit_block::print_dom (std::ostream& os) const |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1785 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1786 short_print (os); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1787 os << ":\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1788 os << " mid: " << mid << std::endl; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1789 os << " predecessors: "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1790 for (jit_use *use = first_use (); use; use = use->next ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1791 os << *use->user_parent () << " "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1792 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1793 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1794 os << " successors: "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1795 for (size_t i = 0; i < successor_count (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1796 os << *successor (i) << " "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1797 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1798 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1799 os << " idom: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1800 if (idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1801 os << *idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1802 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1803 os << "NULL"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1804 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1805 os << " df: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1806 for (df_iterator iter = df_begin (); iter != df_end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1807 os << **iter << " "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1808 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1809 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1810 os << " dom_succ: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1811 for (size_t i = 0; i < dom_succ.size (); ++i) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1812 os << *dom_succ[i] << " "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1813 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1814 return os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1815 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1816 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1817 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1818 jit_block::compute_df (size_t avisit_count) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1819 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1820 if (visited (avisit_count)) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1821 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1822 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1823 if (use_count () >= 2) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1824 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1825 for (jit_use *use = first_use (); use; use = use->next ()) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1826 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1827 jit_block *runner = use->user_parent (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1828 while (runner != idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1829 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1830 runner->mdf.insert (this); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1831 runner = runner->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1832 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1833 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1834 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1835 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1836 for (size_t i = 0; i < successor_count (); ++i) |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1837 successor (i)->compute_df (avisit_count); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1838 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1839 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1840 bool |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1841 jit_block::update_idom (size_t avisit_count) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1842 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1843 if (visited (avisit_count) || ! use_count ()) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1844 return false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1845 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1846 bool changed = false; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1847 for (jit_use *use = first_use (); use; use = use->next ()) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1848 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1849 jit_block *pred = use->user_parent (); |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1850 changed = pred->update_idom (avisit_count) || changed; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1851 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1852 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1853 jit_use *use = first_use (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1854 jit_block *new_idom = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1855 use = use->next (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1856 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1857 for (; use; use = use->next ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1858 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1859 jit_block *pred = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1860 jit_block *pidom = pred->idom; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1861 if (pidom) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1862 new_idom = pidom->idom_intersect (new_idom); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1863 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1864 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1865 if (idom != new_idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1866 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1867 idom = new_idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1868 return true; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1869 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1870 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1871 return changed; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1872 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1873 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1874 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1875 jit_block::pop_all (void) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1876 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1877 for (iterator iter = begin (); iter != end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1878 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1879 jit_instruction *instr = *iter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1880 instr->pop_variable (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1881 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1882 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1883 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1884 jit_block * |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1885 jit_block::maybe_split (jit_convert& convert, jit_block *asuccessor) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1886 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1887 if (successor_count () > 1) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1888 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1889 jit_terminator *term = terminator (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1890 size_t idx = term->successor_index (asuccessor); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1891 jit_block *split = convert.create<jit_block> ("phi_split", mvisit_count); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1892 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1893 // try to place splits where they make sense |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1894 if (id () < asuccessor->id ()) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1895 convert.insert_before (asuccessor, split); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1896 else |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1897 convert.insert_after (this, split); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1898 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1899 term->stash_argument (idx, split); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1900 jit_branch *br = split->append (convert.create<jit_branch> (asuccessor)); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1901 replace_in_phi (asuccessor, split); |
14964
434ffa574c78
src/pt-jit.cc (jit_block::maybe_split): Correctly mark if split branch is alive
Max Brister <max@2bass.com>
parents:
14963
diff
changeset
|
1902 |
434ffa574c78
src/pt-jit.cc (jit_block::maybe_split): Correctly mark if split branch is alive
Max Brister <max@2bass.com>
parents:
14963
diff
changeset
|
1903 if (alive ()) |
434ffa574c78
src/pt-jit.cc (jit_block::maybe_split): Correctly mark if split branch is alive
Max Brister <max@2bass.com>
parents:
14963
diff
changeset
|
1904 { |
434ffa574c78
src/pt-jit.cc (jit_block::maybe_split): Correctly mark if split branch is alive
Max Brister <max@2bass.com>
parents:
14963
diff
changeset
|
1905 split->mark_alive (); |
434ffa574c78
src/pt-jit.cc (jit_block::maybe_split): Correctly mark if split branch is alive
Max Brister <max@2bass.com>
parents:
14963
diff
changeset
|
1906 br->infer (); |
434ffa574c78
src/pt-jit.cc (jit_block::maybe_split): Correctly mark if split branch is alive
Max Brister <max@2bass.com>
parents:
14963
diff
changeset
|
1907 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1908 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1909 return split; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1910 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1911 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1912 return this; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1913 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1914 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1915 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1916 jit_block::create_dom_tree (size_t avisit_count) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1917 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1918 if (visited (avisit_count)) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1919 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1920 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1921 if (idom != this) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1922 idom->dom_succ.push_back (this); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1923 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1924 for (size_t i = 0; i < successor_count (); ++i) |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1925 successor (i)->create_dom_tree (avisit_count); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1926 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1927 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1928 jit_block * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1929 jit_block::idom_intersect (jit_block *b) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1930 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1931 jit_block *i = this; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1932 jit_block *j = b; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1933 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1934 while (i != j) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1935 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1936 while (i->id () > j->id ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1937 i = i->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1938 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1939 while (j->id () > i->id ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1940 j = j->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1941 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1942 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1943 return i; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1944 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1945 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1946 // -------------------- jit_phi_incomming -------------------- |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1947 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1948 jit_block * |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1949 jit_phi_incomming::user_parent (void) const |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1950 { return muser->parent (); } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1951 |
14945 | 1952 // -------------------- jit_phi -------------------- |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1953 bool |
14945 | 1954 jit_phi::prune (void) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1955 { |
14945 | 1956 jit_block *p = parent (); |
1957 size_t new_idx = 0; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1958 jit_value *unique = argument (1); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1959 |
14945 | 1960 for (size_t i = 0; i < argument_count (); ++i) |
1961 { | |
1962 jit_block *inc = incomming (i); | |
1963 if (inc->branch_alive (p)) | |
1964 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1965 if (unique != argument (i)) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1966 unique = 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1967 |
14945 | 1968 if (new_idx != i) |
1969 { | |
1970 stash_argument (new_idx, argument (i)); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1971 mincomming[new_idx].stash_value (inc); |
14945 | 1972 } |
1973 | |
1974 ++new_idx; | |
1975 } | |
1976 } | |
1977 | |
1978 if (new_idx != argument_count ()) | |
1979 { | |
1980 resize_arguments (new_idx); | |
1981 mincomming.resize (new_idx); | |
1982 } | |
1983 | |
1984 assert (argument_count () > 0); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1985 if (unique) |
14945 | 1986 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1987 replace_with (unique); |
14945 | 1988 return true; |
1989 } | |
1990 | |
1991 return false; | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1992 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1993 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1994 bool |
14945 | 1995 jit_phi::infer (void) |
1996 { | |
1997 jit_block *p = parent (); | |
1998 if (! p->alive ()) | |
1999 return false; | |
2000 | |
2001 jit_type *infered = 0; | |
2002 for (size_t i = 0; i < argument_count (); ++i) | |
2003 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2004 jit_block *inc = incomming (i); |
14945 | 2005 if (inc->branch_alive (p)) |
2006 infered = jit_typeinfo::join (infered, argument_type (i)); | |
2007 } | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2008 |
14945 | 2009 if (infered != type ()) |
2010 { | |
2011 stash_type (infered); | |
2012 return true; | |
2013 } | |
2014 | |
2015 return false; | |
2016 } | |
2017 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2018 llvm::PHINode * |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2019 jit_phi::to_llvm (void) const |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2020 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2021 return llvm::cast<llvm::PHINode> (jit_value::to_llvm ()); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2022 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2023 |
14945 | 2024 // -------------------- jit_terminator -------------------- |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2025 size_t |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2026 jit_terminator::successor_index (const jit_block *asuccessor) const |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2027 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2028 size_t scount = successor_count (); |
14945 | 2029 for (size_t i = 0; i < scount; ++i) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2030 if (successor (i) == asuccessor) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2031 return i; |
14945 | 2032 |
2033 panic_impossible (); | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2034 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2035 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2036 bool |
14945 | 2037 jit_terminator::infer (void) |
2038 { | |
2039 if (! parent ()->alive ()) | |
2040 return false; | |
2041 | |
2042 bool changed = false; | |
2043 for (size_t i = 0; i < malive.size (); ++i) | |
2044 if (! malive[i] && check_alive (i)) | |
2045 { | |
2046 changed = true; | |
2047 malive[i] = true; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2048 successor (i)->mark_alive (); |
14945 | 2049 } |
2050 | |
2051 return changed; | |
2052 } | |
2053 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2054 llvm::TerminatorInst * |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2055 jit_terminator::to_llvm (void) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2056 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2057 return llvm::cast<llvm::TerminatorInst> (jit_value::to_llvm ()); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2058 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2059 |
14945 | 2060 // -------------------- jit_call -------------------- |
2061 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2062 jit_call::infer (void) |
14903 | 2063 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2064 // FIXME: explain algorithm |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2065 for (size_t i = 0; i < argument_count (); ++i) |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2066 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2067 already_infered[i] = argument_type (i); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2068 if (! already_infered[i]) |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2069 return false; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2070 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2071 |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2072 jit_type *infered = mfunction.get_result (already_infered); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2073 if (! infered && use_count ()) |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2074 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2075 std::stringstream ss; |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2076 ss << "Missing overload in type inference for "; |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2077 print (ss, 0); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2078 fail (ss.str ()); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2079 } |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2080 |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2081 if (infered != type ()) |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2082 { |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2083 stash_type (infered); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2084 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2085 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2086 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2087 return false; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2088 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2089 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2090 // -------------------- jit_convert -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2091 jit_convert::jit_convert (llvm::Module *module, tree &tee) |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2092 : iterator_count (0), short_count (0), breaking (false) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2093 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2094 jit_instruction::reset_ids (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2095 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2096 entry_block = create<jit_block> ("body"); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2097 final_block = create<jit_block> ("final"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2098 append (entry_block); |
14945 | 2099 entry_block->mark_alive (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2100 block = entry_block; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2101 visit (tee); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2102 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2103 // FIXME: Remove if we no longer only compile loops |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2104 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2105 assert (breaks.empty ()); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2106 assert (continues.empty ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2107 |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
2108 block->append (create<jit_branch> (final_block)); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2109 append (final_block); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2110 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2111 for (vmap_t::iterator iter = vmap.begin (); iter != vmap.end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2112 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2113 jit_variable *var = iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2114 const std::string& name = var->name (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2115 if (name.size () && name[0] != '#') |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2116 final_block->append (create<jit_store_argument> (var)); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2117 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2118 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2119 construct_ssa (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2120 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2121 // initialize the worklist to instructions derived from constants |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2122 for (std::list<jit_value *>::iterator iter = constants.begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2123 iter != constants.end (); ++iter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2124 append_users (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2125 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2126 // FIXME: Describe algorithm here |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2127 while (worklist.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2128 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2129 jit_instruction *next = worklist.front (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2130 worklist.pop_front (); |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2131 next->stash_in_worklist (false); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2132 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2133 if (next->infer ()) |
14945 | 2134 { |
2135 // terminators need to be handles specially | |
2136 if (jit_terminator *term = dynamic_cast<jit_terminator *> (next)) | |
2137 append_users_term (term); | |
2138 else | |
2139 append_users (next); | |
2140 } | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2141 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2142 |
14945 | 2143 remove_dead (); |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2144 merge_blocks (); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2145 final_block->label (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2146 place_releases (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2147 simplify_phi (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2148 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2149 #ifdef OCTAVE_JIT_DEBUG |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2150 final_block->label (); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2151 std::cout << "-------------------- Compiling tree --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2152 std::cout << tee.str_print_code () << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2153 print_blocks ("octave jit ir"); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2154 #endif |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2155 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2156 // for now just init arguments from entry, later we will have to do something |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2157 // more interesting |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2158 for (jit_block::iterator iter = entry_block->begin (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2159 iter != entry_block->end (); ++iter) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2160 if (jit_extract_argument *extract |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2161 = dynamic_cast<jit_extract_argument *> (*iter)) |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
2162 arguments.push_back (std::make_pair (extract->name (), true)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2163 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2164 convert_llvm to_llvm (*this); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2165 function = to_llvm.convert (module, arguments, blocks, constants); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2166 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2167 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2168 std::cout << "-------------------- llvm ir --------------------"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2169 llvm::raw_os_ostream llvm_cout (std::cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2170 function->print (llvm_cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2171 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2172 llvm::verifyFunction (*function); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2173 #endif |
14906 | 2174 } |
2175 | |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2176 jit_convert::~jit_convert (void) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2177 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2178 for (std::list<jit_value *>::iterator iter = all_values.begin (); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2179 iter != all_values.end (); ++iter) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2180 delete *iter; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2181 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2182 |
14906 | 2183 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2184 jit_convert::visit_anon_fcn_handle (tree_anon_fcn_handle&) |
14903 | 2185 { |
2186 fail (); | |
2187 } | |
2188 | |
2189 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2190 jit_convert::visit_argument_list (tree_argument_list&) |
14903 | 2191 { |
2192 fail (); | |
2193 } | |
2194 | |
2195 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2196 jit_convert::visit_binary_expression (tree_binary_expression& be) |
14903 | 2197 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2198 if (be.op_type () >= octave_value::num_binary_ops) |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2199 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2200 tree_boolean_expression *boole; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2201 boole = dynamic_cast<tree_boolean_expression *> (&be); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2202 assert (boole); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2203 bool is_and = boole->op_type () == tree_boolean_expression::bool_and; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2204 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2205 std::stringstream ss; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2206 ss << "#short_result" << short_count++; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2207 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2208 std::string short_name = ss.str (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2209 jit_variable *short_result = create<jit_variable> (short_name); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2210 vmap[short_name] = short_result; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2211 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2212 jit_block *done = create<jit_block> (block->name ()); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2213 tree_expression *lhs = be.lhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2214 jit_value *lhsv = visit (lhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2215 lhsv = create_checked (&jit_typeinfo::logically_true, lhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2216 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2217 jit_block *short_early = create<jit_block> ("short_early"); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2218 append (short_early); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2219 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2220 jit_block *short_cont = create<jit_block> ("short_cont"); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2221 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2222 if (is_and) |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2223 block->append (create<jit_cond_branch> (lhsv, short_cont, short_early)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2224 else |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2225 block->append (create<jit_cond_branch> (lhsv, short_early, short_cont)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2226 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2227 block = short_early; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2228 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2229 jit_value *early_result = create<jit_const_bool> (! is_and); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2230 block->append (create<jit_assign> (short_result, early_result)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2231 block->append (create<jit_branch> (done)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2232 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2233 append (short_cont); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2234 block = short_cont; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2235 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2236 tree_expression *rhs = be.rhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2237 jit_value *rhsv = visit (rhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2238 rhsv = create_checked (&jit_typeinfo::logically_true, rhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2239 block->append (create<jit_assign> (short_result, rhsv)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2240 block->append (create<jit_branch> (done)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2241 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2242 append (done); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2243 block = done; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2244 result = short_result; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2245 } |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2246 else |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2247 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2248 tree_expression *lhs = be.lhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2249 jit_value *lhsv = visit (lhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2250 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2251 tree_expression *rhs = be.rhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2252 jit_value *rhsv = visit (rhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2253 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2254 const jit_operation& fn = jit_typeinfo::binary_op (be.op_type ()); |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2255 result = create_checked (fn, lhsv, rhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2256 } |
14903 | 2257 } |
2258 | |
2259 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2260 jit_convert::visit_break_command (tree_break_command&) |
14903 | 2261 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2262 breaks.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2263 breaking = true; |
14903 | 2264 } |
2265 | |
2266 void | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2267 jit_convert::visit_colon_expression (tree_colon_expression& expr) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2268 { |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2269 // in the futher we need to add support for classes and deal with rvalues |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2270 jit_value *base = visit (expr.base ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2271 jit_value *limit = visit (expr.limit ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2272 jit_value *increment; |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2273 tree_expression *tinc = expr.increment (); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2274 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2275 if (tinc) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2276 increment = visit (tinc); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2277 else |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2278 increment = create<jit_const_scalar> (1); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2279 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2280 result = block->append (create<jit_call> (jit_typeinfo::make_range, base, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2281 limit, increment)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2282 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2283 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2284 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2285 jit_convert::visit_continue_command (tree_continue_command&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2286 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2287 continues.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2288 breaking = true; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2289 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2290 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2291 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2292 jit_convert::visit_global_command (tree_global_command&) |
14903 | 2293 { |
2294 fail (); | |
2295 } | |
2296 | |
2297 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2298 jit_convert::visit_persistent_command (tree_persistent_command&) |
14903 | 2299 { |
2300 fail (); | |
2301 } | |
2302 | |
2303 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2304 jit_convert::visit_decl_elt (tree_decl_elt&) |
14903 | 2305 { |
2306 fail (); | |
2307 } | |
2308 | |
2309 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2310 jit_convert::visit_decl_init_list (tree_decl_init_list&) |
14903 | 2311 { |
2312 fail (); | |
2313 } | |
2314 | |
2315 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2316 jit_convert::visit_simple_for_command (tree_simple_for_command& cmd) |
14903 | 2317 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2318 // Note we do an initial check to see if the loop will run atleast once. |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2319 // This allows us to get better type inference bounds on variables defined |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2320 // and used only inside the for loop (e.g. the index variable) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2321 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2322 // If we are a nested for loop we need to store the previous breaks |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2323 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2324 unwind_protect prot; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2325 prot.protect_var (breaks); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2326 prot.protect_var (continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2327 prot.protect_var (breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2328 breaks.clear (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2329 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2330 // we need a variable for our iterator, because it is used in multiple blocks |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2331 std::stringstream ss; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2332 ss << "#iter" << iterator_count++; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2333 std::string iter_name = ss.str (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2334 jit_variable *iterator = create<jit_variable> (iter_name); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2335 vmap[iter_name] = iterator; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2336 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2337 jit_block *body = create<jit_block> ("for_body"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2338 append (body); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2339 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2340 jit_block *tail = create<jit_block> ("for_tail"); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2341 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2342 // do control expression, iter init, and condition check in prev_block (block) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2343 jit_value *control = visit (cmd.control_expr ()); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2344 jit_call *init_iter = create<jit_call> (jit_typeinfo::for_init, control); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2345 block->append (init_iter); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2346 block->append (create<jit_assign> (iterator, init_iter)); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2347 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2348 jit_value *check = block->append (create<jit_call> (jit_typeinfo::for_check, |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2349 control, iterator)); |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
2350 block->append (create<jit_cond_branch> (check, body, tail)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2351 block = body; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2352 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2353 // compute the syntactical iterator |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2354 jit_call *idx_rhs = create<jit_call> (jit_typeinfo::for_index, control, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2355 iterator); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2356 block->append (idx_rhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2357 do_assign (cmd.left_hand_side (), idx_rhs); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2358 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2359 // do loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2360 tree_statement_list *pt_body = cmd.body (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2361 pt_body->accept (*this); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2362 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2363 if (breaking && continues.empty ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2364 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2365 // WTF are you doing user? Every branch was a continue, why did you have |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2366 // a loop??? Users are silly people... |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2367 finish_breaks (tail, breaks); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2368 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2369 block = tail; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2370 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2371 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2372 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2373 // check our condition, continues jump to this block |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2374 jit_block *check_block = create<jit_block> ("for_check"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2375 append (check_block); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2376 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2377 if (! breaking) |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
2378 block->append (create<jit_branch> (check_block)); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2379 finish_breaks (check_block, continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2380 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2381 block = check_block; |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2382 const jit_operation& add_fn = jit_typeinfo::binary_op (octave_value::op_add); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2383 jit_value *one = create<jit_const_index> (1); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2384 jit_call *iter_inc = create<jit_call> (add_fn, iterator, one); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2385 block->append (iter_inc); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2386 block->append (create<jit_assign> (iterator, iter_inc)); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2387 check = block->append (create<jit_call> (jit_typeinfo::for_check, control, |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2388 iterator)); |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
2389 block->append (create<jit_cond_branch> (check, body, tail)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2390 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2391 // breaks will go to our tail |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2392 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2393 finish_breaks (tail, breaks); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2394 block = tail; |
14903 | 2395 } |
2396 | |
2397 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2398 jit_convert::visit_complex_for_command (tree_complex_for_command&) |
14903 | 2399 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2400 fail (); |
14903 | 2401 } |
2402 | |
2403 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2404 jit_convert::visit_octave_user_script (octave_user_script&) |
14903 | 2405 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2406 fail (); |
14903 | 2407 } |
2408 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2409 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2410 jit_convert::visit_octave_user_function (octave_user_function&) |
14903 | 2411 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2412 fail (); |
14899 | 2413 } |
2414 | |
14903 | 2415 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2416 jit_convert::visit_octave_user_function_header (octave_user_function&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2417 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2418 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2419 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2420 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2421 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2422 jit_convert::visit_octave_user_function_trailer (octave_user_function&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2423 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2424 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2425 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2426 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2427 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2428 jit_convert::visit_function_def (tree_function_def&) |
14899 | 2429 { |
14903 | 2430 fail (); |
2431 } | |
14899 | 2432 |
14903 | 2433 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2434 jit_convert::visit_identifier (tree_identifier& ti) |
14903 | 2435 { |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2436 result = get_variable (ti.name ()); |
14899 | 2437 } |
2438 | |
2439 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2440 jit_convert::visit_if_clause (tree_if_clause&) |
14903 | 2441 { |
2442 fail (); | |
14899 | 2443 } |
2444 | |
2445 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2446 jit_convert::visit_if_command (tree_if_command& cmd) |
14903 | 2447 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2448 tree_if_command_list *lst = cmd.cmd_list (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2449 assert (lst); // jwe: Can this be null? |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2450 lst->accept (*this); |
14903 | 2451 } |
2452 | |
2453 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2454 jit_convert::visit_if_command_list (tree_if_command_list& lst) |
14903 | 2455 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2456 tree_if_clause *last = lst.back (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2457 size_t last_else = static_cast<size_t> (last->is_else_clause ()); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2458 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2459 // entry_blocks represents the block you need to enter in order to execute |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2460 // the condition check for the ith clause. For the else, it is simple the |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2461 // else body. If there is no else body, then it is padded with the tail |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2462 std::vector<jit_block *> entry_blocks (lst.size () + 1 - last_else); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2463 std::vector<jit_block *> branch_blocks (lst.size (), 0); // final blocks |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2464 entry_blocks[0] = block; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2465 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2466 // we need to construct blocks first, because they have jumps to eachother |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2467 tree_if_command_list::iterator iter = lst.begin (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2468 ++iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2469 for (size_t i = 1; iter != lst.end (); ++iter, ++i) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2470 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2471 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2472 if (tic->is_else_clause ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2473 entry_blocks[i] = create<jit_block> ("else"); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2474 else |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2475 entry_blocks[i] = create<jit_block> ("ifelse_cond"); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2476 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2477 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2478 jit_block *tail = create<jit_block> ("if_tail"); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2479 if (! last_else) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2480 entry_blocks[entry_blocks.size () - 1] = tail; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2481 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2482 size_t num_incomming = 0; // number of incomming blocks to our tail |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2483 iter = lst.begin (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2484 for (size_t i = 0; iter != lst.end (); ++iter, ++i) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2485 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2486 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2487 block = entry_blocks[i]; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2488 assert (block); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2489 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2490 if (i) // the first block is prev_block, so it has already been added |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2491 append (entry_blocks[i]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2492 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2493 if (! tic->is_else_clause ()) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2494 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2495 tree_expression *expr = tic->condition (); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2496 jit_value *cond = visit (expr); |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
2497 jit_call *check = create_checked (&jit_typeinfo::logically_true, |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
2498 cond); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2499 jit_block *body = create<jit_block> (i == 0 ? "if_body" |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2500 : "ifelse_body"); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2501 append (body); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2502 |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
2503 jit_instruction *br = create<jit_cond_branch> (check, body, |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2504 entry_blocks[i + 1]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2505 block->append (br); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2506 block = body; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2507 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2508 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2509 tree_statement_list *stmt_lst = tic->commands (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2510 assert (stmt_lst); // jwe: Can this be null? |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2511 stmt_lst->accept (*this); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2512 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2513 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2514 breaking = false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2515 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2516 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2517 ++num_incomming; |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
2518 block->append (create<jit_branch> (tail)); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2519 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2520 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2521 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2522 if (num_incomming || ! last_else) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2523 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2524 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2525 block = tail; |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2526 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2527 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2528 // every branch broke, so we don't have a tail |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2529 breaking = true; |
14903 | 2530 } |
2531 | |
2532 void | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2533 jit_convert::visit_index_expression (tree_index_expression& exp) |
14903 | 2534 { |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2535 std::pair<jit_value *, jit_value *> res = resolve (exp); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2536 jit_value *object = res.first; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2537 jit_value *index = res.second; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2538 |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
2539 result = create_checked (jit_typeinfo::paren_subsref, object, index); |
14903 | 2540 } |
2541 | |
2542 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2543 jit_convert::visit_matrix (tree_matrix&) |
14899 | 2544 { |
2545 fail (); | |
2546 } | |
2547 | |
2548 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2549 jit_convert::visit_cell (tree_cell&) |
14906 | 2550 { |
2551 fail (); | |
2552 } | |
2553 | |
2554 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2555 jit_convert::visit_multi_assignment (tree_multi_assignment&) |
14899 | 2556 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2557 fail (); |
14903 | 2558 } |
2559 | |
2560 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2561 jit_convert::visit_no_op_command (tree_no_op_command&) |
14906 | 2562 { |
2563 fail (); | |
2564 } | |
2565 | |
2566 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2567 jit_convert::visit_constant (tree_constant& tc) |
14903 | 2568 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2569 octave_value v = tc.rvalue1 (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2570 if (v.is_real_scalar () && v.is_double_type ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2571 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2572 double dv = v.double_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2573 result = create<jit_const_scalar> (dv); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2574 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2575 else if (v.is_range ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2576 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2577 Range rv = v.range_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2578 result = create<jit_const_range> (rv); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2579 } |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2580 else if (v.is_complex_scalar ()) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2581 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2582 Complex cv = v.complex_value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2583 result = create<jit_const_complex> (cv); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2584 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2585 else |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2586 fail ("Unknown constant"); |
14903 | 2587 } |
14899 | 2588 |
14903 | 2589 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2590 jit_convert::visit_fcn_handle (tree_fcn_handle&) |
14903 | 2591 { |
2592 fail (); | |
2593 } | |
14899 | 2594 |
14903 | 2595 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2596 jit_convert::visit_parameter_list (tree_parameter_list&) |
14906 | 2597 { |
2598 fail (); | |
2599 } | |
2600 | |
2601 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2602 jit_convert::visit_postfix_expression (tree_postfix_expression&) |
14903 | 2603 { |
2604 fail (); | |
2605 } | |
14899 | 2606 |
14903 | 2607 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2608 jit_convert::visit_prefix_expression (tree_prefix_expression&) |
14899 | 2609 { |
2610 fail (); | |
2611 } | |
2612 | |
2613 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2614 jit_convert::visit_return_command (tree_return_command&) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2615 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2616 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2617 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2618 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2619 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2620 jit_convert::visit_return_list (tree_return_list&) |
14899 | 2621 { |
2622 fail (); | |
2623 } | |
2624 | |
2625 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2626 jit_convert::visit_simple_assignment (tree_simple_assignment& tsa) |
14899 | 2627 { |
14953 | 2628 if (tsa.op_type () != octave_value::op_asn_eq) |
2629 fail ("Unsupported assign"); | |
2630 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2631 // resolve rhs |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2632 tree_expression *rhs = tsa.right_hand_side (); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2633 jit_value *rhsv = visit (rhs); |
14899 | 2634 |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2635 result = do_assign (tsa.left_hand_side (), rhsv); |
14899 | 2636 } |
2637 | |
2638 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2639 jit_convert::visit_statement (tree_statement& stmt) |
14899 | 2640 { |
2641 tree_command *cmd = stmt.command (); | |
2642 tree_expression *expr = stmt.expression (); | |
2643 | |
2644 if (cmd) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2645 visit (cmd); |
14899 | 2646 else |
2647 { | |
2648 // stolen from tree_evaluator::visit_statement | |
2649 bool do_bind_ans = false; | |
2650 | |
2651 if (expr->is_identifier ()) | |
2652 { | |
2653 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
2654 | |
2655 do_bind_ans = (! id->is_variable ()); | |
2656 } | |
2657 else | |
2658 do_bind_ans = (! expr->is_assignment_expression ()); | |
2659 | |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2660 jit_value *expr_result = visit (expr); |
14899 | 2661 |
2662 if (do_bind_ans) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2663 do_assign ("ans", expr_result, expr->print_result ()); |
14899 | 2664 else if (expr->is_identifier () && expr->print_result ()) |
2665 { | |
2666 // FIXME: ugly hack, we need to come up with a way to pass | |
2667 // nargout to visit_identifier | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2668 const jit_operation& fn = jit_typeinfo::print_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2669 jit_const_string *name = create<jit_const_string> (expr->name ()); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2670 block->append (create<jit_call> (fn, name, expr_result)); |
14899 | 2671 } |
2672 } | |
2673 } | |
2674 | |
2675 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2676 jit_convert::visit_statement_list (tree_statement_list& lst) |
14906 | 2677 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2678 for (tree_statement_list::iterator iter = lst.begin (); iter != lst.end(); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2679 ++iter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2680 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2681 tree_statement *elt = *iter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2682 // jwe: Can this ever be null? |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2683 assert (elt); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2684 elt->accept (*this); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2685 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2686 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2687 break; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2688 } |
14906 | 2689 } |
2690 | |
2691 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2692 jit_convert::visit_switch_case (tree_switch_case&) |
14906 | 2693 { |
2694 fail (); | |
2695 } | |
2696 | |
2697 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2698 jit_convert::visit_switch_case_list (tree_switch_case_list&) |
14899 | 2699 { |
2700 fail (); | |
2701 } | |
2702 | |
2703 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2704 jit_convert::visit_switch_command (tree_switch_command&) |
14906 | 2705 { |
2706 fail (); | |
2707 } | |
2708 | |
2709 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2710 jit_convert::visit_try_catch_command (tree_try_catch_command&) |
14899 | 2711 { |
2712 fail (); | |
2713 } | |
2714 | |
2715 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2716 jit_convert::visit_unwind_protect_command (tree_unwind_protect_command&) |
14899 | 2717 { |
2718 fail (); | |
2719 } | |
2720 | |
2721 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2722 jit_convert::visit_while_command (tree_while_command&) |
14906 | 2723 { |
2724 fail (); | |
2725 } | |
2726 | |
2727 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2728 jit_convert::visit_do_until_command (tree_do_until_command&) |
14899 | 2729 { |
2730 fail (); | |
2731 } | |
2732 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2733 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2734 jit_convert::append (jit_block *ablock) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2735 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2736 blocks.push_back (ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2737 ablock->stash_location (--blocks.end ()); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2738 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2739 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2740 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2741 jit_convert::insert_before (block_iterator iter, jit_block *ablock) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2742 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2743 iter = blocks.insert (iter, ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2744 ablock->stash_location (iter); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2745 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2746 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2747 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2748 jit_convert::insert_after (block_iterator iter, jit_block *ablock) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2749 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2750 ++iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2751 insert_before (iter, ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2752 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2753 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2754 jit_variable * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2755 jit_convert::get_variable (const std::string& vname) |
14899 | 2756 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2757 vmap_t::iterator iter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2758 iter = vmap.find (vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2759 if (iter != vmap.end ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2760 return iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2761 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2762 jit_variable *var = create<jit_variable> (vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2763 octave_value val = symbol_table::find (vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2764 jit_type *type = jit_typeinfo::type_of (val); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2765 jit_extract_argument *extract; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2766 extract = create<jit_extract_argument> (type, var); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2767 entry_block->prepend (extract); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2768 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2769 return vmap[vname] = var; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2770 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2771 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2772 std::pair<jit_value *, jit_value *> |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2773 jit_convert::resolve (tree_index_expression& exp) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2774 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2775 std::string type = exp.type_tags (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2776 if (! (type.size () == 1 && type[0] == '(')) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2777 fail ("Unsupported index operation"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2778 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2779 std::list<tree_argument_list *> args = exp.arg_lists (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2780 if (args.size () != 1) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2781 fail ("Bad number of arguments in tree_index_expression"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2782 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2783 tree_argument_list *arg_list = args.front (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2784 if (! arg_list) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2785 fail ("null argument list"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2786 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2787 if (arg_list->size () != 1) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2788 fail ("Bad number of arguments in arg_list"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2789 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2790 tree_expression *tree_object = exp.expression (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2791 jit_value *object = visit (tree_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2792 tree_expression *arg0 = arg_list->front (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2793 jit_value *index = visit (arg0); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2794 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2795 return std::make_pair (object, index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2796 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2797 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2798 jit_value * |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2799 jit_convert::do_assign (tree_expression *exp, jit_value *rhs, bool artificial) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2800 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2801 if (! exp) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2802 fail ("NULL lhs in assign"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2803 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2804 if (isa<tree_identifier> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2805 return do_assign (exp->name (), rhs, exp->print_result (), artificial); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2806 else if (tree_index_expression *idx |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2807 = dynamic_cast<tree_index_expression *> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2808 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2809 std::pair<jit_value *, jit_value *> res = resolve (*idx); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2810 jit_value *object = res.first; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2811 jit_value *index = res.second; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2812 jit_call *new_object = create<jit_call> (&jit_typeinfo::paren_subsasgn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2813 object, index, rhs); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2814 block->append (new_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2815 do_assign (idx->expression (), new_object, true); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2816 create_check (new_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2817 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2818 // FIXME: Will not work for values that must be release/grabed |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2819 return rhs; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2820 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2821 else |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2822 fail ("Unsupported assignment"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2823 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2824 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2825 jit_value * |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2826 jit_convert::do_assign (const std::string& lhs, jit_value *rhs, |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2827 bool print, bool artificial) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2828 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2829 jit_variable *var = get_variable (lhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2830 jit_assign *assign = block->append (create<jit_assign> (var, rhs)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2831 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2832 if (artificial) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2833 assign->mark_artificial (); |
14906 | 2834 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2835 if (print) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2836 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2837 const jit_operation& print_fn = jit_typeinfo::print_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2838 jit_const_string *name = create<jit_const_string> (lhs); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2839 block->append (create<jit_call> (print_fn, name, var)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2840 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2841 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2842 return var; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2843 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2844 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2845 jit_value * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2846 jit_convert::visit (tree& tee) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2847 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2848 result = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2849 tee.accept (*this); |
14906 | 2850 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2851 jit_value *ret = result; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2852 result = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2853 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2854 } |
14906 | 2855 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2856 void |
14945 | 2857 jit_convert::append_users_term (jit_terminator *term) |
2858 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2859 for (size_t i = 0; i < term->successor_count (); ++i) |
14945 | 2860 { |
2861 if (term->alive (i)) | |
2862 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2863 jit_block *succ = term->successor (i); |
14945 | 2864 for (jit_block::iterator iter = succ->begin (); iter != succ->end () |
2865 && isa<jit_phi> (*iter); ++iter) | |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2866 push_worklist (*iter); |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2867 |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2868 jit_terminator *sterm = succ->terminator (); |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2869 if (sterm) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2870 push_worklist (sterm); |
14945 | 2871 } |
2872 } | |
2873 } | |
2874 | |
2875 void | |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2876 jit_convert::merge_blocks (void) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2877 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2878 std::vector<jit_block *> dead; |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2879 for (block_list::iterator iter = blocks.begin (); iter != blocks.end (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2880 ++iter) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2881 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2882 jit_block *b = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2883 jit_block *merged = b->maybe_merge (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2884 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2885 if (merged) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2886 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2887 if (merged == final_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2888 final_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2889 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2890 if (merged == entry_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2891 entry_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2892 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2893 dead.push_back (merged); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2894 } |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2895 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2896 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2897 for (size_t i = 0; i < dead.size (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2898 blocks.erase (dead[i]->location ()); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2899 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2900 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2901 void |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2902 jit_convert::construct_ssa (void) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2903 { |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2904 merge_blocks (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2905 final_block->label (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2906 final_block->compute_idom (entry_block); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2907 entry_block->compute_df (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2908 entry_block->create_dom_tree (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2909 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2910 // insert phi nodes where needed, this is done on a per variable basis |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2911 for (vmap_t::iterator iter = vmap.begin (); iter != vmap.end (); ++iter) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2912 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2913 jit_block::df_set visited, added_phi; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2914 std::list<jit_block *> ssa_worklist; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2915 iter->second->use_blocks (visited); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2916 ssa_worklist.insert (ssa_worklist.begin (), visited.begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2917 visited.end ()); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2918 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2919 while (ssa_worklist.size ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2920 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2921 jit_block *b = ssa_worklist.front (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2922 ssa_worklist.pop_front (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2923 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2924 for (jit_block::df_iterator diter = b->df_begin (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2925 diter != b->df_end (); ++diter) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2926 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2927 jit_block *dblock = *diter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2928 if (! added_phi.count (dblock)) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2929 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2930 jit_phi *phi = create<jit_phi> (iter->second, |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2931 dblock->use_count ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2932 dblock->prepend (phi); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2933 added_phi.insert (dblock); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2934 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2935 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2936 if (! visited.count (dblock)) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2937 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2938 ssa_worklist.push_back (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2939 visited.insert (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2940 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2941 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2942 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2943 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2944 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2945 do_construct_ssa (*entry_block, entry_block->visit_count ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2946 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2947 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2948 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2949 jit_convert::do_construct_ssa (jit_block& ablock, size_t avisit_count) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2950 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2951 if (ablock.visited (avisit_count)) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2952 return; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2953 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2954 // replace variables with their current SSA value |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2955 for (jit_block::iterator iter = ablock.begin (); iter != ablock.end (); ++iter) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2956 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2957 jit_instruction *instr = *iter; |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2958 instr->construct_ssa (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2959 instr->push_variable (); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2960 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2961 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2962 // finish phi nodes of successors |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2963 for (size_t i = 0; i < ablock.successor_count (); ++i) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2964 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2965 jit_block *finish = ablock.successor (i); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2966 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2967 for (jit_block::iterator iter = finish->begin (); iter != finish->end () |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2968 && isa<jit_phi> (*iter);) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2969 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2970 jit_phi *phi = static_cast<jit_phi *> (*iter); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2971 jit_variable *var = phi->dest (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2972 if (var->has_top ()) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2973 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2974 phi->add_incomming (&ablock, var->top ()); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2975 ++iter; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2976 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2977 else |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2978 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2979 // temporaries may have extranious phi nodes which can be removed |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2980 assert (! phi->use_count ()); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2981 assert (var->name ().size () && var->name ()[0] == '#'); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2982 iter = finish->remove (iter); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2983 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2984 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2985 } |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2986 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2987 for (size_t i = 0; i < ablock.dom_successor_count (); ++i) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2988 do_construct_ssa (*ablock.dom_successor (i), avisit_count); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2989 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2990 ablock.pop_all (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2991 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2992 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2993 void |
14945 | 2994 jit_convert::remove_dead () |
2995 { | |
2996 block_list::iterator biter; | |
2997 for (biter = blocks.begin (); biter != blocks.end (); ++biter) | |
2998 { | |
2999 jit_block *b = *biter; | |
3000 if (b->alive ()) | |
3001 { | |
3002 for (jit_block::iterator iter = b->begin (); iter != b->end () | |
3003 && isa<jit_phi> (*iter);) | |
3004 { | |
3005 jit_phi *phi = static_cast<jit_phi *> (*iter); | |
3006 if (phi->prune ()) | |
3007 iter = b->remove (iter); | |
3008 else | |
3009 ++iter; | |
3010 } | |
3011 } | |
3012 } | |
3013 | |
3014 for (biter = blocks.begin (); biter != blocks.end ();) | |
3015 { | |
3016 jit_block *b = *biter; | |
3017 if (b->alive ()) | |
3018 { | |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
3019 // FIXME: A special case for jit_error_check, if we generalize to |
14945 | 3020 // we will need to change! |
3021 jit_terminator *term = b->terminator (); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3022 if (term && term->successor_count () == 2 && ! term->alive (0)) |
14945 | 3023 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3024 jit_block *succ = term->successor (1); |
14945 | 3025 term->remove (); |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
3026 jit_branch *abreak = b->append (create<jit_branch> (succ)); |
14945 | 3027 abreak->infer (); |
3028 } | |
3029 | |
3030 ++biter; | |
3031 } | |
3032 else | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3033 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3034 jit_terminator *term = b->terminator (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3035 if (term) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3036 term->remove (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3037 biter = blocks.erase (biter); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3038 } |
14945 | 3039 } |
3040 } | |
3041 | |
3042 void | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3043 jit_convert::place_releases (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3044 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3045 std::set<jit_value *> temporaries; |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3046 for (block_list::iterator iter = blocks.begin (); iter != blocks.end (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3047 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3048 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3049 jit_block& ablock = **iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3050 if (ablock.id () != jit_block::NO_ID) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3051 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3052 release_temp (ablock, temporaries); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3053 release_dead_phi (ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3054 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3055 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3056 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3057 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3058 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3059 jit_convert::release_temp (jit_block& ablock, std::set<jit_value *>& temp) |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3060 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3061 for (jit_block::iterator iter = ablock.begin (); iter != ablock.end (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3062 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3063 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3064 jit_instruction *instr = *iter; |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3065 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3066 // check for temporaries that require release and live across |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3067 // multiple blocks |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3068 if (instr->needs_release ()) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3069 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3070 jit_block *fu_block = instr->first_use_block (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3071 if (fu_block && fu_block != &ablock) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3072 temp.insert (instr); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3073 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3074 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3075 if (isa<jit_call> (instr)) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3076 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3077 // place releases for temporary arguments |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3078 for (size_t i = 0; i < instr->argument_count (); ++i) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3079 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3080 jit_value *arg = instr->argument (i); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3081 if (arg->needs_release ()) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3082 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3083 jit_call *release = create<jit_call> (&jit_typeinfo::release, |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3084 arg); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3085 release->infer (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3086 ablock.insert_after (iter, release); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3087 ++iter; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3088 temp.erase (arg); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3089 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3090 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3091 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3092 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3093 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3094 if (! temp.size () || ! isa<jit_error_check> (ablock.terminator ())) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3095 return; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3096 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3097 // FIXME: If we support try/catch or unwind_protect final_block may not be the |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3098 // destination |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3099 jit_block *split = ablock.maybe_split (*this, final_block); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3100 jit_terminator *term = split->terminator (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3101 for (std::set<jit_value *>::const_iterator iter = temp.begin (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3102 iter != temp.end (); ++iter) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3103 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3104 jit_value *value = *iter; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3105 jit_call *release = create<jit_call> (&jit_typeinfo::release, value); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3106 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3107 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3108 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3109 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3110 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3111 void |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3112 jit_convert::release_dead_phi (jit_block& ablock) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3113 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3114 jit_block::iterator iter = ablock.begin (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3115 while (iter != ablock.end () && isa<jit_phi> (*iter)) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3116 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3117 jit_phi *phi = static_cast<jit_phi *> (*iter); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3118 ++iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3119 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3120 jit_use *use = phi->first_use (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3121 if (phi->use_count () == 1 && isa<jit_assign> (use->user ())) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3122 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3123 // instead of releasing on assign, release on all incomming branches, |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3124 // this can get rid of casts inside loops |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3125 for (size_t i = 0; i < phi->argument_count (); ++i) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3126 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3127 jit_value *arg = phi->argument (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3128 jit_block *inc = phi->incomming (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3129 jit_block *split = inc->maybe_split (*this, ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3130 jit_terminator *term = split->terminator (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3131 jit_call *release = create<jit_call> (jit_typeinfo::release, arg); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3132 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3133 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3134 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3135 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3136 phi->replace_with (0); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3137 phi->remove (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3138 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3139 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3140 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3141 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3142 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3143 jit_convert::simplify_phi (void) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3144 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3145 for (block_list::iterator biter = blocks.begin (); biter != blocks.end (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3146 ++biter) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3147 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3148 jit_block &ablock = **biter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3149 for (jit_block::iterator iter = ablock.begin (); iter != ablock.end () |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3150 && isa<jit_phi> (*iter); ++iter) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3151 simplify_phi (*static_cast<jit_phi *> (*iter)); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3152 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3153 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3154 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3155 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3156 jit_convert::simplify_phi (jit_phi& phi) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3157 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3158 jit_block& pblock = *phi.parent (); |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3159 const jit_operation& cast_fn = jit_typeinfo::cast (phi.type ()); |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3160 jit_variable *dest = phi.dest (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3161 for (size_t i = 0; i < phi.argument_count (); ++i) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3162 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3163 jit_value *arg = phi.argument (i); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3164 if (arg->type () != phi.type ()) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3165 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3166 jit_block *pred = phi.incomming (i); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3167 jit_block *split = pred->maybe_split (*this, pblock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3168 jit_terminator *term = split->terminator (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3169 jit_instruction *cast = create<jit_call> (cast_fn, arg); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3170 jit_assign *assign = create<jit_assign> (dest, cast); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3171 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3172 split->insert_before (term, cast); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3173 split->insert_before (term, assign); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3174 cast->infer (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3175 assign->infer (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3176 phi.stash_argument (i, assign); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3177 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3178 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3179 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3180 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3181 void |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3182 jit_convert::finish_breaks (jit_block *dest, const block_list& lst) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3183 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3184 for (block_list::const_iterator iter = lst.begin (); iter != lst.end (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3185 ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3186 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3187 jit_block *b = *iter; |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
3188 b->append (create<jit_branch> (dest)); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3189 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3190 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3191 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3192 // -------------------- jit_convert::convert_llvm -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3193 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3194 jit_convert::convert_llvm::convert (llvm::Module *module, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3195 const std::vector<std::pair< std::string, bool> >& args, |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3196 const std::list<jit_block *>& blocks, |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3197 const std::list<jit_value *>& constants) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3198 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3199 jit_type *any = jit_typeinfo::get_any (); |
14899 | 3200 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3201 // argument is an array of octave_base_value*, or octave_base_value** |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3202 llvm::Type *arg_type = any->to_llvm (); // this is octave_base_value* |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3203 arg_type = arg_type->getPointerTo (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3204 llvm::FunctionType *ft = llvm::FunctionType::get (llvm::Type::getVoidTy (context), |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3205 arg_type, false); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3206 function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3207 "foobar", module); |
14906 | 3208 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3209 try |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3210 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3211 prelude = llvm::BasicBlock::Create (context, "prelude", function); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3212 builder.SetInsertPoint (prelude); |
14906 | 3213 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3214 llvm::Value *arg = function->arg_begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3215 for (size_t i = 0; i < args.size (); ++i) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3216 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3217 llvm::Value *loaded_arg = builder.CreateConstInBoundsGEP1_32 (arg, i); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3218 arguments[args[i].first] = loaded_arg; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3219 } |
14906 | 3220 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3221 std::list<jit_block *>::const_iterator biter; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3222 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3223 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3224 jit_block *jblock = *biter; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3225 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3226 jblock->name (), |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3227 function); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3228 jblock->stash_llvm (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3229 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3230 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3231 jit_block *first = *blocks.begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3232 builder.CreateBr (first->to_llvm ()); |
14906 | 3233 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3234 // constants aren't in the IR, we visit those first |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3235 for (std::list<jit_value *>::const_iterator iter = constants.begin (); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3236 iter != constants.end (); ++iter) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3237 if (! isa<jit_instruction> (*iter)) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3238 visit (*iter); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3239 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3240 // convert all instructions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3241 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3242 visit (*biter); |
14906 | 3243 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3244 // now finish phi nodes |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3245 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3246 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3247 jit_block& block = **biter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3248 for (jit_block::iterator piter = block.begin (); |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
3249 piter != block.end () && isa<jit_phi> (*piter); ++piter) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3250 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3251 jit_instruction *phi = *piter; |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3252 finish_phi (static_cast<jit_phi *> (phi)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3253 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3254 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3255 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3256 jit_block *last = blocks.back (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3257 builder.SetInsertPoint (last->to_llvm ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3258 builder.CreateRetVoid (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3259 } catch (const jit_fail_exception& e) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3260 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3261 function->eraseFromParent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3262 throw; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3263 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3264 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3265 return function; |
14899 | 3266 } |
3267 | |
3268 void | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3269 jit_convert::convert_llvm::finish_phi (jit_phi *phi) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3270 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3271 llvm::PHINode *llvm_phi = phi->to_llvm (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3272 for (size_t i = 0; i < phi->argument_count (); ++i) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3273 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3274 llvm::BasicBlock *pred = phi->incomming_llvm (i); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3275 llvm_phi->addIncoming (phi->argument_llvm (i), pred); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3276 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3277 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3278 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3279 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3280 jit_convert::convert_llvm::visit (jit_const_string& cs) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3281 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3282 cs.stash_llvm (builder.CreateGlobalStringPtr (cs.value ())); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3283 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3284 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3285 void |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3286 jit_convert::convert_llvm::visit (jit_const_bool& cb) |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3287 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3288 cb.stash_llvm (llvm::ConstantInt::get (cb.type_llvm (), cb.value ())); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3289 } |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3290 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3291 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3292 jit_convert::convert_llvm::visit (jit_const_scalar& cs) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3293 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3294 cs.stash_llvm (llvm::ConstantFP::get (cs.type_llvm (), cs.value ())); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3295 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3296 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3297 void |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3298 jit_convert::convert_llvm::visit (jit_const_complex& cc) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3299 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3300 llvm::Type *scalar_t = jit_typeinfo::get_scalar_llvm (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3301 llvm::Constant *values[2]; |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3302 Complex value = cc.value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3303 values[0] = llvm::ConstantFP::get (scalar_t, value.real ()); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3304 values[1] = llvm::ConstantFP::get (scalar_t, value.imag ()); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3305 cc.stash_llvm (llvm::ConstantVector::get (values)); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3306 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3307 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3308 void jit_convert::convert_llvm::visit (jit_const_index& ci) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3309 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3310 ci.stash_llvm (llvm::ConstantInt::get (ci.type_llvm (), ci.value ())); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3311 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3312 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3313 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3314 jit_convert::convert_llvm::visit (jit_const_range& cr) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3315 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3316 llvm::StructType *stype = llvm::cast<llvm::StructType>(cr.type_llvm ()); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3317 llvm::Type *scalar_t = jit_typeinfo::get_scalar_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3318 llvm::Type *idx = jit_typeinfo::get_index_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3319 const jit_range& rng = cr.value (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3320 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3321 llvm::Constant *constants[4]; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3322 constants[0] = llvm::ConstantFP::get (scalar_t, rng.base); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3323 constants[1] = llvm::ConstantFP::get (scalar_t, rng.limit); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3324 constants[2] = llvm::ConstantFP::get (scalar_t, rng.inc); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3325 constants[3] = llvm::ConstantInt::get (idx, rng.nelem); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3326 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3327 llvm::Value *as_llvm; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3328 as_llvm = llvm::ConstantStruct::get (stype, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3329 llvm::makeArrayRef (constants, 4)); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3330 cr.stash_llvm (as_llvm); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3331 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3332 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3333 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3334 jit_convert::convert_llvm::visit (jit_block& b) |
14899 | 3335 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3336 llvm::BasicBlock *block = b.to_llvm (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3337 builder.SetInsertPoint (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3338 for (jit_block::iterator iter = b.begin (); iter != b.end (); ++iter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3339 visit (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3340 } |
14903 | 3341 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3342 void |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
3343 jit_convert::convert_llvm::visit (jit_branch& b) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3344 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3345 b.stash_llvm (builder.CreateBr (b.successor_llvm ())); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3346 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3347 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3348 void |
14958
4b98b3f66e46
Rename jit_break to jit_branch and jit_cond_break to jit_cond_branch
Max Brister <max@2bass.com>
parents:
14955
diff
changeset
|
3349 jit_convert::convert_llvm::visit (jit_cond_branch& cb) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3350 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3351 llvm::Value *cond = cb.cond_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3352 llvm::Value *br; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3353 br = builder.CreateCondBr (cond, cb.successor_llvm (0), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3354 cb.successor_llvm (1)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3355 cb.stash_llvm (br); |
14899 | 3356 } |
3357 | |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3358 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3359 jit_convert::convert_llvm::visit (jit_call& call) |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3360 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3361 llvm::Value *ret = create_call (call.overload (), call.arguments ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3362 call.stash_llvm (ret); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3363 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3364 |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3365 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3366 jit_convert::convert_llvm::visit (jit_extract_argument& extract) |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3367 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3368 llvm::Value *arg = arguments[extract.name ()]; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3369 assert (arg); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3370 arg = builder.CreateLoad (arg); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3371 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3372 jit_value *jarg = jthis.create<jit_argument> (jit_typeinfo::get_any (), arg); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3373 extract.stash_llvm (create_call (extract.overload (), jarg)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3374 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3375 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3376 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3377 jit_convert::convert_llvm::visit (jit_store_argument& store) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3378 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3379 llvm::Value *arg_value = create_call (store.overload (), store.result ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3380 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3381 llvm::Value *arg = arguments[store.name ()]; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3382 store.stash_llvm (builder.CreateStore (arg_value, arg)); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3383 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3384 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3385 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3386 jit_convert::convert_llvm::visit (jit_phi& phi) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3387 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3388 // we might not have converted all incoming branches, so we don't |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3389 // set incomming branches now |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3390 llvm::PHINode *node = llvm::PHINode::Create (phi.type_llvm (), |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3391 phi.argument_count ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3392 builder.Insert (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3393 phi.stash_llvm (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3394 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3395 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3396 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3397 jit_convert::convert_llvm::visit (jit_variable&) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3398 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3399 fail ("ERROR: SSA construction should remove all variables"); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3400 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3401 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3402 void |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
3403 jit_convert::convert_llvm::visit (jit_error_check& check) |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3404 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3405 llvm::Value *cond = jit_typeinfo::insert_error_check (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3406 llvm::Value *br = builder.CreateCondBr (cond, check.successor_llvm (0), |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3407 check.successor_llvm (1)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3408 check.stash_llvm (br); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3409 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3410 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3411 void |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3412 jit_convert::convert_llvm::visit (jit_assign& assign) |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3413 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3414 assign.stash_llvm (assign.src ()->to_llvm ()); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3415 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3416 if (assign.artificial ()) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3417 return; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3418 |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3419 jit_value *new_value = assign.src (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3420 if (isa<jit_assign_base> (new_value)) |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3421 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3422 const jit_operation::overload& ol |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3423 = jit_typeinfo::get_grab (new_value->type ()); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3424 if (ol.function) |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3425 assign.stash_llvm (create_call (ol, new_value)); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3426 } |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3427 |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3428 jit_value *overwrite = assign.overwrite (); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3429 if (isa<jit_assign_base> (overwrite)) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3430 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3431 const jit_operation::overload& ol |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3432 = jit_typeinfo::get_release (overwrite->type ()); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3433 if (ol.function) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3434 create_call (ol, overwrite); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3435 } |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3436 } |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3437 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3438 void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3439 jit_convert::convert_llvm::visit (jit_argument&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3440 {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3441 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3442 llvm::Value * |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3443 jit_convert::convert_llvm::create_call (const jit_operation::overload& ol, |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3444 const std::vector<jit_value *>& jargs) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3445 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3446 llvm::IRBuilder<> alloca_inserter (prelude, prelude->begin ()); |
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3447 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3448 llvm::Function *fun = ol.function; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3449 if (! fun) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3450 fail ("Missing overload"); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3451 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3452 const llvm::Function::ArgumentListType& alist = fun->getArgumentList (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3453 size_t nargs = alist.size (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3454 bool sret = false; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3455 if (nargs != jargs.size ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3456 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3457 // first argument is the structure return value |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3458 assert (nargs == jargs.size () + 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3459 sret = true; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3460 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3461 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3462 std::vector<llvm::Value *> args (nargs); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3463 llvm::Function::arg_iterator llvm_arg = fun->arg_begin (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3464 if (sret) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3465 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3466 args[0] = alloca_inserter.CreateAlloca (ol.result->to_llvm ()); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3467 ++llvm_arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3468 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3469 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3470 for (size_t i = 0; i < jargs.size (); ++i, ++llvm_arg) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3471 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3472 llvm::Value *arg = jargs[i]->to_llvm (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3473 llvm::Type *arg_type = arg->getType (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3474 llvm::Type *llvm_arg_type = llvm_arg->getType (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3475 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3476 if (arg_type == llvm_arg_type) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3477 args[i + sret] = arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3478 else |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3479 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3480 // pass structure by pointer |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3481 assert (arg_type->getPointerTo () == llvm_arg_type); |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3482 llvm::Value *new_arg = alloca_inserter.CreateAlloca (arg_type); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3483 builder.CreateStore (arg, new_arg); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3484 args[i + sret] = new_arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3485 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3486 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3487 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3488 llvm::Value *llvm_call = builder.CreateCall (fun, args); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3489 return sret ? builder.CreateLoad (args[0]) : llvm_call; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3490 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3491 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3492 llvm::Value * |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3493 jit_convert::convert_llvm::create_call (const jit_operation::overload& ol, |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3494 const std::vector<jit_use>& uses) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3495 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3496 std::vector<jit_value *> values (uses.size ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3497 for (size_t i = 0; i < uses.size (); ++i) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3498 values[i] = uses[i].value (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3499 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3500 return create_call (ol, values); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3501 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3502 |
14906 | 3503 // -------------------- tree_jit -------------------- |
3504 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3505 tree_jit::tree_jit (void) : module (0), engine (0) |
14906 | 3506 { |
3507 } | |
3508 | |
3509 tree_jit::~tree_jit (void) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3510 {} |
14906 | 3511 |
3512 bool | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3513 tree_jit::execute (tree_simple_for_command& cmd) |
14906 | 3514 { |
3515 if (! initialize ()) | |
3516 return false; | |
3517 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3518 jit_info *info = cmd.get_info (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3519 if (! info || ! info->match ()) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3520 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3521 delete info; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3522 info = new jit_info (*this, cmd); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3523 cmd.stash_info (info); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3524 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3525 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3526 return info->execute (); |
14906 | 3527 } |
3528 | |
3529 bool | |
3530 tree_jit::initialize (void) | |
14903 | 3531 { |
14906 | 3532 if (engine) |
3533 return true; | |
3534 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3535 if (! module) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3536 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3537 llvm::InitializeNativeTarget (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3538 module = new llvm::Module ("octave", context); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3539 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3540 |
14906 | 3541 // sometimes this fails pre main |
3542 engine = llvm::ExecutionEngine::createJIT (module); | |
3543 | |
3544 if (! engine) | |
3545 return false; | |
3546 | |
3547 module_pass_manager = new llvm::PassManager (); | |
3548 module_pass_manager->add (llvm::createAlwaysInlinerPass ()); | |
3549 | |
3550 pass_manager = new llvm::FunctionPassManager (module); | |
3551 pass_manager->add (new llvm::TargetData(*engine->getTargetData ())); | |
3552 pass_manager->add (llvm::createBasicAliasAnalysisPass ()); | |
3553 pass_manager->add (llvm::createPromoteMemoryToRegisterPass ()); | |
3554 pass_manager->add (llvm::createInstructionCombiningPass ()); | |
3555 pass_manager->add (llvm::createReassociatePass ()); | |
3556 pass_manager->add (llvm::createGVNPass ()); | |
3557 pass_manager->add (llvm::createCFGSimplificationPass ()); | |
3558 pass_manager->doInitialization (); | |
3559 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3560 jit_typeinfo::initialize (module, engine); |
14906 | 3561 |
3562 return true; | |
3563 } | |
3564 | |
3565 | |
3566 void | |
3567 tree_jit::optimize (llvm::Function *fn) | |
3568 { | |
3569 module_pass_manager->run (*module); | |
3570 pass_manager->run (*fn); | |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3571 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3572 #ifdef OCTAVE_JIT_DEBUG |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3573 std::string error; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3574 llvm::raw_fd_ostream fout ("test.bc", error, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3575 llvm::raw_fd_ostream::F_Binary); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3576 llvm::WriteBitcodeToFile (module, fout); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3577 #endif |
14906 | 3578 } |
3579 | |
3580 // -------------------- jit_info -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3581 jit_info::jit_info (tree_jit& tjit, tree& tee) |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3582 : engine (tjit.get_engine ()), llvm_function (0) |
14906 | 3583 { |
14903 | 3584 try |
3585 { | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3586 jit_convert conv (tjit.get_module (), tee); |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3587 llvm_function = conv.get_function (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3588 arguments = conv.get_arguments (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3589 bounds = conv.get_bounds (); |
14903 | 3590 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3591 catch (const jit_fail_exception& e) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3592 { |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3593 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3594 if (e.known ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3595 std::cout << "jit fail: " << e.what () << std::endl; |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3596 #endif |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3597 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3598 |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3599 if (! llvm_function) |
14903 | 3600 { |
3601 function = 0; | |
3602 return; | |
3603 } | |
3604 | |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3605 tjit.optimize (llvm_function); |
14906 | 3606 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3607 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3608 std::cout << "-------------------- optimized llvm ir --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3609 llvm::raw_os_ostream llvm_cout (std::cout); |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3610 llvm_function->print (llvm_cout); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3611 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3612 #endif |
14903 | 3613 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3614 void *void_fn = engine->getPointerToFunction (llvm_function); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3615 function = reinterpret_cast<jited_function> (void_fn); |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3616 } |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3617 |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3618 jit_info::~jit_info (void) |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3619 { |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3620 if (llvm_function) |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3621 llvm_function->eraseFromParent (); |
14903 | 3622 } |
3623 | |
3624 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3625 jit_info::execute (void) const |
14899 | 3626 { |
3627 if (! function) | |
3628 return false; | |
3629 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3630 std::vector<octave_base_value *> real_arguments (arguments.size ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3631 for (size_t i = 0; i < arguments.size (); ++i) |
14899 | 3632 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3633 if (arguments[i].second) |
14899 | 3634 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3635 octave_value current = symbol_table::varval (arguments[i].first); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3636 octave_base_value *obv = current.internal_rep (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3637 obv->grab (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3638 real_arguments[i] = obv; |
14899 | 3639 } |
3640 } | |
3641 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3642 function (&real_arguments[0]); |
14899 | 3643 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3644 for (size_t i = 0; i < arguments.size (); ++i) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3645 symbol_table::varref (arguments[i].first) = real_arguments[i]; |
14910
a8f1e08de8fc
Simplified llvm::GenericValue creation
Max Brister <max@2bass.com>
parents:
14906
diff
changeset
|
3646 |
14899 | 3647 return true; |
3648 } | |
14903 | 3649 |
3650 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3651 jit_info::match (void) const |
14903 | 3652 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3653 if (! function) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3654 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3655 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3656 for (size_t i = 0; i < bounds.size (); ++i) |
14903 | 3657 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3658 const std::string& arg_name = bounds[i].second; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3659 octave_value value = symbol_table::find (arg_name); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3660 jit_type *type = jit_typeinfo::type_of (value); |
14906 | 3661 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3662 // FIXME: Check for a parent relationship |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3663 if (type != bounds[i].first) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3664 return false; |
14903 | 3665 } |
3666 | |
3667 return true; | |
3668 } | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3669 #endif |