Mercurial > octave
annotate src/pt-jit.cc @ 14992:fd8d1a616be1
Compile JIT on msvc
* src/TEMPLATE-INST/Array-jit.cc: Mark Array<octave_idx_type> as dll import.
* src/pt-jit.cc: Include symtab.h.
* src/pt-jit.h: Avoid including Array<octave_value> in Cell.h.
author | Michael Goffioul |
---|---|
date | Tue, 17 Jul 2012 09:48:53 -0500 |
parents | dfaa8da46364 |
children | 094bc0a145a1 |
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" |
14992 | 63 #include "symtab.h" |
14899 | 64 |
14903 | 65 static llvm::IRBuilder<> builder (llvm::getGlobalContext ()); |
66 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
67 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
|
68 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
69 jit_typeinfo *jit_typeinfo::instance; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
70 |
14906 | 71 // 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
|
72 class jit_fail_exception : public std::runtime_error |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
73 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
74 public: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
75 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
|
76 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
|
77 mknown (true) |
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 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
80 bool known (void) const { return mknown; } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
81 private: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
82 bool mknown; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
83 }; |
14906 | 84 |
14940
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
85 static void fail (void) GCC_ATTR_NORETURN; |
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
86 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
|
87 |
14906 | 88 static void |
89 fail (void) | |
90 { | |
91 throw jit_fail_exception (); | |
92 } | |
93 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
94 #ifdef OCTAVE_JIT_DEBUG |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
95 static void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
96 fail (const std::string& reason) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
97 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
98 throw jit_fail_exception (reason); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
99 } |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
100 #else |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
101 static void |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
102 fail (const std::string&) |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
103 { |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
104 throw jit_fail_exception (); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
105 } |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
106 #endif // OCTAVE_JIT_DEBUG |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
107 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
108 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
|
109 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
110 if (! atype) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
111 return os << "null"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
112 return os << atype->name (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
113 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
114 |
14903 | 115 // function that jit code calls |
116 extern "C" void | |
117 octave_jit_print_any (const char *name, octave_base_value *obv) | |
118 { | |
119 obv->print_with_name (octave_stdout, name, true); | |
120 } | |
14899 | 121 |
122 extern "C" void | |
14903 | 123 octave_jit_print_double (const char *name, double value) |
14899 | 124 { |
125 // FIXME: We should avoid allocating a new octave_scalar each time | |
126 octave_value ov (value); | |
127 ov.print_with_name (octave_stdout, name); | |
128 } | |
129 | |
14903 | 130 extern "C" octave_base_value* |
131 octave_jit_binary_any_any (octave_value::binary_op op, octave_base_value *lhs, | |
132 octave_base_value *rhs) | |
133 { | |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
134 octave_value olhs (lhs, true); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
135 octave_value orhs (rhs, true); |
14903 | 136 octave_value result = do_binary_op (op, olhs, orhs); |
137 octave_base_value *rep = result.internal_rep (); | |
138 rep->grab (); | |
139 return rep; | |
140 } | |
141 | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
142 extern "C" octave_idx_type |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
143 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
|
144 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
145 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
|
146 return rng.nelem (); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
147 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
148 |
14903 | 149 extern "C" void |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
150 octave_jit_release_any (octave_base_value *obv) |
14903 | 151 { |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
152 obv->release (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
153 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
154 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
155 extern "C" void |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
156 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
|
157 { |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
158 delete m->array; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
159 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
160 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
161 extern "C" octave_base_value * |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
162 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
|
163 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
164 obv->grab (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
165 return obv; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
166 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
167 |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
168 extern "C" void |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
169 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
|
170 { |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
171 *result = *m->array; |
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 |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
174 extern "C" octave_base_value * |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
175 octave_jit_cast_any_matrix (jit_matrix *m) |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
176 { |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
177 octave_value ret (*m->array); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
178 octave_base_value *rep = ret.internal_rep (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
179 rep->grab (); |
14987
65f74f52886c
Memory leaks with matrices in JIT
Max Brister <max@2bass.com>
parents:
14986
diff
changeset
|
180 delete m->array; |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
181 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
182 return rep; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
183 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
184 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
185 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
186 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
|
187 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
188 NDArray m = obv->array_value (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
189 *ret = m; |
14987
65f74f52886c
Memory leaks with matrices in JIT
Max Brister <max@2bass.com>
parents:
14986
diff
changeset
|
190 obv->release (); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
191 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
192 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
193 extern "C" double |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
194 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
|
195 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
196 double ret = obv->double_value (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
197 obv->release (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
198 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
199 } |
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 extern "C" octave_base_value * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
202 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
|
203 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
204 return new octave_scalar (value); |
14903 | 205 } |
206 | |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
207 extern "C" Complex |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
208 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
|
209 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
210 Complex ret = obv->complex_value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
211 obv->release (); |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
212 return ret; |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
213 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
214 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
215 extern "C" octave_base_value * |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
216 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
|
217 { |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
218 if (c.imag () == 0) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
219 return new octave_scalar (c.real ()); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
220 else |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
221 return new octave_complex (c); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
222 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
223 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
224 extern "C" void |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
225 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
|
226 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
227 try |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
228 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
229 gripe_nan_to_logical_conversion (); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
230 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
231 catch (const octave_execution_exception&) |
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 gripe_library_execution_error (); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
234 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
235 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
236 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
237 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
238 octave_jit_ginvalid_index (void) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
239 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
240 try |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
241 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
242 gripe_invalid_index (); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
243 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
244 catch (const octave_execution_exception&) |
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 gripe_library_execution_error (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
247 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
248 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
249 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
250 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
251 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
|
252 octave_idx_type ext) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
253 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
254 try |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
255 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
256 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
|
257 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
258 catch (const octave_execution_exception&) |
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 gripe_library_execution_error (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
261 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
262 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
263 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
264 extern "C" void |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
265 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
|
266 double value) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
267 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
268 NDArray *array = mat->array; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
269 if (array->nelem () < index) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
270 array->resize1 (index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
271 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
272 double *data = array->fortran_vec (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
273 data[index - 1] = value; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
274 |
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
|
275 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
|
276 } |
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 |
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 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
|
279 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
|
280 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
|
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 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
|
283 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
|
284 |
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 // 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
|
286 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
|
287 && 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
|
288 { |
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
|
289 // 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
|
290 // 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
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 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
|
298 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
|
299 } |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
300 |
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 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
|
302 { |
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
|
303 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
|
304 |
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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 { |
d3f9801b1f29
src/pt-jit.cc: Take into account step for matrix range subsasgn in JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
310 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
|
311 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
|
312 } |
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
|
313 } |
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 |
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 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
|
317 { |
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 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
|
319 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
|
320 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
|
321 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
|
322 } |
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
|
323 |
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
|
324 result->update (array); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
325 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
326 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
327 extern "C" Complex |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
328 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
|
329 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
330 // see src/OPERATORS/op-cs-cs.cc |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
331 if (rhs == 0.0) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
332 gripe_divide_by_zero (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
333 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
334 return lhs / rhs; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
335 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
336 |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
337 // FIXME: CP form src/xpow.cc |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
338 static inline int |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
339 xisint (double x) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
340 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
341 return (D_NINT (x) == x |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
342 && ((x >= 0 && x < INT_MAX) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
343 || (x <= 0 && x > INT_MIN))); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
344 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
345 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
346 extern "C" Complex |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
347 octave_jit_pow_scalar_scalar (double lhs, double rhs) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
348 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
349 // FIXME: almost CP from src/xpow.cc |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
350 if (lhs < 0.0 && ! xisint (rhs)) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
351 return std::pow (Complex (lhs), rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
352 return std::pow (lhs, rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
353 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
354 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
355 extern "C" Complex |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
356 octave_jit_pow_complex_complex (Complex lhs, Complex rhs) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
357 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
358 if (lhs.imag () == 0 && rhs.imag () == 0) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
359 return octave_jit_pow_scalar_scalar (lhs.real (), rhs.real ()); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
360 return std::pow (lhs, rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
361 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
362 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
363 extern "C" Complex |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
364 octave_jit_pow_complex_scalar (Complex lhs, double rhs) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
365 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
366 if (lhs.imag () == 0) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
367 return octave_jit_pow_scalar_scalar (lhs.real (), rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
368 return std::pow (lhs, rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
369 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
370 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
371 extern "C" Complex |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
372 octave_jit_pow_scalar_complex (double lhs, Complex rhs) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
373 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
374 if (rhs.imag () == 0) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
375 return octave_jit_pow_scalar_scalar (lhs, rhs.real ()); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
376 return std::pow (lhs, rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
377 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
378 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
379 extern "C" void |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
380 octave_jit_print_matrix (jit_matrix *m) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
381 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
382 std::cout << *m << std::endl; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
383 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
384 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
385 static void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
386 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
|
387 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
388 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
|
389 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
390 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
391 // 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
|
392 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
|
393 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
|
394 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
|
395 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
400 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
|
401 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
402 // 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
|
403 // 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
|
404 // 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
|
405 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
|
406 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
407 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
|
408 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
409 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
|
410 return 0; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
411 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
412 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
413 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
|
414 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
|
415 result_type); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
416 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
|
417 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
418 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
|
419 return 0; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
420 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
421 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
422 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
|
423 ret->grab (); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
424 return ret; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
425 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
426 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
427 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
|
428 || (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
|
429 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
|
430 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
431 return 0; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
432 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
433 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
434 // -------------------- 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
|
435 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
|
436 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
|
437 { |
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
|
438 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
|
439 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
|
440 } |
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
|
441 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
442 std::ostream& |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
443 operator<< (std::ostream& os, const jit_range& rng) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
444 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
445 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
|
446 << ", " << rng.nelem << "]"; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
447 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
448 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
449 // -------------------- jit_matrix -------------------- |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
450 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
451 std::ostream& |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
452 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
|
453 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
454 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
|
455 << mat.slice_len << ", " << mat.dimensions << ", " |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
456 << mat.array << "]"; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
457 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
458 |
14903 | 459 // -------------------- jit_type -------------------- |
460 llvm::Type * | |
461 jit_type::to_llvm_arg (void) const | |
462 { | |
463 return llvm_type ? llvm_type->getPointerTo () : 0; | |
464 } | |
465 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
466 // -------------------- jit_operation -------------------- |
14903 | 467 void |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
468 jit_operation::add_overload (const overload& func, |
14903 | 469 const std::vector<jit_type*>& args) |
470 { | |
471 if (args.size () >= overloads.size ()) | |
472 overloads.resize (args.size () + 1); | |
473 | |
474 Array<overload>& over = overloads[args.size ()]; | |
475 dim_vector dv (over.dims ()); | |
476 Array<octave_idx_type> idx = to_idx (args); | |
477 bool must_resize = false; | |
478 | |
479 if (dv.length () != idx.numel ()) | |
480 { | |
481 dv.resize (idx.numel ()); | |
482 must_resize = true; | |
483 } | |
484 | |
485 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
486 if (dv(i) <= idx(i)) | |
487 { | |
488 must_resize = true; | |
489 dv(i) = idx(i) + 1; | |
490 } | |
491 | |
492 if (must_resize) | |
493 over.resize (dv); | |
494 | |
495 over(idx) = func; | |
496 } | |
497 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
498 const jit_operation::overload& |
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
499 jit_operation::get_overload (const std::vector<jit_type*>& types) const |
14903 | 500 { |
501 // FIXME: We should search for the next best overload on failure | |
502 static overload null_overload; | |
503 if (types.size () >= overloads.size ()) | |
504 return null_overload; | |
505 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
506 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
|
507 if (! types[i]) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
508 return null_overload; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
509 |
14903 | 510 const Array<overload>& over = overloads[types.size ()]; |
511 dim_vector dv (over.dims ()); | |
512 Array<octave_idx_type> idx = to_idx (types); | |
513 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
514 if (idx(i) >= dv(i)) | |
515 return null_overload; | |
516 | |
517 return over(idx); | |
518 } | |
519 | |
520 Array<octave_idx_type> | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
521 jit_operation::to_idx (const std::vector<jit_type*>& types) const |
14903 | 522 { |
523 octave_idx_type numel = types.size (); | |
524 if (numel == 1) | |
525 numel = 2; | |
526 | |
527 Array<octave_idx_type> idx (dim_vector (1, numel)); | |
528 for (octave_idx_type i = 0; i < static_cast<octave_idx_type> (types.size ()); | |
529 ++i) | |
530 idx(i) = types[i]->type_id (); | |
531 | |
532 if (types.size () == 1) | |
533 { | |
534 idx(1) = idx(0); | |
535 idx(0) = 0; | |
536 } | |
537 | |
538 return idx; | |
539 } | |
540 | |
541 // -------------------- jit_typeinfo -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
542 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
543 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
|
544 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
545 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
|
546 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
547 |
14906 | 548 jit_typeinfo::jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e) |
549 : module (m), engine (e), next_id (0) | |
14899 | 550 { |
14903 | 551 // 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
|
552 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
|
553 any_t = any_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
554 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 string_t = string_t->getPointerTo (); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
559 llvm::Type *index_t = llvm::Type::getIntNTy (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
560 sizeof(octave_idx_type) * 8); |
14906 | 561 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
562 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
|
563 std::vector<llvm::Type *> range_contents (4, scalar_t); |
14906 | 564 range_contents[3] = index_t; |
565 range_t->setBody (range_contents); | |
566 | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
567 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
|
568 llvm::Type *int_t = refcount_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
569 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
570 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
|
571 llvm::Type *matrix_contents[5]; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
572 matrix_contents[0] = refcount_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
573 matrix_contents[1] = scalar_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
574 matrix_contents[2] = index_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
575 matrix_contents[3] = index_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
576 matrix_contents[4] = string_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
577 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
|
578 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
579 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
|
580 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
581 // 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
|
582 // conventions right. |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
583 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
|
584 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
|
585 complex_ret->setBody (complex_ret_contents); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
586 |
14903 | 587 // create types |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
588 any = new_type ("any", 0, any_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
589 matrix = new_type ("matrix", any, matrix_t); |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
590 complex = new_type ("complex", any, complex_t); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
591 scalar = new_type ("scalar", complex, scalar_t); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 index = new_type ("index", any, index_t); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
596 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
597 casts.resize (next_id + 1); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
598 identities.resize (next_id + 1, 0); |
14903 | 599 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
600 // bind global variables |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
601 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
|
602 llvm::GlobalValue::ExternalLinkage, |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
603 0, "error_state"); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
604 engine->addGlobalMapping (lerror_state, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
605 reinterpret_cast<void *> (&error_state)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
606 |
14903 | 607 // 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
|
608 llvm::Function *fn; |
14903 | 609 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
|
610 = 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
|
611 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
|
612 any_t, binary_op_type, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
613 any_t, any_t); |
14903 | 614 engine->addGlobalMapping (any_binary, |
615 reinterpret_cast<void*>(&octave_jit_binary_any_any)); | |
616 | |
617 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
|
618 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
|
619 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
620 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
|
621 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
|
622 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
|
623 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
624 |
14903 | 625 for (int op = 0; op < octave_value::num_binary_ops; ++op) |
626 { | |
627 llvm::Twine fn_name ("octave_jit_binary_any_any_"); | |
628 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
|
629 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
|
630 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 631 builder.SetInsertPoint (block); |
14903 | 632 llvm::APInt op_int(sizeof (octave_value::binary_op), op, |
633 std::numeric_limits<octave_value::binary_op>::is_signed); | |
634 llvm::Value *op_as_llvm = llvm::ConstantInt::get (binary_op_type, op_int); | |
14906 | 635 llvm::Value *ret = builder.CreateCall3 (any_binary, |
14903 | 636 op_as_llvm, |
637 fn->arg_begin (), | |
638 ++fn->arg_begin ()); | |
14906 | 639 builder.CreateRet (ret); |
14945 | 640 binary_ops[op].add_overload (fn, true, any, any, any); |
14903 | 641 } |
642 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
643 llvm::Type *void_t = llvm::Type::getVoidTy (context); |
14903 | 644 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
645 // grab any |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
646 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
|
647 engine->addGlobalMapping (fn, reinterpret_cast<void*>(&octave_jit_grab_any)); |
14945 | 648 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
|
649 grab_fn.stash_name ("grab"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
650 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
651 // grab matrix |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
652 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
|
653 void_t, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
654 matrix_t->getPointerTo ()); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
655 engine->addGlobalMapping (print_matrix, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
656 reinterpret_cast<void*>(&octave_jit_print_matrix)); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
657 fn = create_function ("octave_jit_grab_matrix", void_t, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
658 matrix_t->getPointerTo (), matrix_t->getPointerTo ()); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
659 engine->addGlobalMapping (fn, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
660 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
|
661 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
|
662 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
663 // release any |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
664 fn = create_function ("octave_jit_release_any", void_t, any_t); |
14973 | 665 llvm::Function *release_any = fn; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
666 engine->addGlobalMapping (fn, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
667 reinterpret_cast<void*>(&octave_jit_release_any)); |
14945 | 668 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
|
669 release_fn.stash_name ("release"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
670 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
671 // release matrix |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
672 fn = create_function ("octave_jit_release_matrix", void_t, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
673 matrix_t->getPointerTo ()); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
674 engine->addGlobalMapping (fn, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
675 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
|
676 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
|
677 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
678 // release scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
679 fn = create_identity (scalar); |
14945 | 680 release_fn.add_overload (fn, false, 0, scalar); |
14903 | 681 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
682 // release complex |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
683 fn = create_identity (complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
684 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
|
685 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
686 // release index |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
687 fn = create_identity (index); |
14945 | 688 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
|
689 |
14903 | 690 // now for binary scalar operations |
691 // FIXME: Finish all operations | |
692 add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); | |
693 add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); | |
694 add_binary_op (scalar, octave_value::op_mul, llvm::Instruction::FMul); | |
695 add_binary_op (scalar, octave_value::op_el_mul, llvm::Instruction::FMul); | |
696 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 |
14941 | 704 llvm::Function *gripe_div0 = create_function ("gripe_divide_by_zero", void_t); |
705 engine->addGlobalMapping (gripe_div0, | |
706 reinterpret_cast<void *> (&gripe_divide_by_zero)); | |
707 | |
708 // divide is annoying because it might error | |
709 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
|
710 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); |
14941 | 711 builder.SetInsertPoint (body); |
712 { | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
713 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
|
714 fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
715 llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
716 "normal", fn); |
14941 | 717 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
718 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); |
14941 | 719 llvm::Value *check = builder.CreateFCmpUEQ (zero, ++fn->arg_begin ()); |
720 builder.CreateCondBr (check, warn_block, normal_block); | |
721 | |
722 builder.SetInsertPoint (warn_block); | |
723 builder.CreateCall (gripe_div0); | |
724 builder.CreateBr (normal_block); | |
725 | |
726 builder.SetInsertPoint (normal_block); | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
727 llvm::Value *ret = builder.CreateFDiv (fn->arg_begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
728 ++fn->arg_begin ()); |
14941 | 729 builder.CreateRet (ret); |
730 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
731 jit_operation::overload ol (fn, true, scalar, scalar, scalar); |
14941 | 732 binary_ops[octave_value::op_div].add_overload (ol); |
733 binary_ops[octave_value::op_el_div].add_overload (ol); | |
734 } | |
735 llvm::verifyFunction (*fn); | |
736 | |
737 // ldiv is the same as div with the operators reversed | |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
738 fn = mirror_binary (fn); |
14941 | 739 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
740 jit_operation::overload ol (fn, true, scalar, scalar, scalar); |
14941 | 741 binary_ops[octave_value::op_ldiv].add_overload (ol); |
742 binary_ops[octave_value::op_el_ldiv].add_overload (ol); | |
743 } | |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
744 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
745 // In general, the result of scalar ^ scalar is a complex number. We might be |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
746 // able to improve on this if we keep track of the range of values varaibles |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
747 // can take on. |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
748 fn = create_function ("octave_jit_pow_scalar_scalar", complex_ret, scalar_t, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
749 scalar_t); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
750 engine->addGlobalMapping (fn, reinterpret_cast<void *> (octave_jit_pow_scalar_scalar)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
751 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
752 jit_operation::overload ol (wrap_complex (fn), false, complex, scalar, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
753 scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
754 binary_ops[octave_value::op_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
755 binary_ops[octave_value::op_el_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
756 } |
14941 | 757 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
758 // now for binary complex operations |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
759 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
|
760 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
|
761 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
762 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
|
763 complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
764 body = llvm::BasicBlock::Create (context, "body", fn); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
765 builder.SetInsertPoint (body); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
766 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
767 // (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
|
768 // 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
|
769 // addition. |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
770 llvm::Value *lhs = fn->arg_begin (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
771 llvm::Value *rhs = ++fn->arg_begin (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
772 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
773 // 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
|
774 // directly is sort of a pain. |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
775 llvm::Value *zero = builder.getInt32 (0); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
776 llvm::Value *one = builder.getInt32 (1); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
777 llvm::Value *two = builder.getInt32 (2); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
778 llvm::Value *three = builder.getInt32 (3); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
779 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
780 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
|
781 llvm::Value *mlhs = llvm::UndefValue::get (vec4); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
782 llvm::Value *mrhs = mlhs; |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
783 |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
784 llvm::Value *temp = complex_real (lhs); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
785 mlhs = builder.CreateInsertElement (mlhs, temp, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
786 mlhs = builder.CreateInsertElement (mlhs, temp, two); |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
787 temp = complex_imag (lhs); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
788 mlhs = builder.CreateInsertElement (mlhs, temp, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
789 mlhs = builder.CreateInsertElement (mlhs, temp, three); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
790 |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
791 temp = complex_real (rhs); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
792 mrhs = builder.CreateInsertElement (mrhs, temp, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
793 mrhs = builder.CreateInsertElement (mrhs, temp, three); |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
794 temp = complex_imag (rhs); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
795 mrhs = builder.CreateInsertElement (mrhs, temp, one); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
796 mrhs = builder.CreateInsertElement (mrhs, temp, two); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
797 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
798 llvm::Value *mres = builder.CreateFMul (mlhs, mrhs); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
799 llvm::Value *tlhs = builder.CreateExtractElement (mres, zero); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
800 llvm::Value *trhs = builder.CreateExtractElement (mres, one); |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
801 llvm::Value *ret_real = builder.CreateFSub (tlhs, trhs); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
802 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
803 tlhs = builder.CreateExtractElement (mres, two); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
804 trhs = builder.CreateExtractElement (mres, three); |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
805 llvm::Value *ret_imag = builder.CreateFAdd (tlhs, trhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
806 builder.CreateRet (complex_new (ret_real, ret_imag)); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
807 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
812 llvm::verifyFunction (*fn); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
813 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
814 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
|
815 complex_ret, complex_ret, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
816 complex_ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
817 engine->addGlobalMapping (complex_div, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
818 reinterpret_cast<void *> (&octave_jit_complex_div)); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
819 complex_div = wrap_complex (complex_div); |
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 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
|
822 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
|
823 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
|
824 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
825 |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
826 fn = mirror_binary (complex_div); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
827 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
828 jit_operation::overload ol (fn, true, complex, complex, complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
829 binary_ops[octave_value::op_ldiv].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
830 binary_ops[octave_value::op_el_ldiv].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
831 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
832 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
833 fn = create_function ("octave_jit_pow_complex_complex", complex_ret, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
834 complex_ret, complex_ret); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
835 engine->addGlobalMapping (fn, reinterpret_cast<void *> (octave_jit_pow_complex_complex)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
836 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
837 jit_operation::overload ol (wrap_complex (fn), false, complex, complex, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
838 complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
839 binary_ops[octave_value::op_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
840 binary_ops[octave_value::op_el_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
841 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
842 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
843 fn = create_function ("octave_jit_*_scalar_complex", complex, scalar, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
844 complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
845 llvm::Function *mul_scalar_complex = fn; |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
846 body = llvm::BasicBlock::Create (context, "body", fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
847 builder.SetInsertPoint (body); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
848 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
849 llvm::Value *lhs = fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
850 llvm::Value *tlhs = complex_new (lhs, lhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
851 llvm::Value *rhs = ++fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
852 builder.CreateRet (builder.CreateFMul (tlhs, rhs)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
853 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
854 jit_operation::overload ol (fn, false, complex, scalar, complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
855 binary_ops[octave_value::op_mul].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
856 binary_ops[octave_value::op_el_mul].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
857 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
858 llvm::verifyFunction (*fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
859 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
860 fn = mirror_binary (mul_scalar_complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
861 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
862 jit_operation::overload ol (fn, false, complex, complex, scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
863 binary_ops[octave_value::op_mul].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
864 binary_ops[octave_value::op_el_mul].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
865 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
866 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
867 fn = create_function ("octave_jit_+_scalar_complex", complex, scalar, |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
868 complex); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
869 body = llvm::BasicBlock::Create (context, "body", fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
870 builder.SetInsertPoint (body); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
871 { |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
872 llvm::Value *lhs = fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
873 llvm::Value *rhs = ++fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
874 llvm::Value *real = builder.CreateFAdd (lhs, complex_real (rhs)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
875 builder.CreateRet (complex_real (rhs, real)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
876 llvm::verifyFunction (*fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
877 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
878 binary_ops[octave_value::op_add].add_overload (fn, false, complex, scalar, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
879 complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
880 fn = mirror_binary (fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
881 binary_ops[octave_value::op_add].add_overload (fn, false, complex, complex, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
882 scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
883 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
884 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
885 fn = create_function ("octave_jit_-_complex_scalar", complex, complex, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
886 scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
887 body = llvm::BasicBlock::Create (context, "body", fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
888 builder.SetInsertPoint (body); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
889 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
890 llvm::Value *lhs = fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
891 llvm::Value *rhs = ++fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
892 llvm::Value *real = builder.CreateFSub (complex_real (lhs), rhs); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
893 builder.CreateRet (complex_real (lhs, real)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
894 llvm::verifyFunction (*fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
895 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
896 binary_ops[octave_value::op_sub].add_overload (fn, false, complex, complex, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
897 scalar); |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
898 } |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
899 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
900 fn = create_function ("octave_jit_-_scalar_complex", complex, scalar, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
901 complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
902 body = llvm::BasicBlock::Create (context, "body", fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
903 builder.SetInsertPoint (body); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
904 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
905 llvm::Value *lhs = fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
906 llvm::Value *rhs = ++fn->arg_begin (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
907 llvm::Value *real = builder.CreateFSub (lhs, complex_real (rhs)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
908 builder.CreateRet (complex_real (rhs, real)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
909 llvm::verifyFunction (*fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
910 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
911 binary_ops[octave_value::op_sub].add_overload (fn, false, complex, scalar, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
912 complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
913 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
914 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
915 fn = create_function ("octave_jit_pow_scalar_complex", complex_ret, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
916 scalar_t, complex_ret); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
917 engine->addGlobalMapping (fn, reinterpret_cast<void *> (octave_jit_pow_scalar_complex)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
918 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
919 jit_operation::overload ol (wrap_complex (fn), false, complex, scalar, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
920 complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
921 binary_ops[octave_value::op_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
922 binary_ops[octave_value::op_el_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
923 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
924 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
925 fn = create_function ("octave_jit_pow_complex_scalar", complex_ret, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
926 complex_ret, scalar_t); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
927 engine->addGlobalMapping (fn, reinterpret_cast<void *> (octave_jit_pow_complex_complex)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
928 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
929 jit_operation::overload ol (wrap_complex (fn), false, complex, complex, |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
930 scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
931 binary_ops[octave_value::op_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
932 binary_ops[octave_value::op_el_pow].add_overload (ol); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
933 } |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
934 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
935 // now for binary index operators |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
936 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
|
937 |
14975
95bfd032f4c7
Add element wise boolean And and Or in JIT
Max Brister <max@2bass.com>
parents:
14974
diff
changeset
|
938 // and binary bool operators |
95bfd032f4c7
Add element wise boolean And and Or in JIT
Max Brister <max@2bass.com>
parents:
14974
diff
changeset
|
939 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
|
940 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
|
941 |
14903 | 942 // now for printing functions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
943 print_fn.stash_name ("print"); |
14903 | 944 add_print (any, reinterpret_cast<void*> (&octave_jit_print_any)); |
945 add_print (scalar, reinterpret_cast<void*> (&octave_jit_print_double)); | |
14906 | 946 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
947 // initialize for loop |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
948 for_init_fn.stash_name ("for_init"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
949 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
950 fn = create_function ("octave_jit_for_range_init", index, range); |
14941 | 951 body = llvm::BasicBlock::Create (context, "body", fn); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
952 builder.SetInsertPoint (body); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
953 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
954 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
|
955 builder.CreateRet (zero); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
956 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
957 llvm::verifyFunction (*fn); |
14945 | 958 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
|
959 |
14906 | 960 // bounds check for for loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
961 for_check_fn.stash_name ("for_check"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
962 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
963 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
|
964 body = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 965 builder.SetInsertPoint (body); |
966 { | |
967 llvm::Value *nelem | |
968 = builder.CreateExtractValue (fn->arg_begin (), 3); | |
969 llvm::Value *idx = ++fn->arg_begin (); | |
970 llvm::Value *ret = builder.CreateICmpULT (idx, nelem); | |
971 builder.CreateRet (ret); | |
972 } | |
973 llvm::verifyFunction (*fn); | |
14945 | 974 for_check_fn.add_overload (fn, false, boolean, range, index); |
14906 | 975 |
976 // index variabe for for loop | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
977 for_index_fn.stash_name ("for_index"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
978 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
979 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
|
980 body = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 981 builder.SetInsertPoint (body); |
982 { | |
983 llvm::Value *idx = ++fn->arg_begin (); | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
984 llvm::Value *didx = builder.CreateSIToFP (idx, scalar_t); |
14906 | 985 llvm::Value *rng = fn->arg_begin (); |
986 llvm::Value *base = builder.CreateExtractValue (rng, 0); | |
987 llvm::Value *inc = builder.CreateExtractValue (rng, 2); | |
988 | |
989 llvm::Value *ret = builder.CreateFMul (didx, inc); | |
990 ret = builder.CreateFAdd (base, ret); | |
991 builder.CreateRet (ret); | |
992 } | |
993 llvm::verifyFunction (*fn); | |
14945 | 994 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
|
995 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
996 // logically true |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
997 logically_true_fn.stash_name ("logically_true"); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
998 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
999 llvm::Function *gripe_nantl |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1000 = 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
|
1001 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
|
1002 |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1003 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
|
1004 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
|
1005 builder.SetInsertPoint (body); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1006 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1007 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
|
1008 fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1009 llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1010 "normal", fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1011 |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1012 llvm::Value *check = builder.CreateFCmpUNE (fn->arg_begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1013 fn->arg_begin ()); |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1014 builder.CreateCondBr (check, error_block, normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1015 |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1016 builder.SetInsertPoint (error_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1017 builder.CreateCall (gripe_nantl); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1018 builder.CreateBr (normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1019 builder.SetInsertPoint (normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1020 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1021 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
|
1022 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
|
1023 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1024 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1025 llvm::verifyFunction (*fn); |
14945 | 1026 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
|
1027 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1028 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
|
1029 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
|
1030 builder.SetInsertPoint (body); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1031 builder.CreateRet (fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1032 llvm::verifyFunction (*fn); |
14945 | 1033 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
|
1034 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1035 // make_range |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1036 // 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
|
1037 make_range_fn.stash_name ("make_range"); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1038 llvm::Function *compute_nelem |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1039 = 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
|
1040 scalar); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1041 engine->addGlobalMapping (compute_nelem, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1042 reinterpret_cast<void*> (&octave_jit_compute_nelem)); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1043 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1044 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
|
1045 body = llvm::BasicBlock::Create (context, "body", fn); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1046 builder.SetInsertPoint (body); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1047 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1048 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
|
1049 llvm::Value *base = args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1050 llvm::Value *limit = ++args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1051 llvm::Value *inc = ++args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1052 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
|
1053 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1054 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
|
1055 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
|
1056 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
|
1057 izero, NULL); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1058 rng = builder.CreateInsertValue (rng, base, 0); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1059 rng = builder.CreateInsertValue (rng, limit, 1); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1060 rng = builder.CreateInsertValue (rng, inc, 2); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1061 rng = builder.CreateInsertValue (rng, nelem, 3); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1062 builder.CreateRet (rng); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1063 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1064 llvm::verifyFunction (*fn); |
14945 | 1065 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
|
1066 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1067 // paren_subsref |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1068 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
|
1069 void_t); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1070 engine->addGlobalMapping (ginvalid_index, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1071 reinterpret_cast<void*> (&octave_jit_ginvalid_index)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1072 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1073 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
|
1074 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
|
1075 index_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1076 engine->addGlobalMapping (gindex_range, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1077 reinterpret_cast<void*> (&octave_jit_gindex_range)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1078 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1079 fn = create_function ("()subsref", scalar, matrix, scalar); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1080 body = llvm::BasicBlock::Create (context, "body", fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1081 builder.SetInsertPoint (body); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1082 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1083 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
|
1084 llvm::Value *ione; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1085 if (index_t == int_t) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1086 ione = one; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1087 else |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1088 ione = llvm::ConstantInt::get (int_t, 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1089 |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
1090 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
|
1091 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1092 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
|
1093 llvm::Value *mat = args++; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1094 llvm::Value *idx = args; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1095 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1096 // 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
|
1097 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
|
1098 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
|
1099 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
|
1100 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
|
1101 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1102 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1103 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
|
1104 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1105 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
|
1106 "conv_error", fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1107 done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1108 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
|
1109 done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1110 builder.CreateCondBr (cond, conv_error, normal); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1111 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1112 builder.SetInsertPoint (conv_error); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1113 builder.CreateCall (ginvalid_index); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1114 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1115 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1116 builder.SetInsertPoint (normal); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1117 llvm::Value *len = builder.CreateExtractValue (mat, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1118 llvm::ArrayRef<unsigned> (2)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1119 cond = builder.CreateICmpSGT (int_idx, len); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1120 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1121 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1122 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
|
1123 "bounds_error", |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1124 fn, done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1125 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1126 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
|
1127 fn, done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1128 builder.CreateCondBr (cond, bounds_error, success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1129 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1130 builder.SetInsertPoint (bounds_error); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1131 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
|
1132 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1133 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1134 builder.SetInsertPoint (success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1135 llvm::Value *data = builder.CreateExtractValue (mat, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1136 llvm::ArrayRef<unsigned> (1)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1137 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
|
1138 llvm::Value *ret = builder.CreateLoad (gep); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1139 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1140 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1141 builder.SetInsertPoint (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1142 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1143 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
|
1144 builder.Insert (merge); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
1145 merge->addIncoming (undef, conv_error); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
1146 merge->addIncoming (undef, bounds_error); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1147 merge->addIncoming (ret, success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1148 builder.CreateRet (merge); |
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 llvm::verifyFunction (*fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1151 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
|
1152 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1153 // paren subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1154 paren_subsasgn_fn.stash_name ("()subsasgn"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1155 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1156 llvm::Function *resize_paren_subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1157 = 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
|
1158 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
|
1159 engine->addGlobalMapping (resize_paren_subsasgn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1160 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
|
1161 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1162 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
|
1163 scalar); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1164 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
|
1165 builder.SetInsertPoint (body); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1166 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1167 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
|
1168 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1169 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
|
1170 llvm::Value *mat = args++; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1171 llvm::Value *idx = args++; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1172 llvm::Value *value = args; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1173 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1180 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
|
1181 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1182 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
|
1183 "conv_error", fn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1184 done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1185 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
|
1186 done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1187 builder.CreateCondBr (cond, conv_error, normal); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1188 builder.SetInsertPoint (conv_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1189 builder.CreateCall (ginvalid_index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1190 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1191 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1192 builder.SetInsertPoint (normal); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1193 llvm::Value *len = builder.CreateExtractValue (mat, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1194 llvm::ArrayRef<unsigned> (2)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1195 cond0 = builder.CreateICmpSGT (int_idx, len); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1196 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1197 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
|
1198 rcount = builder.CreateLoad (rcount); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1199 cond1 = builder.CreateICmpSGT (rcount, one); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1200 cond = builder.CreateOr (cond0, cond1); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1201 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1202 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
|
1203 "bounds_error", |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1204 fn, done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1205 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1206 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
|
1207 fn, done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1208 builder.CreateCondBr (cond, bounds_error, success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1209 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1210 // resize on out of bounds access |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1211 builder.SetInsertPoint (bounds_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1212 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
|
1213 builder.CreateStore (mat, resize_result); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1214 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
|
1215 resize_result = builder.CreateLoad (resize_result); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1216 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1217 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1218 builder.SetInsertPoint (success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1219 llvm::Value *data = builder.CreateExtractValue (mat, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1220 llvm::ArrayRef<unsigned> (1)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1221 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
|
1222 builder.CreateStore (value, gep); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1223 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1224 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1225 builder.SetInsertPoint (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1226 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1227 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
|
1228 builder.Insert (merge); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1229 merge->addIncoming (mat, conv_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1230 merge->addIncoming (resize_result, bounds_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1231 merge->addIncoming (mat, success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1232 builder.CreateRet (merge); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1233 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1234 llvm::verifyFunction (*fn); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1235 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
|
1236 |
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
|
1237 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
|
1238 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
|
1239 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
|
1240 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
|
1241 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
|
1242 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
|
1243 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1244 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
|
1245 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
|
1246 casts[complex->type_id ()].stash_name ("(complex)"); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1247 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
|
1248 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1249 // cast any <- matrix |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1250 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
|
1251 matrix_t->getPointerTo ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1252 engine->addGlobalMapping (fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1253 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
|
1254 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
|
1255 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1256 // cast matrix <- any |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1257 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
|
1258 matrix_t->getPointerTo (), any_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1259 engine->addGlobalMapping (fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1260 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
|
1261 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
|
1262 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1263 // cast any <- scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1264 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
|
1265 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_any_scalar)); |
14945 | 1266 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
|
1267 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1268 // cast scalar <- any |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1269 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
|
1270 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_scalar_any)); |
14945 | 1271 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
|
1272 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1273 // cast any <- complex |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1274 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
|
1275 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
|
1276 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
|
1277 |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1278 // cast complex <- any |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1279 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
|
1280 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
|
1281 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
|
1282 any); |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1283 |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1284 // cast complex <- scalar |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1285 fn = create_function ("octave_jit_cast_complex_scalar", complex, scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1286 body = llvm::BasicBlock::Create (context, "body", fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1287 builder.SetInsertPoint (body); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1288 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1289 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1290 builder.CreateRet (complex_new (fn->arg_begin (), zero)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1291 llvm::verifyFunction (*fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1292 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1293 casts[complex->type_id ()].add_overload (fn, false, complex, scalar); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1294 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1295 // cast scalar <- complex |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1296 fn = create_function ("octave_jit_cast_scalar_complex", scalar, complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1297 body = llvm::BasicBlock::Create (context, "body", fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1298 builder.SetInsertPoint (body); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1299 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1300 builder.CreateRet (complex_real (fn->arg_begin ())); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1301 llvm::verifyFunction (*fn); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1302 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1303 casts[scalar->type_id ()].add_overload (fn, false, scalar, complex); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1304 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1305 // cast any <- any |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1306 fn = create_identity (any); |
14945 | 1307 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
|
1308 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1309 // cast scalar <- scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1310 fn = create_identity (scalar); |
14945 | 1311 casts[scalar->type_id ()].add_overload (fn, false, scalar, scalar); |
14973 | 1312 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1313 // cast complex <- complex |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1314 fn = create_identity (complex); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1315 casts[complex->type_id ()].add_overload (fn, false, complex, complex); |
14973 | 1316 |
1317 // -------------------- builtin functions -------------------- | |
14986
70ff15b6d996
Ignore unkonwn functions during compilation
Max Brister <max@2bass.com>
parents:
14985
diff
changeset
|
1318 add_builtin ("#unknown_function"); |
70ff15b6d996
Ignore unkonwn functions during compilation
Max Brister <max@2bass.com>
parents:
14985
diff
changeset
|
1319 unknown_function = builtins["#unknown_function"]; |
70ff15b6d996
Ignore unkonwn functions during compilation
Max Brister <max@2bass.com>
parents:
14985
diff
changeset
|
1320 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1321 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
|
1322 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
|
1323 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
|
1324 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1325 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
|
1326 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
|
1327 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
|
1328 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1329 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
|
1330 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
|
1331 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
|
1332 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1333 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
|
1334 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
|
1335 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
|
1336 iter != builtins.end (); ++iter) |
14973 | 1337 { |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1338 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
|
1339 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
|
1340 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
|
1341 casts[btype->type_id ()].add_overload (fn, false, btype, any); |
14973 | 1342 } |
14903 | 1343 } |
1344 | |
1345 void | |
1346 jit_typeinfo::add_print (jit_type *ty, void *call) | |
1347 { | |
1348 std::stringstream name; | |
1349 name << "octave_jit_print_" << ty->name (); | |
1350 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1351 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
|
1352 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
|
1353 llvm::Type::getInt8PtrTy (context), |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1354 ty->to_llvm ()); |
14903 | 1355 engine->addGlobalMapping (fn, call); |
1356 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1357 jit_operation::overload ol (fn, false, 0, string, ty); |
14903 | 1358 print_fn.add_overload (ol); |
1359 } | |
1360 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1361 // FIXME: cp between add_binary_op, add_binary_icmp, and add_binary_fcmp |
14903 | 1362 void |
1363 jit_typeinfo::add_binary_op (jit_type *ty, int op, int llvm_op) | |
1364 { | |
1365 std::stringstream fname; | |
1366 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
1367 fname << "octave_jit_" << octave_value::binary_op_as_string (ov_op) | |
1368 << "_" << ty->name (); | |
14906 | 1369 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1370 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
|
1371 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
|
1372 builder.SetInsertPoint (block); |
14903 | 1373 llvm::Instruction::BinaryOps temp |
1374 = 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
|
1375 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
|
1376 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1377 builder.CreateRet (ret); |
14903 | 1378 llvm::verifyFunction (*fn); |
1379 | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1380 jit_operation::overload ol(fn, false, ty, ty, ty); |
14903 | 1381 binary_ops[op].add_overload (ol); |
1382 } | |
1383 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1384 void |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1385 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
|
1386 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1387 std::stringstream fname; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1388 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
|
1389 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
|
1390 << "_" << ty->name (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1391 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1392 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
|
1393 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
|
1394 builder.SetInsertPoint (block); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1395 llvm::CmpInst::Predicate temp |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1396 = 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
|
1397 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
|
1398 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1399 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1400 llvm::verifyFunction (*fn); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1401 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1402 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
|
1403 binary_ops[op].add_overload (ol); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1404 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1405 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1406 void |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1407 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
|
1408 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1409 std::stringstream fname; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1410 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
|
1411 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
|
1412 << "_" << ty->name (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1413 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1414 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
|
1415 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
|
1416 builder.SetInsertPoint (block); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1417 llvm::CmpInst::Predicate temp |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1418 = 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
|
1419 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
|
1420 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1421 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1422 llvm::verifyFunction (*fn); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1423 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
1424 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
|
1425 binary_ops[op].add_overload (ol); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1426 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1427 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1428 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
|
1429 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
|
1430 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
|
1431 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1432 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
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1438 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
|
1439 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1440 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1441 llvm::Function * |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1442 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
|
1443 const std::vector<llvm::Type *>& args) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1444 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1445 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
|
1446 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
|
1447 llvm::Function::ExternalLinkage, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1448 name, module); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1449 fn->addFnAttr (llvm::Attribute::AlwaysInline); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1450 return fn; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1451 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1452 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1453 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1454 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
|
1455 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1456 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
|
1457 if (id >= identities.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1458 identities.resize (id + 1, 0); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1459 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1460 if (! identities[id]) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1461 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1462 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
|
1463 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
|
1464 builder.SetInsertPoint (body); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1465 builder.CreateRet (fn->arg_begin ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1466 llvm::verifyFunction (*fn); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1467 identities[id] = fn; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1468 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1469 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1470 return identities[id]; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1471 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1472 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1473 llvm::Value * |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1474 jit_typeinfo::do_insert_error_check (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1475 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1476 return builder.CreateLoad (lerror_state); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1477 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1478 |
14974
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1479 void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1480 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
|
1481 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1482 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
|
1483 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
|
1484 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1485 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
|
1486 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
|
1487 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
|
1488 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1489 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1490 void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1491 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
|
1492 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
|
1493 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
|
1494 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1495 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
|
1496 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
|
1497 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
|
1498 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
|
1499 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
|
1500 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1501 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
|
1502 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
|
1503 llvm_args); |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1504 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
|
1505 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
|
1506 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1507 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
|
1508 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
|
1509 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
|
1510 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1511 // 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
|
1512 // 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
|
1513 // 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
|
1514 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
|
1515 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
|
1516 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
|
1517 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1518 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
|
1519 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
|
1520 ++iter; |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1521 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
|
1522 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
|
1523 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1524 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
|
1525 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
|
1526 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
|
1527 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1528 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
|
1529 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1530 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1531 octave_builtin * |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1532 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
|
1533 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1534 // 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
|
1535 // 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
|
1536 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
|
1537 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
|
1538 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1539 |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1540 void |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1541 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
|
1542 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
|
1543 { |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1544 // FIXME: Implement |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1545 } |
e3cd4c9d7ccc
Generalize builtin specification in JIT and add support for cos and exp
Max Brister <max@2bass.com>
parents:
14973
diff
changeset
|
1546 |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1547 llvm::Function * |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1548 jit_typeinfo::mirror_binary (llvm::Function *fn) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1549 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1550 llvm::FunctionType *fn_type = fn->getFunctionType (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1551 llvm::Function *ret = create_function (fn->getName () + "_reverse", |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1552 fn_type->getReturnType (), |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1553 fn_type->getParamType (1), |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1554 fn_type->getParamType (0)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1555 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", ret); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1556 builder.SetInsertPoint (body); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1557 llvm::Value *result = builder.CreateCall2 (fn, ++ret->arg_begin (), |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1558 ret->arg_begin ()); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1559 if (ret->getReturnType () == builder.getVoidTy ()) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1560 builder.CreateRetVoid (); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1561 else |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1562 builder.CreateRet (result); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1563 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1564 llvm::verifyFunction (*ret); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1565 return ret; |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1566 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1567 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1568 llvm::Function * |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1569 jit_typeinfo::wrap_complex (llvm::Function *wrap) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1570 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1571 llvm::SmallVector<llvm::Type *, 5> new_args; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1572 new_args.reserve (wrap->arg_size ()); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1573 llvm::Type *complex_t = complex->to_llvm (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1574 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
|
1575 iter != wrap->arg_end (); ++iter) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1576 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1577 llvm::Value *value = iter; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1578 llvm::Type *type = value->getType (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1579 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
|
1580 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1581 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1582 llvm::FunctionType *wrap_type = wrap->getFunctionType (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1583 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
|
1584 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
|
1585 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
|
1586 llvm::Function *fn = llvm::Function::Create (ft, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1587 llvm::Function::ExternalLinkage, |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1588 wrap->getName () + "_wrap", |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1589 module); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1590 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
|
1591 builder.SetInsertPoint (body); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1592 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1593 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
|
1594 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
|
1595 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
|
1596 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
|
1597 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1598 llvm::Value *warg = witer; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1599 llvm::Value *arg = fiter; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1600 converted[i] = warg->getType () == arg->getType () ? arg |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1601 : pack_complex (arg); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1602 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1603 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1604 llvm::Value *ret = builder.CreateCall (wrap, converted); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1605 if (wrap_type->getReturnType () != builder.getVoidTy ()) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1606 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1607 if (convert_ret) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1608 ret = unpack_complex (ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1609 builder.CreateRet (ret); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1610 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1611 else |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1612 builder.CreateRetVoid (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1613 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1614 llvm::verifyFunction (*fn); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1615 return fn; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1616 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1617 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1618 llvm::Value * |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1619 jit_typeinfo::pack_complex (llvm::Value *cplx) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1620 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1621 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
|
1622 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
|
1623 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
|
1624 ret = builder.CreateInsertValue (ret, real, 0); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1625 return builder.CreateInsertValue (ret, imag, 1); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1626 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1627 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1628 llvm::Value * |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1629 jit_typeinfo::unpack_complex (llvm::Value *result) |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1630 { |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1631 llvm::Type *complex_t = complex->to_llvm (); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1632 llvm::Value *real = builder.CreateExtractValue (result, 0); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1633 llvm::Value *imag = builder.CreateExtractValue (result, 1); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1634 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
|
1635 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
|
1636 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
|
1637 } |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
1638 |
14988
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1639 llvm::Value * |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1640 jit_typeinfo::complex_real (llvm::Value *cx) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1641 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1642 return builder.CreateExtractElement (cx, builder.getInt32 (0)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1643 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1644 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1645 llvm::Value * |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1646 jit_typeinfo::complex_real (llvm::Value *cx, llvm::Value *real) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1647 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1648 return builder.CreateInsertElement (cx, real, builder.getInt32 (0)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1649 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1650 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1651 llvm::Value * |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1652 jit_typeinfo::complex_imag (llvm::Value *cx) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1653 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1654 return builder.CreateExtractElement (cx, builder.getInt32 (1)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1655 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1656 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1657 llvm::Value * |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1658 jit_typeinfo::complex_imag (llvm::Value *cx, llvm::Value *imag) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1659 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1660 return builder.CreateInsertElement (cx, imag, builder.getInt32 (1)); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1661 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1662 |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1663 llvm::Value * |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1664 jit_typeinfo::complex_new (llvm::Value *real, llvm::Value *imag) |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1665 { |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1666 llvm::Value *ret = llvm::UndefValue::get (complex->to_llvm ()); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1667 ret = complex_real (ret, real); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1668 return complex_imag (ret, imag); |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1669 } |
822d52bee973
More support for complex-complex and complex-scalar operations in JIT
Max Brister <max@2bass.com>
parents:
14987
diff
changeset
|
1670 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1671 jit_type * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1672 jit_typeinfo::do_type_of (const octave_value &ov) const |
14903 | 1673 { |
14924 | 1674 if (ov.is_function ()) |
14973 | 1675 { |
1676 // FIXME: This is ugly, we need to finalize how we want to to this, then | |
1677 // have octave_value fully support the needed functionality | |
1678 octave_builtin *builtin | |
1679 = dynamic_cast<octave_builtin *> (ov.internal_rep ()); | |
14986
70ff15b6d996
Ignore unkonwn functions during compilation
Max Brister <max@2bass.com>
parents:
14985
diff
changeset
|
1680 return builtin && builtin->to_jit () ? builtin->to_jit () |
70ff15b6d996
Ignore unkonwn functions during compilation
Max Brister <max@2bass.com>
parents:
14985
diff
changeset
|
1681 : unknown_function; |
14973 | 1682 } |
14903 | 1683 |
14906 | 1684 if (ov.is_range ()) |
1685 return get_range (); | |
1686 | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1687 if (ov.is_double_type ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1688 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1689 if (ov.is_real_scalar ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1690 return get_scalar (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1691 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1692 if (ov.is_matrix_type ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1693 return get_matrix (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1694 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1695 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1696 if (ov.is_complex_scalar ()) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1697 return get_complex (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
1698 |
14903 | 1699 return get_any (); |
1700 } | |
1701 | |
1702 jit_type* | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1703 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
|
1704 llvm::Type *llvm_type) |
14903 | 1705 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1706 jit_type *ret = new jit_type (name, parent, llvm_type, next_id++); |
14903 | 1707 id_to_type.push_back (ret); |
1708 return ret; | |
1709 } | |
1710 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1711 // -------------------- jit_use -------------------- |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1712 jit_block * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1713 jit_use::user_parent (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1714 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1715 return muser->parent (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1716 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1717 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1718 // -------------------- jit_value -------------------- |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1719 jit_value::~jit_value (void) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1720 {} |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1721 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1722 jit_block * |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1723 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
|
1724 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1725 jit_use *use = first_use (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1726 while (use) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1727 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1728 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
|
1729 return use->user_parent (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1730 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1731 use = use->next (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1732 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1733 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1734 return 0; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1735 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
1736 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1737 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1738 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
|
1739 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1740 while (first_use ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1741 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1742 jit_instruction *user = first_use ()->user (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1743 size_t idx = first_use ()->index (); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1744 user->stash_argument (idx, value); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1745 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1746 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1747 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1748 #define JIT_METH(clname) \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1749 void \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1750 jit_ ## clname::accept (jit_ir_walker& walker) \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1751 { \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1752 walker.visit (*this); \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1753 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1754 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1755 JIT_VISIT_IR_NOTEMPLATE |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1756 #undef JIT_METH |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1757 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1758 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1759 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
|
1760 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1761 return value.short_print (os); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1762 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1763 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1764 std::ostream& |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1765 jit_print (std::ostream& os, jit_value *avalue) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1766 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1767 if (avalue) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1768 return avalue->print (os); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1769 return os << "NULL"; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1770 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1771 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1772 // -------------------- jit_instruction -------------------- |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1773 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1774 jit_instruction::remove (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1775 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1776 if (mparent) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1777 mparent->remove (mlocation); |
14945 | 1778 resize_arguments (0); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1779 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1780 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1781 llvm::BasicBlock * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1782 jit_instruction::parent_llvm (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1783 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1784 return mparent->to_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1785 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1786 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1787 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1788 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
|
1789 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1790 if (type ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1791 jit_print (os, type ()) << ": "; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1792 return os << "#" << mid; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1793 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1794 |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1795 void |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1796 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
|
1797 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1798 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
|
1799 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1800 jit_value *arg = argument (i); |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1801 jit_variable *var = dynamic_cast<jit_variable *> (arg); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1802 if (var && var->has_top ()) |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1803 stash_argument (i, var->top ()); |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1804 } |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1805 } |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1806 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1807 // -------------------- jit_block -------------------- |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1808 void |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1809 jit_block::replace_with (jit_value *value) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1810 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1811 assert (isa<jit_block> (value)); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1812 jit_block *block = static_cast<jit_block *> (value); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1813 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1814 jit_value::replace_with (block); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1815 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1816 while (ILIST_T::first_use ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1817 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1818 jit_phi_incomming *incomming = ILIST_T::first_use (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1819 incomming->stash_value (block); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1820 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1821 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1822 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1823 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1824 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
|
1825 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1826 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
|
1827 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
|
1828 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1829 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
|
1830 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
|
1831 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1832 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
|
1833 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
|
1834 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1835 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1836 |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1837 jit_block * |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1838 jit_block::maybe_merge () |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1839 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1840 if (successor_count () == 1 && successor (0) != this |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1841 && (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
|
1842 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1843 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
|
1844 merge (*to_merge); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1845 return to_merge; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1846 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1847 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1848 return 0; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1849 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1850 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1851 void |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1852 jit_block::merge (jit_block& block) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1853 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1854 // 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
|
1855 jit_terminator *old_term = terminator (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1856 if (old_term) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1857 old_term->remove (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1858 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1859 bool was_empty = end () == begin (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1860 iterator merge_begin = end (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1861 if (! was_empty) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1862 --merge_begin; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1863 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1864 instructions.splice (end (), block.instructions); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1865 if (was_empty) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1866 merge_begin = begin (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1867 else |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1868 ++merge_begin; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1869 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1870 // 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
|
1871 // update their parent information |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1872 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
|
1873 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1874 jit_instruction *instr = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1875 instr->stash_parent (this, iter); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1876 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1877 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1878 block.replace_with (this); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1879 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1880 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1881 jit_instruction * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1882 jit_block::prepend (jit_instruction *instr) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1883 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1884 instructions.push_front (instr); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1885 instr->stash_parent (this, instructions.begin ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1886 return instr; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1887 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1888 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1889 jit_instruction * |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1890 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
|
1891 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1892 // FIXME: Make this O(1) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1893 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
|
1894 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1895 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
|
1896 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
|
1897 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1898 insert_before (iter, instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1899 return instr; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1900 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1901 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1902 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1903 return append (instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1904 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1905 |
14945 | 1906 void |
1907 jit_block::internal_append (jit_instruction *instr) | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1908 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1909 instructions.push_back (instr); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1910 instr->stash_parent (this, --instructions.end ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1911 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1912 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1913 jit_instruction * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1914 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
|
1915 { |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1916 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
|
1917 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
|
1918 return instr; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1919 } |
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 jit_instruction * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1922 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
|
1923 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1924 ++loc; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1925 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
|
1926 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
|
1927 return instr; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1928 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1929 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1930 jit_terminator * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1931 jit_block::terminator (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1932 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1933 assert (this); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1934 if (instructions.empty ()) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1935 return 0; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1936 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1937 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
|
1938 return dynamic_cast<jit_terminator *> (last); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1939 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1940 |
14945 | 1941 bool |
1942 jit_block::branch_alive (jit_block *asucc) const | |
1943 { | |
1944 return terminator ()->alive (asucc); | |
1945 } | |
1946 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1947 jit_block * |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1948 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
|
1949 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1950 jit_terminator *term = terminator (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1951 return term->successor (i); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1952 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1953 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1954 size_t |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1955 jit_block::successor_count (void) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1956 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1957 jit_terminator *term = terminator (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1958 return term ? term->successor_count () : 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1959 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1960 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1961 llvm::BasicBlock * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1962 jit_block::to_llvm (void) const |
14903 | 1963 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1964 return llvm::cast<llvm::BasicBlock> (llvm_value); |
14903 | 1965 } |
1966 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1967 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1968 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
|
1969 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1970 short_print (os); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1971 os << ":\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1972 os << " mid: " << mid << std::endl; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1973 os << " predecessors: "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1974 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
|
1975 os << *use->user_parent () << " "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1976 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1977 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1978 os << " successors: "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1979 for (size_t i = 0; i < successor_count (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1980 os << *successor (i) << " "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1981 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1982 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1983 os << " idom: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1984 if (idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1985 os << *idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1986 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1987 os << "NULL"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1988 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1989 os << " df: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1990 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
|
1991 os << **iter << " "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1992 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1993 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1994 os << " dom_succ: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1995 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
|
1996 os << *dom_succ[i] << " "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1997 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1998 return os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1999 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2000 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2001 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2002 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
|
2003 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2004 if (visited (avisit_count)) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2005 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2006 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2007 if (use_count () >= 2) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2008 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2009 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
|
2010 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2011 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
|
2012 while (runner != idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2013 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2014 runner->mdf.insert (this); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2015 runner = runner->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2016 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2017 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2018 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2019 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2020 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
|
2021 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
|
2022 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2023 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2024 bool |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2025 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
|
2026 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2027 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
|
2028 return false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2029 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2030 bool changed = false; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2031 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
|
2032 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2033 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
|
2034 changed = pred->update_idom (avisit_count) || changed; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2035 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2036 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2037 jit_use *use = first_use (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2038 jit_block *new_idom = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2039 use = use->next (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2040 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2041 for (; use; use = use->next ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2042 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2043 jit_block *pred = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2044 jit_block *pidom = pred->idom; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2045 if (pidom) |
14989 | 2046 new_idom = idom_intersect (pidom, new_idom); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2047 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2048 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2049 if (idom != new_idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2050 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2051 idom = new_idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2052 return true; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2053 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2054 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2055 return changed; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2056 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2057 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2058 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2059 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
|
2060 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2061 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
|
2062 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2063 jit_instruction *instr = *iter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2064 instr->pop_variable (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2065 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2066 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2067 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2068 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
|
2069 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
|
2070 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2071 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
|
2072 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2073 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
|
2074 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
|
2075 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
|
2076 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2077 // try to place splits where they make sense |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2078 if (id () < asuccessor->id ()) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2079 convert.insert_before (asuccessor, split); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2080 else |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2081 convert.insert_after (this, split); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2082 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2083 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
|
2084 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
|
2085 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
|
2086 |
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
|
2087 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
|
2088 { |
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
|
2089 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
|
2090 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
|
2091 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2092 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2093 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
|
2094 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2095 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2096 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
|
2097 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2098 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2099 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2100 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
|
2101 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
2102 if (visited (avisit_count)) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2103 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2104 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2105 if (idom != this) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2106 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
|
2107 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2108 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
|
2109 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
|
2110 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2111 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2112 jit_block * |
14989 | 2113 jit_block::idom_intersect (jit_block *i, jit_block *j) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2114 { |
14989 | 2115 while (i && j && i != j) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2116 { |
14989 | 2117 while (i && i->id () > j->id ()) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2118 i = i->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2119 |
14989 | 2120 while (i && j && j->id () > i->id ()) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2121 j = j->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2122 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2123 |
14989 | 2124 return i ? i : j; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2125 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2126 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2127 // -------------------- 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
|
2128 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2129 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
|
2130 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
|
2131 { 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
|
2132 |
14945 | 2133 // -------------------- jit_phi -------------------- |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2134 bool |
14945 | 2135 jit_phi::prune (void) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2136 { |
14945 | 2137 jit_block *p = parent (); |
2138 size_t new_idx = 0; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2139 jit_value *unique = argument (1); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2140 |
14945 | 2141 for (size_t i = 0; i < argument_count (); ++i) |
2142 { | |
2143 jit_block *inc = incomming (i); | |
2144 if (inc->branch_alive (p)) | |
2145 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2146 if (unique != argument (i)) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2147 unique = 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2148 |
14945 | 2149 if (new_idx != i) |
2150 { | |
2151 stash_argument (new_idx, argument (i)); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2152 mincomming[new_idx].stash_value (inc); |
14945 | 2153 } |
2154 | |
2155 ++new_idx; | |
2156 } | |
2157 } | |
2158 | |
2159 if (new_idx != argument_count ()) | |
2160 { | |
2161 resize_arguments (new_idx); | |
2162 mincomming.resize (new_idx); | |
2163 } | |
2164 | |
2165 assert (argument_count () > 0); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2166 if (unique) |
14945 | 2167 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2168 replace_with (unique); |
14945 | 2169 return true; |
2170 } | |
2171 | |
2172 return false; | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2173 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2174 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2175 bool |
14945 | 2176 jit_phi::infer (void) |
2177 { | |
2178 jit_block *p = parent (); | |
2179 if (! p->alive ()) | |
2180 return false; | |
2181 | |
2182 jit_type *infered = 0; | |
2183 for (size_t i = 0; i < argument_count (); ++i) | |
2184 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2185 jit_block *inc = incomming (i); |
14945 | 2186 if (inc->branch_alive (p)) |
2187 infered = jit_typeinfo::join (infered, argument_type (i)); | |
2188 } | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2189 |
14945 | 2190 if (infered != type ()) |
2191 { | |
2192 stash_type (infered); | |
2193 return true; | |
2194 } | |
2195 | |
2196 return false; | |
2197 } | |
2198 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2199 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
|
2200 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
|
2201 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2202 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
|
2203 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2204 |
14945 | 2205 // -------------------- jit_terminator -------------------- |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2206 size_t |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2207 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
|
2208 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2209 size_t scount = successor_count (); |
14945 | 2210 for (size_t i = 0; i < scount; ++i) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2211 if (successor (i) == asuccessor) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2212 return i; |
14945 | 2213 |
2214 panic_impossible (); | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2215 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2216 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2217 bool |
14945 | 2218 jit_terminator::infer (void) |
2219 { | |
2220 if (! parent ()->alive ()) | |
2221 return false; | |
2222 | |
2223 bool changed = false; | |
2224 for (size_t i = 0; i < malive.size (); ++i) | |
2225 if (! malive[i] && check_alive (i)) | |
2226 { | |
2227 changed = true; | |
2228 malive[i] = true; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2229 successor (i)->mark_alive (); |
14945 | 2230 } |
2231 | |
2232 return changed; | |
2233 } | |
2234 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2235 llvm::TerminatorInst * |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2236 jit_terminator::to_llvm (void) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2237 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2238 return llvm::cast<llvm::TerminatorInst> (jit_value::to_llvm ()); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2239 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2240 |
14945 | 2241 // -------------------- jit_call -------------------- |
2242 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2243 jit_call::infer (void) |
14903 | 2244 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2245 // FIXME: explain algorithm |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2246 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
|
2247 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2248 already_infered[i] = argument_type (i); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2249 if (! already_infered[i]) |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2250 return false; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2251 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2252 |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2253 jit_type *infered = mfunction.get_result (already_infered); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2254 if (! infered && use_count ()) |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2255 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2256 std::stringstream ss; |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2257 ss << "Missing overload in type inference for "; |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2258 print (ss, 0); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2259 fail (ss.str ()); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2260 } |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2261 |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2262 if (infered != type ()) |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2263 { |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
2264 stash_type (infered); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2265 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2266 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2267 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2268 return false; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2269 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2270 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2271 // -------------------- jit_convert -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2272 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
|
2273 : 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
|
2274 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2275 jit_instruction::reset_ids (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2276 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2277 entry_block = create<jit_block> ("body"); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2278 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
|
2279 append (entry_block); |
14945 | 2280 entry_block->mark_alive (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2281 block = entry_block; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2282 visit (tee); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2283 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2284 // 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
|
2285 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2286 assert (breaks.empty ()); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2287 assert (continues.empty ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2288 |
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
|
2289 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
|
2290 append (final_block); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2291 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2292 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
|
2293 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2294 jit_variable *var = iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2295 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
|
2296 if (name.size () && name[0] != '#') |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2297 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
|
2298 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2299 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2300 construct_ssa (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2301 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2302 // 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
|
2303 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
|
2304 iter != constants.end (); ++iter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2305 append_users (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2306 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2307 // FIXME: Describe algorithm here |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2308 while (worklist.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2309 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2310 jit_instruction *next = worklist.front (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2311 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
|
2312 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
|
2313 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2314 if (next->infer ()) |
14945 | 2315 { |
2316 // terminators need to be handles specially | |
2317 if (jit_terminator *term = dynamic_cast<jit_terminator *> (next)) | |
2318 append_users_term (term); | |
2319 else | |
2320 append_users (next); | |
2321 } | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2322 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2323 |
14945 | 2324 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
|
2325 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
|
2326 final_block->label (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2327 place_releases (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2328 simplify_phi (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2329 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2330 #ifdef OCTAVE_JIT_DEBUG |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2331 final_block->label (); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2332 std::cout << "-------------------- Compiling tree --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2333 std::cout << tee.str_print_code () << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2334 print_blocks ("octave jit ir"); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2335 #endif |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2336 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2337 // 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
|
2338 // more interesting |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2339 for (jit_block::iterator iter = entry_block->begin (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2340 iter != entry_block->end (); ++iter) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2341 if (jit_extract_argument *extract |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2342 = 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
|
2343 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
|
2344 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2345 convert_llvm to_llvm (*this); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2346 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
|
2347 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2348 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2349 std::cout << "-------------------- llvm ir --------------------"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2350 llvm::raw_os_ostream llvm_cout (std::cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2351 function->print (llvm_cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2352 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2353 llvm::verifyFunction (*function); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
2354 #endif |
14906 | 2355 } |
2356 | |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2357 jit_convert::~jit_convert (void) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2358 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2359 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
|
2360 iter != all_values.end (); ++iter) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2361 delete *iter; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2362 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2363 |
14906 | 2364 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2365 jit_convert::visit_anon_fcn_handle (tree_anon_fcn_handle&) |
14903 | 2366 { |
2367 fail (); | |
2368 } | |
2369 | |
2370 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2371 jit_convert::visit_argument_list (tree_argument_list&) |
14903 | 2372 { |
2373 fail (); | |
2374 } | |
2375 | |
2376 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2377 jit_convert::visit_binary_expression (tree_binary_expression& be) |
14903 | 2378 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2379 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
|
2380 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2381 tree_boolean_expression *boole; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2382 boole = dynamic_cast<tree_boolean_expression *> (&be); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2383 assert (boole); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2384 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
|
2385 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2386 std::stringstream ss; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2387 ss << "#short_result" << short_count++; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2388 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2389 std::string short_name = ss.str (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2390 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
|
2391 vmap[short_name] = short_result; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2392 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2393 jit_block *done = create<jit_block> (block->name ()); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2394 tree_expression *lhs = be.lhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2395 jit_value *lhsv = visit (lhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2396 lhsv = create_checked (&jit_typeinfo::logically_true, lhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2397 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2398 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
|
2399 append (short_early); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2400 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2401 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
|
2402 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2403 if (is_and) |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2404 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
|
2405 else |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2406 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
|
2407 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2408 block = short_early; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2409 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2410 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
|
2411 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
|
2412 block->append (create<jit_branch> (done)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2413 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2414 append (short_cont); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2415 block = short_cont; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2416 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2417 tree_expression *rhs = be.rhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2418 jit_value *rhsv = visit (rhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2419 rhsv = create_checked (&jit_typeinfo::logically_true, rhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2420 block->append (create<jit_assign> (short_result, rhsv)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2421 block->append (create<jit_branch> (done)); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2422 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2423 append (done); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2424 block = done; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2425 result = short_result; |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2426 } |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2427 else |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2428 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2429 tree_expression *lhs = be.lhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2430 jit_value *lhsv = visit (lhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2431 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2432 tree_expression *rhs = be.rhs (); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2433 jit_value *rhsv = visit (rhs); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2434 |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2435 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
|
2436 result = create_checked (fn, lhsv, rhsv); |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2437 } |
14903 | 2438 } |
2439 | |
2440 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2441 jit_convert::visit_break_command (tree_break_command&) |
14903 | 2442 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2443 breaks.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2444 breaking = true; |
14903 | 2445 } |
2446 | |
2447 void | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2448 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
|
2449 { |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2450 // 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
|
2451 jit_value *base = visit (expr.base ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2452 jit_value *limit = visit (expr.limit ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2453 jit_value *increment; |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2454 tree_expression *tinc = expr.increment (); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2455 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2456 if (tinc) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2457 increment = visit (tinc); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2458 else |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2459 increment = create<jit_const_scalar> (1); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2460 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
2461 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
|
2462 limit, increment)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2463 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2464 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2465 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2466 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
|
2467 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2468 continues.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2469 breaking = true; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2470 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2471 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2472 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2473 jit_convert::visit_global_command (tree_global_command&) |
14903 | 2474 { |
2475 fail (); | |
2476 } | |
2477 | |
2478 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2479 jit_convert::visit_persistent_command (tree_persistent_command&) |
14903 | 2480 { |
2481 fail (); | |
2482 } | |
2483 | |
2484 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2485 jit_convert::visit_decl_elt (tree_decl_elt&) |
14903 | 2486 { |
2487 fail (); | |
2488 } | |
2489 | |
2490 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2491 jit_convert::visit_decl_init_list (tree_decl_init_list&) |
14903 | 2492 { |
2493 fail (); | |
2494 } | |
2495 | |
2496 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2497 jit_convert::visit_simple_for_command (tree_simple_for_command& cmd) |
14903 | 2498 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2499 // 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
|
2500 // 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
|
2501 // 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
|
2502 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2503 // 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
|
2504 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2505 unwind_protect prot; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2506 prot.protect_var (breaks); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2507 prot.protect_var (continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2508 prot.protect_var (breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2509 breaks.clear (); |
14989 | 2510 continues.clear (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2511 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2512 // 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
|
2513 std::stringstream ss; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2514 ss << "#iter" << iterator_count++; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2515 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
|
2516 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
|
2517 vmap[iter_name] = iterator; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2518 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2519 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
|
2520 append (body); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2521 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2522 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
|
2523 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2524 // 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
|
2525 jit_value *control = visit (cmd.control_expr ()); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2526 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
|
2527 block->append (init_iter); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2528 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
|
2529 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2530 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
|
2531 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
|
2532 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
|
2533 block = body; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2534 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2535 // compute the syntactical iterator |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2536 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
|
2537 iterator); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2538 block->append (idx_rhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2539 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
|
2540 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2541 // do loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2542 tree_statement_list *pt_body = cmd.body (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2543 pt_body->accept (*this); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2544 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2545 if (breaking && continues.empty ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2546 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2547 // 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
|
2548 // 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
|
2549 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
|
2550 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2551 block = tail; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2552 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2553 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2554 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2555 // 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
|
2556 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
|
2557 append (check_block); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2558 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2559 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
|
2560 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
|
2561 finish_breaks (check_block, continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2562 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2563 block = check_block; |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2564 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
|
2565 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
|
2566 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
|
2567 block->append (iter_inc); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2568 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
|
2569 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
|
2570 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
|
2571 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
|
2572 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2573 // 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
|
2574 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2575 finish_breaks (tail, breaks); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2576 block = tail; |
14903 | 2577 } |
2578 | |
2579 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2580 jit_convert::visit_complex_for_command (tree_complex_for_command&) |
14903 | 2581 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2582 fail (); |
14903 | 2583 } |
2584 | |
2585 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2586 jit_convert::visit_octave_user_script (octave_user_script&) |
14903 | 2587 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2588 fail (); |
14903 | 2589 } |
2590 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
2591 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2592 jit_convert::visit_octave_user_function (octave_user_function&) |
14903 | 2593 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2594 fail (); |
14899 | 2595 } |
2596 | |
14903 | 2597 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2598 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
|
2599 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2600 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2601 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2602 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2603 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2604 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
|
2605 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2606 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2607 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2608 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2609 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2610 jit_convert::visit_function_def (tree_function_def&) |
14899 | 2611 { |
14903 | 2612 fail (); |
2613 } | |
14899 | 2614 |
14903 | 2615 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2616 jit_convert::visit_identifier (tree_identifier& ti) |
14903 | 2617 { |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2618 result = get_variable (ti.name ()); |
14899 | 2619 } |
2620 | |
2621 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2622 jit_convert::visit_if_clause (tree_if_clause&) |
14903 | 2623 { |
2624 fail (); | |
14899 | 2625 } |
2626 | |
2627 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2628 jit_convert::visit_if_command (tree_if_command& cmd) |
14903 | 2629 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2630 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
|
2631 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
|
2632 lst->accept (*this); |
14903 | 2633 } |
2634 | |
2635 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2636 jit_convert::visit_if_command_list (tree_if_command_list& lst) |
14903 | 2637 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2638 tree_if_clause *last = lst.back (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2639 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
|
2640 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2641 // 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
|
2642 // 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
|
2643 // 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
|
2644 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
|
2645 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
|
2646 entry_blocks[0] = block; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2647 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2648 // 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
|
2649 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
|
2650 ++iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2651 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
|
2652 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2653 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2654 if (tic->is_else_clause ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2655 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
|
2656 else |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2657 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
|
2658 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2659 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2660 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
|
2661 if (! last_else) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2662 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
|
2663 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2664 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
|
2665 iter = lst.begin (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2666 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
|
2667 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2668 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2669 block = entry_blocks[i]; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2670 assert (block); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2671 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2672 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
|
2673 append (entry_blocks[i]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2674 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2675 if (! tic->is_else_clause ()) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2676 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2677 tree_expression *expr = tic->condition (); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2678 jit_value *cond = visit (expr); |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
2679 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
|
2680 cond); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2681 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
|
2682 : "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
|
2683 append (body); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2684 |
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
|
2685 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
|
2686 entry_blocks[i + 1]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2687 block->append (br); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2688 block = body; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2689 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2690 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2691 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
|
2692 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
|
2693 stmt_lst->accept (*this); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2694 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2695 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2696 breaking = false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2697 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2698 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2699 ++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
|
2700 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
|
2701 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2702 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2703 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2704 if (num_incomming || ! last_else) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2705 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2706 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2707 block = tail; |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2708 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2709 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2710 // 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
|
2711 breaking = true; |
14903 | 2712 } |
2713 | |
2714 void | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2715 jit_convert::visit_index_expression (tree_index_expression& exp) |
14903 | 2716 { |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2717 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
|
2718 jit_value *object = res.first; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2719 jit_value *index = res.second; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2720 |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
2721 result = create_checked (jit_typeinfo::paren_subsref, object, index); |
14903 | 2722 } |
2723 | |
2724 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2725 jit_convert::visit_matrix (tree_matrix&) |
14899 | 2726 { |
2727 fail (); | |
2728 } | |
2729 | |
2730 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2731 jit_convert::visit_cell (tree_cell&) |
14906 | 2732 { |
2733 fail (); | |
2734 } | |
2735 | |
2736 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2737 jit_convert::visit_multi_assignment (tree_multi_assignment&) |
14899 | 2738 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2739 fail (); |
14903 | 2740 } |
2741 | |
2742 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2743 jit_convert::visit_no_op_command (tree_no_op_command&) |
14906 | 2744 { |
2745 fail (); | |
2746 } | |
2747 | |
2748 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2749 jit_convert::visit_constant (tree_constant& tc) |
14903 | 2750 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2751 octave_value v = tc.rvalue1 (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2752 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
|
2753 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2754 double dv = v.double_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2755 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
|
2756 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2757 else if (v.is_range ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2758 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2759 Range rv = v.range_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2760 result = create<jit_const_range> (rv); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2761 } |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2762 else if (v.is_complex_scalar ()) |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2763 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2764 Complex cv = v.complex_value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2765 result = create<jit_const_complex> (cv); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
2766 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2767 else |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2768 fail ("Unknown constant"); |
14903 | 2769 } |
14899 | 2770 |
14903 | 2771 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2772 jit_convert::visit_fcn_handle (tree_fcn_handle&) |
14903 | 2773 { |
2774 fail (); | |
2775 } | |
14899 | 2776 |
14903 | 2777 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2778 jit_convert::visit_parameter_list (tree_parameter_list&) |
14906 | 2779 { |
2780 fail (); | |
2781 } | |
2782 | |
2783 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2784 jit_convert::visit_postfix_expression (tree_postfix_expression&) |
14903 | 2785 { |
2786 fail (); | |
2787 } | |
14899 | 2788 |
14903 | 2789 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2790 jit_convert::visit_prefix_expression (tree_prefix_expression&) |
14899 | 2791 { |
2792 fail (); | |
2793 } | |
2794 | |
2795 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2796 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
|
2797 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2798 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2799 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2800 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2801 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2802 jit_convert::visit_return_list (tree_return_list&) |
14899 | 2803 { |
2804 fail (); | |
2805 } | |
2806 | |
2807 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2808 jit_convert::visit_simple_assignment (tree_simple_assignment& tsa) |
14899 | 2809 { |
14953 | 2810 if (tsa.op_type () != octave_value::op_asn_eq) |
2811 fail ("Unsupported assign"); | |
2812 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2813 // resolve rhs |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2814 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
|
2815 jit_value *rhsv = visit (rhs); |
14899 | 2816 |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
2817 result = do_assign (tsa.left_hand_side (), rhsv); |
14899 | 2818 } |
2819 | |
2820 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2821 jit_convert::visit_statement (tree_statement& stmt) |
14899 | 2822 { |
2823 tree_command *cmd = stmt.command (); | |
2824 tree_expression *expr = stmt.expression (); | |
2825 | |
2826 if (cmd) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2827 visit (cmd); |
14899 | 2828 else |
2829 { | |
2830 // stolen from tree_evaluator::visit_statement | |
2831 bool do_bind_ans = false; | |
2832 | |
2833 if (expr->is_identifier ()) | |
2834 { | |
2835 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
2836 | |
2837 do_bind_ans = (! id->is_variable ()); | |
2838 } | |
2839 else | |
2840 do_bind_ans = (! expr->is_assignment_expression ()); | |
2841 | |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2842 jit_value *expr_result = visit (expr); |
14899 | 2843 |
2844 if (do_bind_ans) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2845 do_assign ("ans", expr_result, expr->print_result ()); |
14899 | 2846 else if (expr->is_identifier () && expr->print_result ()) |
2847 { | |
2848 // FIXME: ugly hack, we need to come up with a way to pass | |
2849 // nargout to visit_identifier | |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
2850 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
|
2851 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
|
2852 block->append (create<jit_call> (fn, name, expr_result)); |
14899 | 2853 } |
2854 } | |
2855 } | |
2856 | |
2857 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2858 jit_convert::visit_statement_list (tree_statement_list& lst) |
14906 | 2859 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2860 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
|
2861 ++iter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2862 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2863 tree_statement *elt = *iter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2864 // jwe: Can this ever be null? |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2865 assert (elt); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2866 elt->accept (*this); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2867 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2868 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2869 break; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2870 } |
14906 | 2871 } |
2872 | |
2873 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2874 jit_convert::visit_switch_case (tree_switch_case&) |
14906 | 2875 { |
2876 fail (); | |
2877 } | |
2878 | |
2879 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2880 jit_convert::visit_switch_case_list (tree_switch_case_list&) |
14899 | 2881 { |
2882 fail (); | |
2883 } | |
2884 | |
2885 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2886 jit_convert::visit_switch_command (tree_switch_command&) |
14906 | 2887 { |
2888 fail (); | |
2889 } | |
2890 | |
2891 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2892 jit_convert::visit_try_catch_command (tree_try_catch_command&) |
14899 | 2893 { |
2894 fail (); | |
2895 } | |
2896 | |
2897 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2898 jit_convert::visit_unwind_protect_command (tree_unwind_protect_command&) |
14899 | 2899 { |
2900 fail (); | |
2901 } | |
2902 | |
2903 void | |
14989 | 2904 jit_convert::visit_while_command (tree_while_command& wc) |
14906 | 2905 { |
14989 | 2906 assert (! breaking); |
2907 unwind_protect prot; | |
2908 prot.protect_var (breaks); | |
2909 prot.protect_var (continues); | |
2910 prot.protect_var (breaking); | |
2911 breaks.clear (); | |
2912 continues.clear (); | |
2913 | |
2914 jit_block *cond_check = create<jit_block> ("while_cond_check"); | |
2915 block->append (create<jit_branch> (cond_check)); | |
2916 append (cond_check); | |
2917 block = cond_check; | |
2918 | |
2919 tree_expression *expr = wc.condition (); | |
2920 assert (expr && "While expression can not be null"); | |
2921 jit_value *check = visit (expr); | |
2922 check = create_checked (&jit_typeinfo::logically_true, check); | |
2923 | |
2924 jit_block *body = create<jit_block> ("while_body"); | |
2925 append (body); | |
2926 | |
2927 jit_block *tail = create<jit_block> ("while_tail"); | |
2928 block->append (create<jit_cond_branch> (check, body, tail)); | |
2929 block = body; | |
2930 | |
2931 tree_statement_list *loop_body = wc.body (); | |
2932 if (loop_body) | |
2933 loop_body->accept (*this); | |
2934 | |
2935 finish_breaks (tail, breaks); | |
2936 finish_breaks (cond_check, continues); | |
2937 | |
2938 if (! breaking) | |
2939 block->append (create<jit_branch> (cond_check)); | |
2940 | |
2941 append (tail); | |
2942 block = tail; | |
14906 | 2943 } |
2944 | |
2945 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2946 jit_convert::visit_do_until_command (tree_do_until_command&) |
14899 | 2947 { |
2948 fail (); | |
2949 } | |
2950 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2951 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2952 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
|
2953 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2954 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
|
2955 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
|
2956 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2957 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2958 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2959 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
|
2960 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2961 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
|
2962 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
|
2963 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2964 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2965 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2966 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
|
2967 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2968 ++iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2969 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
|
2970 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2971 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2972 jit_variable * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2973 jit_convert::get_variable (const std::string& vname) |
14899 | 2974 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2975 vmap_t::iterator iter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2976 iter = vmap.find (vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2977 if (iter != vmap.end ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2978 return iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2979 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2980 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
|
2981 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
|
2982 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
|
2983 jit_extract_argument *extract; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2984 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
|
2985 entry_block->prepend (extract); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2986 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2987 return vmap[vname] = var; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2988 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2989 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2990 std::pair<jit_value *, jit_value *> |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2991 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
|
2992 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2993 std::string type = exp.type_tags (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2994 if (! (type.size () == 1 && type[0] == '(')) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2995 fail ("Unsupported index operation"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2996 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2997 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
|
2998 if (args.size () != 1) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2999 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
|
3000 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3001 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
|
3002 if (! arg_list) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3003 fail ("null argument list"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3004 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3005 if (arg_list->size () != 1) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3006 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
|
3007 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3008 tree_expression *tree_object = exp.expression (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3009 jit_value *object = visit (tree_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3010 tree_expression *arg0 = arg_list->front (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3011 jit_value *index = visit (arg0); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3012 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3013 return std::make_pair (object, index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3014 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3015 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3016 jit_value * |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3017 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
|
3018 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3019 if (! exp) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3020 fail ("NULL lhs in assign"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3021 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3022 if (isa<tree_identifier> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3023 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
|
3024 else if (tree_index_expression *idx |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3025 = dynamic_cast<tree_index_expression *> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3026 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3027 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
|
3028 jit_value *object = res.first; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3029 jit_value *index = res.second; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3030 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
|
3031 object, index, rhs); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3032 block->append (new_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3033 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
|
3034 create_check (new_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3035 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3036 // 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
|
3037 return rhs; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3038 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3039 else |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3040 fail ("Unsupported assignment"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3041 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3042 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3043 jit_value * |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3044 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
|
3045 bool print, bool artificial) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3046 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3047 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
|
3048 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
|
3049 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3050 if (artificial) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3051 assign->mark_artificial (); |
14906 | 3052 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3053 if (print) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3054 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3055 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
|
3056 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
|
3057 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
|
3058 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3059 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3060 return var; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3061 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3062 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3063 jit_value * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3064 jit_convert::visit (tree& tee) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3065 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3066 result = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3067 tee.accept (*this); |
14906 | 3068 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3069 jit_value *ret = result; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3070 result = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3071 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3072 } |
14906 | 3073 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3074 void |
14945 | 3075 jit_convert::append_users_term (jit_terminator *term) |
3076 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3077 for (size_t i = 0; i < term->successor_count (); ++i) |
14945 | 3078 { |
3079 if (term->alive (i)) | |
3080 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3081 jit_block *succ = term->successor (i); |
14945 | 3082 for (jit_block::iterator iter = succ->begin (); iter != succ->end () |
3083 && 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
|
3084 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
|
3085 |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
3086 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
|
3087 if (sterm) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
3088 push_worklist (sterm); |
14945 | 3089 } |
3090 } | |
3091 } | |
3092 | |
3093 void | |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3094 jit_convert::merge_blocks (void) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3095 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3096 std::vector<jit_block *> dead; |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3097 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
|
3098 ++iter) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3099 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3100 jit_block *b = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3101 jit_block *merged = b->maybe_merge (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3102 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3103 if (merged) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3104 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3105 if (merged == final_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3106 final_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3107 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3108 if (merged == entry_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3109 entry_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3110 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3111 dead.push_back (merged); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3112 } |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3113 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3114 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3115 for (size_t i = 0; i < dead.size (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3116 blocks.erase (dead[i]->location ()); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3117 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3118 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3119 void |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3120 jit_convert::construct_ssa (void) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3121 { |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3122 merge_blocks (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3123 final_block->label (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
3124 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
|
3125 entry_block->compute_df (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3126 entry_block->create_dom_tree (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3127 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3128 // 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
|
3129 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
|
3130 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3131 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
|
3132 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
|
3133 iter->second->use_blocks (visited); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3134 ssa_worklist.insert (ssa_worklist.begin (), visited.begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3135 visited.end ()); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
3136 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3137 while (ssa_worklist.size ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3138 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3139 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
|
3140 ssa_worklist.pop_front (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3141 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3142 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
|
3143 diter != b->df_end (); ++diter) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
3144 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3145 jit_block *dblock = *diter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3146 if (! added_phi.count (dblock)) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
3147 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3148 jit_phi *phi = create<jit_phi> (iter->second, |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3149 dblock->use_count ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3150 dblock->prepend (phi); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3151 added_phi.insert (dblock); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
3152 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
3153 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3154 if (! visited.count (dblock)) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3155 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3156 ssa_worklist.push_back (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3157 visited.insert (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3158 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
3159 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3160 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3161 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3162 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3163 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
|
3164 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3165 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3166 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3167 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
|
3168 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3169 if (ablock.visited (avisit_count)) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3170 return; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3171 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3172 // 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
|
3173 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
|
3174 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3175 jit_instruction *instr = *iter; |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3176 instr->construct_ssa (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3177 instr->push_variable (); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3178 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3179 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3180 // 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
|
3181 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
|
3182 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3183 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
|
3184 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3185 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
|
3186 && isa<jit_phi> (*iter);) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3187 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3188 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
|
3189 jit_variable *var = phi->dest (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3190 if (var->has_top ()) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3191 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3192 phi->add_incomming (&ablock, var->top ()); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3193 ++iter; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3194 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3195 else |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3196 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3197 // 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
|
3198 assert (! phi->use_count ()); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3199 assert (var->name ().size () && var->name ()[0] == '#'); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3200 iter = finish->remove (iter); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3201 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3202 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3203 } |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3204 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3205 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
|
3206 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
|
3207 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3208 ablock.pop_all (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3209 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3210 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3211 void |
14945 | 3212 jit_convert::remove_dead () |
3213 { | |
3214 block_list::iterator biter; | |
3215 for (biter = blocks.begin (); biter != blocks.end (); ++biter) | |
3216 { | |
3217 jit_block *b = *biter; | |
3218 if (b->alive ()) | |
3219 { | |
3220 for (jit_block::iterator iter = b->begin (); iter != b->end () | |
3221 && isa<jit_phi> (*iter);) | |
3222 { | |
3223 jit_phi *phi = static_cast<jit_phi *> (*iter); | |
3224 if (phi->prune ()) | |
3225 iter = b->remove (iter); | |
3226 else | |
3227 ++iter; | |
3228 } | |
3229 } | |
3230 } | |
3231 | |
3232 for (biter = blocks.begin (); biter != blocks.end ();) | |
3233 { | |
3234 jit_block *b = *biter; | |
3235 if (b->alive ()) | |
3236 { | |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
3237 // FIXME: A special case for jit_error_check, if we generalize to |
14945 | 3238 // we will need to change! |
3239 jit_terminator *term = b->terminator (); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3240 if (term && term->successor_count () == 2 && ! term->alive (0)) |
14945 | 3241 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3242 jit_block *succ = term->successor (1); |
14945 | 3243 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
|
3244 jit_branch *abreak = b->append (create<jit_branch> (succ)); |
14945 | 3245 abreak->infer (); |
3246 } | |
3247 | |
3248 ++biter; | |
3249 } | |
3250 else | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3251 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3252 jit_terminator *term = b->terminator (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3253 if (term) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3254 term->remove (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3255 biter = blocks.erase (biter); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3256 } |
14945 | 3257 } |
3258 } | |
3259 | |
3260 void | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3261 jit_convert::place_releases (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3262 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3263 std::set<jit_value *> temporaries; |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3264 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
|
3265 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3266 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3267 jit_block& ablock = **iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3268 if (ablock.id () != jit_block::NO_ID) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3269 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3270 release_temp (ablock, temporaries); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3271 release_dead_phi (ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3272 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3273 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3274 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3275 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3276 void |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3277 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
|
3278 { |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3279 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
|
3280 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3281 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3282 jit_instruction *instr = *iter; |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3283 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3284 // 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
|
3285 // multiple blocks |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3286 if (instr->needs_release ()) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3287 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3288 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
|
3289 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
|
3290 temp.insert (instr); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3291 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3292 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3293 if (isa<jit_call> (instr)) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3294 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3295 // place releases for temporary arguments |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3296 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
|
3297 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3298 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
|
3299 if (arg->needs_release ()) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3300 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3301 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
|
3302 arg); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3303 release->infer (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3304 ablock.insert_after (iter, release); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3305 ++iter; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3306 temp.erase (arg); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3307 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3308 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3309 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3310 } |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3311 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3312 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
|
3313 return; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3314 |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3315 // 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
|
3316 // destination |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3317 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
|
3318 jit_terminator *term = split->terminator (); |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3319 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
|
3320 iter != temp.end (); ++iter) |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3321 { |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3322 jit_value *value = *iter; |
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
3323 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
|
3324 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3325 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3326 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3327 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3328 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3329 void |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3330 jit_convert::release_dead_phi (jit_block& ablock) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3331 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3332 jit_block::iterator iter = ablock.begin (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3333 while (iter != ablock.end () && isa<jit_phi> (*iter)) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3334 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3335 jit_phi *phi = static_cast<jit_phi *> (*iter); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3336 ++iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3337 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3338 jit_use *use = phi->first_use (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3339 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
|
3340 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3341 // 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
|
3342 // this can get rid of casts inside loops |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3343 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
|
3344 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3345 jit_value *arg = phi->argument (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3346 jit_block *inc = phi->incomming (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3347 jit_block *split = inc->maybe_split (*this, ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3348 jit_terminator *term = split->terminator (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3349 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
|
3350 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3351 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3352 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3353 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3354 phi->replace_with (0); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3355 phi->remove (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3356 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3357 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3358 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3359 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3360 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3361 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
|
3362 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3363 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
|
3364 ++biter) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3365 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3366 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
|
3367 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
|
3368 && 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
|
3369 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
|
3370 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3371 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3372 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3373 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3374 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
|
3375 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3376 jit_block& pblock = *phi.parent (); |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3377 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
|
3378 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
|
3379 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
|
3380 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3381 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
|
3382 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
|
3383 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3384 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
|
3385 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
|
3386 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
|
3387 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
|
3388 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
|
3389 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3390 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
|
3391 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
|
3392 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
|
3393 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
|
3394 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
|
3395 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3396 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3397 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3398 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3399 void |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3400 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
|
3401 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3402 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
|
3403 ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3404 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3405 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
|
3406 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
|
3407 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3408 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3409 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3410 // -------------------- jit_convert::convert_llvm -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3411 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3412 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
|
3413 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
|
3414 const std::list<jit_block *>& blocks, |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3415 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
|
3416 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3417 jit_type *any = jit_typeinfo::get_any (); |
14899 | 3418 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3419 // 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
|
3420 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
|
3421 arg_type = arg_type->getPointerTo (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3422 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
|
3423 arg_type, false); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3424 function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3425 "foobar", module); |
14906 | 3426 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3427 try |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3428 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3429 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
|
3430 builder.SetInsertPoint (prelude); |
14906 | 3431 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3432 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
|
3433 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
|
3434 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3435 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
|
3436 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
|
3437 } |
14906 | 3438 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3439 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
|
3440 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
|
3441 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3442 jit_block *jblock = *biter; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3443 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3444 jblock->name (), |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3445 function); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3446 jblock->stash_llvm (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3447 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3448 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3449 jit_block *first = *blocks.begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3450 builder.CreateBr (first->to_llvm ()); |
14906 | 3451 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3452 // 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
|
3453 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
|
3454 iter != constants.end (); ++iter) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3455 if (! isa<jit_instruction> (*iter)) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3456 visit (*iter); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
3457 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3458 // convert all instructions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3459 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
|
3460 visit (*biter); |
14906 | 3461 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3462 // now finish phi nodes |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3463 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3464 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3465 jit_block& block = **biter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3466 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
|
3467 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
|
3468 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3469 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
|
3470 finish_phi (static_cast<jit_phi *> (phi)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3471 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3472 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3473 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3474 jit_block *last = blocks.back (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3475 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
|
3476 builder.CreateRetVoid (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3477 } 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
|
3478 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3479 function->eraseFromParent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3480 throw; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3481 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3482 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3483 return function; |
14899 | 3484 } |
3485 | |
3486 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
|
3487 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
|
3488 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3489 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
|
3490 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
|
3491 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
3492 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
|
3493 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
|
3494 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3495 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3496 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
3497 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3498 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
|
3499 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3500 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
|
3501 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3502 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3503 void |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3504 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
|
3505 { |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3506 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
|
3507 } |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3508 |
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14977
diff
changeset
|
3509 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3510 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
|
3511 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3512 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
|
3513 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3514 |
14984
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3515 void |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3516 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
|
3517 { |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3518 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
|
3519 llvm::Constant *values[2]; |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3520 Complex value = cc.value (); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3521 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
|
3522 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
|
3523 cc.stash_llvm (llvm::ConstantVector::get (values)); |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3524 } |
561aad6a9e4b
Initial support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14983
diff
changeset
|
3525 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3526 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
|
3527 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3528 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
|
3529 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3530 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3531 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3532 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
|
3533 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3534 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
|
3535 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
|
3536 llvm::Type *idx = jit_typeinfo::get_index_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3537 const jit_range& rng = cr.value (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3538 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3539 llvm::Constant *constants[4]; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3540 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
|
3541 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
|
3542 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
|
3543 constants[3] = llvm::ConstantInt::get (idx, rng.nelem); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3544 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3545 llvm::Value *as_llvm; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3546 as_llvm = llvm::ConstantStruct::get (stype, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3547 llvm::makeArrayRef (constants, 4)); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3548 cr.stash_llvm (as_llvm); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3549 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3550 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3551 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3552 jit_convert::convert_llvm::visit (jit_block& b) |
14899 | 3553 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3554 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
|
3555 builder.SetInsertPoint (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3556 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
|
3557 visit (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3558 } |
14903 | 3559 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3560 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
|
3561 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
|
3562 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3563 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
|
3564 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3565 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3566 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
|
3567 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
|
3568 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3569 llvm::Value *cond = cb.cond_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3570 llvm::Value *br; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3571 br = builder.CreateCondBr (cond, cb.successor_llvm (0), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3572 cb.successor_llvm (1)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3573 cb.stash_llvm (br); |
14899 | 3574 } |
3575 | |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3576 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3577 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
|
3578 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3579 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
|
3580 call.stash_llvm (ret); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3581 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3582 |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3583 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3584 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
|
3585 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3586 llvm::Value *arg = arguments[extract.name ()]; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3587 assert (arg); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3588 arg = builder.CreateLoad (arg); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3589 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3590 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
|
3591 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
|
3592 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3593 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3594 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3595 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
|
3596 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3597 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
|
3598 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3599 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
|
3600 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
|
3601 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
3602 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3603 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3604 jit_convert::convert_llvm::visit (jit_phi& phi) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3605 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3606 // 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
|
3607 // set incomming branches now |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3608 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
|
3609 phi.argument_count ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3610 builder.Insert (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3611 phi.stash_llvm (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3612 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3613 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3614 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3615 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
|
3616 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3617 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
|
3618 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
3619 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3620 void |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
3621 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
|
3622 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3623 llvm::Value *cond = jit_typeinfo::insert_error_check (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
3624 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
|
3625 check.successor_llvm (1)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3626 check.stash_llvm (br); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3627 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3628 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3629 void |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3630 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
|
3631 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3632 assign.stash_llvm (assign.src ()->to_llvm ()); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3633 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3634 if (assign.artificial ()) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3635 return; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
3636 |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3637 jit_value *new_value = assign.src (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3638 if (isa<jit_assign_base> (new_value)) |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3639 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3640 const jit_operation::overload& ol |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3641 = jit_typeinfo::get_grab (new_value->type ()); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3642 if (ol.function) |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
3643 assign.stash_llvm (create_call (ol, new_value)); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3644 } |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3645 |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3646 jit_value *overwrite = assign.overwrite (); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3647 if (isa<jit_assign_base> (overwrite)) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3648 { |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3649 const jit_operation::overload& ol |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3650 = jit_typeinfo::get_release (overwrite->type ()); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3651 if (ol.function) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3652 create_call (ol, overwrite); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
3653 } |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
3654 } |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
3655 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3656 void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3657 jit_convert::convert_llvm::visit (jit_argument&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3658 {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3659 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3660 llvm::Value * |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3661 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
|
3662 const std::vector<jit_value *>& jargs) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3663 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3664 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
|
3665 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3666 llvm::Function *fun = ol.function; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3667 if (! fun) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3668 fail ("Missing overload"); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3669 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3670 const llvm::Function::ArgumentListType& alist = fun->getArgumentList (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3671 size_t nargs = alist.size (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3672 bool sret = false; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3673 if (nargs != jargs.size ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3674 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3675 // first argument is the structure return value |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3676 assert (nargs == jargs.size () + 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3677 sret = true; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3678 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3679 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3680 std::vector<llvm::Value *> args (nargs); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3681 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
|
3682 if (sret) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3683 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
3684 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
|
3685 ++llvm_arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3686 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3687 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3688 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
|
3689 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3690 llvm::Value *arg = jargs[i]->to_llvm (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3691 llvm::Type *arg_type = arg->getType (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3692 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
|
3693 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3694 if (arg_type == llvm_arg_type) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3695 args[i + sret] = arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3696 else |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3697 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3698 // pass structure by pointer |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3699 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
|
3700 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
|
3701 builder.CreateStore (arg, new_arg); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3702 args[i + sret] = new_arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3703 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3704 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3705 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3706 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
|
3707 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
|
3708 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3709 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3710 llvm::Value * |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
3711 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
|
3712 const std::vector<jit_use>& uses) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3713 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3714 std::vector<jit_value *> values (uses.size ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3715 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
|
3716 values[i] = uses[i].value (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3717 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3718 return create_call (ol, values); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3719 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
3720 |
14906 | 3721 // -------------------- tree_jit -------------------- |
3722 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3723 tree_jit::tree_jit (void) : module (0), engine (0) |
14906 | 3724 { |
3725 } | |
3726 | |
3727 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
|
3728 {} |
14906 | 3729 |
3730 bool | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3731 tree_jit::execute (tree_simple_for_command& cmd) |
14906 | 3732 { |
3733 if (! initialize ()) | |
3734 return false; | |
3735 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3736 jit_info *info = cmd.get_info (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3737 if (! info || ! info->match ()) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3738 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3739 delete info; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3740 info = new jit_info (*this, cmd); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3741 cmd.stash_info (info); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3742 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3743 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3744 return info->execute (); |
14906 | 3745 } |
3746 | |
3747 bool | |
3748 tree_jit::initialize (void) | |
14903 | 3749 { |
14906 | 3750 if (engine) |
3751 return true; | |
3752 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3753 if (! module) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3754 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3755 llvm::InitializeNativeTarget (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3756 module = new llvm::Module ("octave", context); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3757 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3758 |
14906 | 3759 // sometimes this fails pre main |
3760 engine = llvm::ExecutionEngine::createJIT (module); | |
3761 | |
3762 if (! engine) | |
3763 return false; | |
3764 | |
3765 module_pass_manager = new llvm::PassManager (); | |
3766 module_pass_manager->add (llvm::createAlwaysInlinerPass ()); | |
3767 | |
3768 pass_manager = new llvm::FunctionPassManager (module); | |
3769 pass_manager->add (new llvm::TargetData(*engine->getTargetData ())); | |
3770 pass_manager->add (llvm::createBasicAliasAnalysisPass ()); | |
3771 pass_manager->add (llvm::createPromoteMemoryToRegisterPass ()); | |
3772 pass_manager->add (llvm::createInstructionCombiningPass ()); | |
3773 pass_manager->add (llvm::createReassociatePass ()); | |
3774 pass_manager->add (llvm::createGVNPass ()); | |
3775 pass_manager->add (llvm::createCFGSimplificationPass ()); | |
3776 pass_manager->doInitialization (); | |
3777 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3778 jit_typeinfo::initialize (module, engine); |
14906 | 3779 |
3780 return true; | |
3781 } | |
3782 | |
3783 | |
3784 void | |
3785 tree_jit::optimize (llvm::Function *fn) | |
3786 { | |
3787 module_pass_manager->run (*module); | |
3788 pass_manager->run (*fn); | |
14985
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3789 |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3790 #ifdef OCTAVE_JIT_DEBUG |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3791 std::string error; |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3792 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
|
3793 llvm::raw_fd_ostream::F_Binary); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3794 llvm::WriteBitcodeToFile (module, fout); |
f5925478bc15
More support for complex numbers in JIT
Max Brister <max@2bass.com>
parents:
14984
diff
changeset
|
3795 #endif |
14906 | 3796 } |
3797 | |
3798 // -------------------- jit_info -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3799 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
|
3800 : engine (tjit.get_engine ()), llvm_function (0) |
14906 | 3801 { |
14903 | 3802 try |
3803 { | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3804 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
|
3805 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
|
3806 arguments = conv.get_arguments (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3807 bounds = conv.get_bounds (); |
14903 | 3808 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3809 catch (const jit_fail_exception& e) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3810 { |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3811 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3812 if (e.known ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3813 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
|
3814 #endif |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3815 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3816 |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3817 if (! llvm_function) |
14903 | 3818 { |
3819 function = 0; | |
3820 return; | |
3821 } | |
3822 | |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3823 tjit.optimize (llvm_function); |
14906 | 3824 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3825 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3826 std::cout << "-------------------- optimized llvm ir --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3827 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
|
3828 llvm_function->print (llvm_cout); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3829 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3830 #endif |
14903 | 3831 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3832 void *void_fn = engine->getPointerToFunction (llvm_function); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3833 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
|
3834 } |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3835 |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3836 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
|
3837 { |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3838 if (llvm_function) |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3839 llvm_function->eraseFromParent (); |
14903 | 3840 } |
3841 | |
3842 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3843 jit_info::execute (void) const |
14899 | 3844 { |
3845 if (! function) | |
3846 return false; | |
3847 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3848 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
|
3849 for (size_t i = 0; i < arguments.size (); ++i) |
14899 | 3850 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3851 if (arguments[i].second) |
14899 | 3852 { |
14987
65f74f52886c
Memory leaks with matrices in JIT
Max Brister <max@2bass.com>
parents:
14986
diff
changeset
|
3853 octave_value ¤t = symbol_table::varref (arguments[i].first); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3854 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
|
3855 obv->grab (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3856 real_arguments[i] = obv; |
14987
65f74f52886c
Memory leaks with matrices in JIT
Max Brister <max@2bass.com>
parents:
14986
diff
changeset
|
3857 current = octave_value (); |
14899 | 3858 } |
3859 } | |
3860 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3861 function (&real_arguments[0]); |
14899 | 3862 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3863 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
|
3864 symbol_table::varref (arguments[i].first) = real_arguments[i]; |
14910
a8f1e08de8fc
Simplified llvm::GenericValue creation
Max Brister <max@2bass.com>
parents:
14906
diff
changeset
|
3865 |
14899 | 3866 return true; |
3867 } | |
14903 | 3868 |
3869 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3870 jit_info::match (void) const |
14903 | 3871 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3872 if (! function) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3873 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3874 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3875 for (size_t i = 0; i < bounds.size (); ++i) |
14903 | 3876 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3877 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
|
3878 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
|
3879 jit_type *type = jit_typeinfo::type_of (value); |
14906 | 3880 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3881 // 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
|
3882 if (type != bounds[i].first) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3883 return false; |
14903 | 3884 } |
3885 | |
3886 return true; | |
3887 } | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3888 #endif |