Mercurial > octave-nkf
annotate src/pt-jit.cc @ 14969:bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
* src/pt-jit.cc (octave_jit_subsasgn_impl, jit_convert::resolve): New function.
(jit_typeinfo::jit_typeinfo): Add subsasgn implementation in llvm.
(jit_convert::visit_simple_for_command): Use new do_assign overload.
(jit_convert::visit_index_expression): Use new do_assign overload and resolve.
(jit_convert::visit_simple_assignment): Use new do_assign overload.
(jit_convert::do_assign): New overload.
(jit_convert::convert_llvm::visit): Check if assignment is artificial.
* src/pt-jit.h (jit_typeinfo::paren_subsasgn, jit_convert::create_check):
New function.
(jit_assign::jit_assign): Initialize martificial.
(jit_assign::artificial, jit_assign::mark_artificial): New function.
(jit_assign::print): Print the artificial flag.
(jit_convert::create_checked_impl): Call create_check.
(jit_convert::resolve): New declaration.
(jit_convert::do_assign): New overload declaration.
author | Max Brister <max@2bass.com> |
---|---|
date | Mon, 25 Jun 2012 14:21:45 -0500 |
parents | 7f60cdfcc0e5 |
children | b23a98ca0e43 |
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> | |
40 #include <llvm/Support/IRBuilder.h> | |
41 #include <llvm/ExecutionEngine/ExecutionEngine.h> | |
42 #include <llvm/ExecutionEngine/JIT.h> | |
43 #include <llvm/PassManager.h> | |
44 #include <llvm/Analysis/Verifier.h> | |
14903 | 45 #include <llvm/Analysis/CallGraph.h> |
14899 | 46 #include <llvm/Analysis/Passes.h> |
47 #include <llvm/Target/TargetData.h> | |
48 #include <llvm/Transforms/Scalar.h> | |
14903 | 49 #include <llvm/Transforms/IPO.h> |
14899 | 50 #include <llvm/Support/TargetSelect.h> |
51 #include <llvm/Support/raw_os_ostream.h> | |
52 | |
14903 | 53 #include "octave.h" |
14899 | 54 #include "ov-fcn-handle.h" |
55 #include "ov-usr-fcn.h" | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
56 #include "ov-scalar.h" |
14899 | 57 #include "pt-all.h" |
58 | |
14903 | 59 static llvm::IRBuilder<> builder (llvm::getGlobalContext ()); |
60 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
61 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
|
62 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
63 jit_typeinfo *jit_typeinfo::instance; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
64 |
14906 | 65 // 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
|
66 class jit_fail_exception : public std::runtime_error |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
67 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
68 public: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
69 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
|
70 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
|
71 mknown (true) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
72 {} |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
73 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
74 bool known (void) const { return mknown; } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
75 private: |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
76 bool mknown; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
77 }; |
14906 | 78 |
14940
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
79 static void fail (void) GCC_ATTR_NORETURN; |
5f05007ccc5f
Mark fail with GCC_ATTR_NORETURN
Max Brister <max@2bass.com>
parents:
14939
diff
changeset
|
80 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
|
81 |
14906 | 82 static void |
83 fail (void) | |
84 { | |
85 throw jit_fail_exception (); | |
86 } | |
87 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
88 #ifdef OCTAVE_JIT_DEBUG |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
89 static void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
90 fail (const std::string& reason) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
91 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
92 throw jit_fail_exception (reason); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
93 } |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
94 #else |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
95 static void |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
96 fail (const std::string&) |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
97 { |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
98 throw jit_fail_exception (); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
99 } |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
100 #endif // OCTAVE_JIT_DEBUG |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
101 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
102 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
|
103 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
104 if (! atype) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
105 return os << "null"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
106 return os << atype->name (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
107 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
108 |
14903 | 109 // function that jit code calls |
110 extern "C" void | |
111 octave_jit_print_any (const char *name, octave_base_value *obv) | |
112 { | |
113 obv->print_with_name (octave_stdout, name, true); | |
114 } | |
14899 | 115 |
116 extern "C" void | |
14903 | 117 octave_jit_print_double (const char *name, double value) |
14899 | 118 { |
119 // FIXME: We should avoid allocating a new octave_scalar each time | |
120 octave_value ov (value); | |
121 ov.print_with_name (octave_stdout, name); | |
122 } | |
123 | |
14903 | 124 extern "C" octave_base_value* |
125 octave_jit_binary_any_any (octave_value::binary_op op, octave_base_value *lhs, | |
126 octave_base_value *rhs) | |
127 { | |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
128 octave_value olhs (lhs, true); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
129 octave_value orhs (rhs, true); |
14903 | 130 octave_value result = do_binary_op (op, olhs, orhs); |
131 octave_base_value *rep = result.internal_rep (); | |
132 rep->grab (); | |
133 return rep; | |
134 } | |
135 | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
136 extern "C" octave_idx_type |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
137 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
|
138 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
139 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
|
140 return rng.nelem (); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
141 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
142 |
14903 | 143 extern "C" void |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
144 octave_jit_release_any (octave_base_value *obv) |
14903 | 145 { |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
146 obv->release (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
147 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
148 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
149 extern "C" void |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
150 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
|
151 { |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
152 delete m->array; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
153 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
154 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
155 extern "C" octave_base_value * |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
156 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
|
157 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
158 obv->grab (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
159 return obv; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
160 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
161 |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
162 extern "C" void |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
163 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
|
164 { |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
165 *result = *m->array; |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
166 } |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
167 |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
168 extern "C" octave_base_value * |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
169 octave_jit_cast_any_matrix (jit_matrix *m) |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
170 { |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
171 octave_value ret (*m->array); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
172 octave_base_value *rep = ret.internal_rep (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
173 rep->grab (); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
174 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
175 return rep; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
176 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
177 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
178 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
179 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
|
180 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
181 NDArray m = obv->array_value (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
182 *ret = m; |
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 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
185 extern "C" double |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
186 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
|
187 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
188 double ret = obv->double_value (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
189 obv->release (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
190 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
191 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
192 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
193 extern "C" octave_base_value * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
194 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
|
195 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
196 return new octave_scalar (value); |
14903 | 197 } |
198 | |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
199 extern "C" void |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
200 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
|
201 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
202 try |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
203 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
204 gripe_nan_to_logical_conversion (); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
205 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
206 catch (const octave_execution_exception&) |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
207 { |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
208 gripe_library_execution_error (); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
209 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
210 } |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
211 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
212 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
213 octave_jit_ginvalid_index (void) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
214 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
215 try |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
216 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
217 gripe_invalid_index (); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
218 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
219 catch (const octave_execution_exception&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
220 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
221 gripe_library_execution_error (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
222 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
223 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
224 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
225 extern "C" void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
226 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
|
227 octave_idx_type ext) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
228 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
229 try |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
230 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
231 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
|
232 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
233 catch (const octave_execution_exception&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
234 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
235 gripe_library_execution_error (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
236 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
237 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
238 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
239 extern "C" void |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
240 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
|
241 double value) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
242 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
243 std::cout << "impl\n"; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
244 NDArray *array = mat->array; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
245 if (array->nelem () < index) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
246 array->resize1 (index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
247 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
248 double *data = array->fortran_vec (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
249 data[index - 1] = value; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
250 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
251 mat->ref_count = array->jit_ref_count (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
252 mat->slice_data = array->jit_slice_data () - 1; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
253 mat->dimensions = array->jit_dimensions (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
254 mat->slice_len = array->nelem (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
255 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
256 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
257 extern "C" void |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
258 octave_jit_print_matrix (jit_matrix *m) |
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 std::cout << *m << std::endl; |
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 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
263 // -------------------- jit_range -------------------- |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
264 std::ostream& |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
265 operator<< (std::ostream& os, const jit_range& rng) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
266 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
267 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
|
268 << ", " << rng.nelem << "]"; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
269 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
270 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
271 // -------------------- jit_matrix -------------------- |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
272 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
273 std::ostream& |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
274 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
|
275 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
276 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
|
277 << mat.slice_len << ", " << mat.dimensions << ", " |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
278 << mat.array << "]"; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
279 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
280 |
14903 | 281 // -------------------- jit_type -------------------- |
282 llvm::Type * | |
283 jit_type::to_llvm_arg (void) const | |
284 { | |
285 return llvm_type ? llvm_type->getPointerTo () : 0; | |
286 } | |
287 | |
288 // -------------------- jit_function -------------------- | |
289 void | |
290 jit_function::add_overload (const overload& func, | |
291 const std::vector<jit_type*>& args) | |
292 { | |
293 if (args.size () >= overloads.size ()) | |
294 overloads.resize (args.size () + 1); | |
295 | |
296 Array<overload>& over = overloads[args.size ()]; | |
297 dim_vector dv (over.dims ()); | |
298 Array<octave_idx_type> idx = to_idx (args); | |
299 bool must_resize = false; | |
300 | |
301 if (dv.length () != idx.numel ()) | |
302 { | |
303 dv.resize (idx.numel ()); | |
304 must_resize = true; | |
305 } | |
306 | |
307 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
308 if (dv(i) <= idx(i)) | |
309 { | |
310 must_resize = true; | |
311 dv(i) = idx(i) + 1; | |
312 } | |
313 | |
314 if (must_resize) | |
315 over.resize (dv); | |
316 | |
317 over(idx) = func; | |
318 } | |
319 | |
320 const jit_function::overload& | |
321 jit_function::get_overload (const std::vector<jit_type*>& types) const | |
322 { | |
323 // FIXME: We should search for the next best overload on failure | |
324 static overload null_overload; | |
325 if (types.size () >= overloads.size ()) | |
326 return null_overload; | |
327 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
328 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
|
329 if (! types[i]) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
330 return null_overload; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
331 |
14903 | 332 const Array<overload>& over = overloads[types.size ()]; |
333 dim_vector dv (over.dims ()); | |
334 Array<octave_idx_type> idx = to_idx (types); | |
335 for (octave_idx_type i = 0; i < dv.length (); ++i) | |
336 if (idx(i) >= dv(i)) | |
337 return null_overload; | |
338 | |
339 return over(idx); | |
340 } | |
341 | |
342 Array<octave_idx_type> | |
343 jit_function::to_idx (const std::vector<jit_type*>& types) const | |
344 { | |
345 octave_idx_type numel = types.size (); | |
346 if (numel == 1) | |
347 numel = 2; | |
348 | |
349 Array<octave_idx_type> idx (dim_vector (1, numel)); | |
350 for (octave_idx_type i = 0; i < static_cast<octave_idx_type> (types.size ()); | |
351 ++i) | |
352 idx(i) = types[i]->type_id (); | |
353 | |
354 if (types.size () == 1) | |
355 { | |
356 idx(1) = idx(0); | |
357 idx(0) = 0; | |
358 } | |
359 | |
360 return idx; | |
361 } | |
362 | |
363 // -------------------- jit_typeinfo -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
364 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
365 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
|
366 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
367 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
|
368 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
369 |
14906 | 370 jit_typeinfo::jit_typeinfo (llvm::Module *m, llvm::ExecutionEngine *e) |
371 : module (m), engine (e), next_id (0) | |
14899 | 372 { |
14903 | 373 // 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
|
374 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
|
375 any_t = any_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
376 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
377 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
|
378 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
|
379 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
|
380 string_t = string_t->getPointerTo (); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
381 llvm::Type *index_t = llvm::Type::getIntNTy (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
382 sizeof(octave_idx_type) * 8); |
14906 | 383 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
384 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
|
385 std::vector<llvm::Type *> range_contents (4, scalar_t); |
14906 | 386 range_contents[3] = index_t; |
387 range_t->setBody (range_contents); | |
388 | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
389 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
|
390 llvm::Type *int_t = refcount_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
391 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
392 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
|
393 llvm::Type *matrix_contents[5]; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
394 matrix_contents[0] = refcount_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
395 matrix_contents[1] = scalar_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
396 matrix_contents[2] = index_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
397 matrix_contents[3] = index_t->getPointerTo (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
398 matrix_contents[4] = string_t; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
399 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
|
400 |
14903 | 401 // create types |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
402 any = new_type ("any", 0, any_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
403 matrix = new_type ("matrix", any, matrix_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
404 scalar = new_type ("scalar", any, scalar_t); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 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
|
409 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
410 casts.resize (next_id + 1); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
411 identities.resize (next_id + 1, 0); |
14903 | 412 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
413 // bind global variables |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
414 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
|
415 llvm::GlobalValue::ExternalLinkage, |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
416 0, "error_state"); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
417 engine->addGlobalMapping (lerror_state, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
418 reinterpret_cast<void *> (&error_state)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
419 |
14903 | 420 // 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
|
421 llvm::Function *fn; |
14903 | 422 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
|
423 = 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
|
424 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
|
425 any_t, binary_op_type, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
426 any_t, any_t); |
14903 | 427 engine->addGlobalMapping (any_binary, |
428 reinterpret_cast<void*>(&octave_jit_binary_any_any)); | |
429 | |
430 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
|
431 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
|
432 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
433 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
|
434 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
|
435 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
|
436 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
437 |
14903 | 438 for (int op = 0; op < octave_value::num_binary_ops; ++op) |
439 { | |
440 llvm::Twine fn_name ("octave_jit_binary_any_any_"); | |
441 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
|
442 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
|
443 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 444 builder.SetInsertPoint (block); |
14903 | 445 llvm::APInt op_int(sizeof (octave_value::binary_op), op, |
446 std::numeric_limits<octave_value::binary_op>::is_signed); | |
447 llvm::Value *op_as_llvm = llvm::ConstantInt::get (binary_op_type, op_int); | |
14906 | 448 llvm::Value *ret = builder.CreateCall3 (any_binary, |
14903 | 449 op_as_llvm, |
450 fn->arg_begin (), | |
451 ++fn->arg_begin ()); | |
14906 | 452 builder.CreateRet (ret); |
14945 | 453 binary_ops[op].add_overload (fn, true, any, any, any); |
14903 | 454 } |
455 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
456 llvm::Type *void_t = llvm::Type::getVoidTy (context); |
14903 | 457 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
458 // grab any |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
459 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
|
460 engine->addGlobalMapping (fn, reinterpret_cast<void*>(&octave_jit_grab_any)); |
14945 | 461 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
|
462 grab_fn.stash_name ("grab"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
463 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
464 // grab matrix |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
465 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
|
466 void_t, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
467 matrix_t->getPointerTo ()); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
468 engine->addGlobalMapping (print_matrix, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
469 reinterpret_cast<void*>(&octave_jit_print_matrix)); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
470 fn = create_function ("octave_jit_grab_matrix", void_t, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
471 matrix_t->getPointerTo (), matrix_t->getPointerTo ()); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
472 engine->addGlobalMapping (fn, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
473 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
|
474 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
|
475 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
476 // release any |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
477 fn = create_function ("octave_jit_release_any", void_t, any_t); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
478 engine->addGlobalMapping (fn, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
479 reinterpret_cast<void*>(&octave_jit_release_any)); |
14945 | 480 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
|
481 release_fn.stash_name ("release"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
482 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
483 // release matrix |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
484 fn = create_function ("octave_jit_release_matrix", void_t, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
485 matrix_t->getPointerTo ()); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
486 engine->addGlobalMapping (fn, |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
487 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
|
488 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
|
489 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
490 // release scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
491 fn = create_identity (scalar); |
14945 | 492 release_fn.add_overload (fn, false, 0, scalar); |
14903 | 493 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
494 // release index |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
495 fn = create_identity (index); |
14945 | 496 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
|
497 |
14903 | 498 // now for binary scalar operations |
499 // FIXME: Finish all operations | |
500 add_binary_op (scalar, octave_value::op_add, llvm::Instruction::FAdd); | |
501 add_binary_op (scalar, octave_value::op_sub, llvm::Instruction::FSub); | |
502 add_binary_op (scalar, octave_value::op_mul, llvm::Instruction::FMul); | |
503 add_binary_op (scalar, octave_value::op_el_mul, llvm::Instruction::FMul); | |
504 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 |
14941 | 512 llvm::Function *gripe_div0 = create_function ("gripe_divide_by_zero", void_t); |
513 engine->addGlobalMapping (gripe_div0, | |
514 reinterpret_cast<void *> (&gripe_divide_by_zero)); | |
515 | |
516 // divide is annoying because it might error | |
517 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
|
518 llvm::BasicBlock *body = llvm::BasicBlock::Create (context, "body", fn); |
14941 | 519 builder.SetInsertPoint (body); |
520 { | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
521 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
|
522 fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
523 llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
524 "normal", fn); |
14941 | 525 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
526 llvm::Value *zero = llvm::ConstantFP::get (scalar_t, 0); |
14941 | 527 llvm::Value *check = builder.CreateFCmpUEQ (zero, ++fn->arg_begin ()); |
528 builder.CreateCondBr (check, warn_block, normal_block); | |
529 | |
530 builder.SetInsertPoint (warn_block); | |
531 builder.CreateCall (gripe_div0); | |
532 builder.CreateBr (normal_block); | |
533 | |
534 builder.SetInsertPoint (normal_block); | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
535 llvm::Value *ret = builder.CreateFDiv (fn->arg_begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
536 ++fn->arg_begin ()); |
14941 | 537 builder.CreateRet (ret); |
538 | |
14945 | 539 jit_function::overload ol (fn, true, scalar, scalar, scalar); |
14941 | 540 binary_ops[octave_value::op_div].add_overload (ol); |
541 binary_ops[octave_value::op_el_div].add_overload (ol); | |
542 } | |
543 llvm::verifyFunction (*fn); | |
544 | |
545 // ldiv is the same as div with the operators reversed | |
546 llvm::Function *div = fn; | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
547 fn = create_function ("octave_jit_ldiv_scalar_scalar", scalar, scalar, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
548 scalar); |
14941 | 549 body = llvm::BasicBlock::Create (context, "body", fn); |
550 builder.SetInsertPoint (body); | |
551 { | |
552 llvm::Value *ret = builder.CreateCall2 (div, ++fn->arg_begin (), | |
553 fn->arg_begin ()); | |
554 builder.CreateRet (ret); | |
555 | |
14945 | 556 jit_function::overload ol (fn, true, scalar, scalar, scalar); |
14941 | 557 binary_ops[octave_value::op_ldiv].add_overload (ol); |
558 binary_ops[octave_value::op_el_ldiv].add_overload (ol); | |
559 } | |
560 llvm::verifyFunction (*fn); | |
561 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
562 // now for binary index operators |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
563 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
|
564 |
14903 | 565 // now for printing functions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
566 print_fn.stash_name ("print"); |
14903 | 567 add_print (any, reinterpret_cast<void*> (&octave_jit_print_any)); |
568 add_print (scalar, reinterpret_cast<void*> (&octave_jit_print_double)); | |
14906 | 569 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
570 // initialize for loop |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
571 for_init_fn.stash_name ("for_init"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
572 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
573 fn = create_function ("octave_jit_for_range_init", index, range); |
14941 | 574 body = llvm::BasicBlock::Create (context, "body", fn); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
575 builder.SetInsertPoint (body); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
576 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
577 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
|
578 builder.CreateRet (zero); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
579 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
580 llvm::verifyFunction (*fn); |
14945 | 581 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
|
582 |
14906 | 583 // bounds check for for loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
584 for_check_fn.stash_name ("for_check"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
585 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
586 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
|
587 body = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 588 builder.SetInsertPoint (body); |
589 { | |
590 llvm::Value *nelem | |
591 = builder.CreateExtractValue (fn->arg_begin (), 3); | |
592 llvm::Value *idx = ++fn->arg_begin (); | |
593 llvm::Value *ret = builder.CreateICmpULT (idx, nelem); | |
594 builder.CreateRet (ret); | |
595 } | |
596 llvm::verifyFunction (*fn); | |
14945 | 597 for_check_fn.add_overload (fn, false, boolean, range, index); |
14906 | 598 |
599 // index variabe for for loop | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
600 for_index_fn.stash_name ("for_index"); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
601 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
602 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
|
603 body = llvm::BasicBlock::Create (context, "body", fn); |
14906 | 604 builder.SetInsertPoint (body); |
605 { | |
606 llvm::Value *idx = ++fn->arg_begin (); | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
607 llvm::Value *didx = builder.CreateSIToFP (idx, scalar_t); |
14906 | 608 llvm::Value *rng = fn->arg_begin (); |
609 llvm::Value *base = builder.CreateExtractValue (rng, 0); | |
610 llvm::Value *inc = builder.CreateExtractValue (rng, 2); | |
611 | |
612 llvm::Value *ret = builder.CreateFMul (didx, inc); | |
613 ret = builder.CreateFAdd (base, ret); | |
614 builder.CreateRet (ret); | |
615 } | |
616 llvm::verifyFunction (*fn); | |
14945 | 617 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
|
618 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
619 // logically true |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
620 logically_true_fn.stash_name ("logically_true"); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
621 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
622 llvm::Function *gripe_nantl |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
623 = 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
|
624 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
|
625 |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
626 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
|
627 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
|
628 builder.SetInsertPoint (body); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
629 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
630 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
|
631 fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
632 llvm::BasicBlock *normal_block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
633 "normal", fn); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
634 |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
635 llvm::Value *check = builder.CreateFCmpUNE (fn->arg_begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
636 fn->arg_begin ()); |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
637 builder.CreateCondBr (check, error_block, normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
638 |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
639 builder.SetInsertPoint (error_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
640 builder.CreateCall (gripe_nantl); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
641 builder.CreateBr (normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
642 builder.SetInsertPoint (normal_block); |
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
643 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
644 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
|
645 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
|
646 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
647 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
648 llvm::verifyFunction (*fn); |
14945 | 649 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
|
650 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
651 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
|
652 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
|
653 builder.SetInsertPoint (body); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
654 builder.CreateRet (fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
655 llvm::verifyFunction (*fn); |
14945 | 656 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
|
657 |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
658 // make_range |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
659 // 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
|
660 make_range_fn.stash_name ("make_range"); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
661 llvm::Function *compute_nelem |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
662 = 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
|
663 scalar); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
664 engine->addGlobalMapping (compute_nelem, |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
665 reinterpret_cast<void*> (&octave_jit_compute_nelem)); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
666 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
667 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
|
668 body = llvm::BasicBlock::Create (context, "body", fn); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
669 builder.SetInsertPoint (body); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
670 { |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
671 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
|
672 llvm::Value *base = args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
673 llvm::Value *limit = ++args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
674 llvm::Value *inc = ++args; |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
675 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
|
676 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 izero, NULL); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
681 rng = builder.CreateInsertValue (rng, base, 0); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
682 rng = builder.CreateInsertValue (rng, limit, 1); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
683 rng = builder.CreateInsertValue (rng, inc, 2); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
684 rng = builder.CreateInsertValue (rng, nelem, 3); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
685 builder.CreateRet (rng); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
686 } |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
687 llvm::verifyFunction (*fn); |
14945 | 688 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
|
689 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
690 // paren_subsref |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
691 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
|
692 void_t); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
693 engine->addGlobalMapping (ginvalid_index, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
694 reinterpret_cast<void*> (&octave_jit_ginvalid_index)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
695 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
696 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
|
697 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
|
698 index_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
699 engine->addGlobalMapping (gindex_range, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
700 reinterpret_cast<void*> (&octave_jit_gindex_range)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
701 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
702 fn = create_function ("()subsref", scalar, matrix, scalar); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
703 body = llvm::BasicBlock::Create (context, "body", fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
704 builder.SetInsertPoint (body); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
705 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
706 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
|
707 llvm::Value *ione; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
708 if (index_t == int_t) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
709 ione = one; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
710 else |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
711 ione = llvm::ConstantInt::get (int_t, 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
712 |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
713 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
|
714 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
715 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
|
716 llvm::Value *mat = args++; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
717 llvm::Value *idx = args; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
718 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
719 // 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
|
720 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
|
721 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
|
722 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
|
723 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
|
724 llvm::Value *cond = builder.CreateOr (cond0, cond1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
725 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
726 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
|
727 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
728 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
|
729 "conv_error", fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
730 done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
731 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
|
732 done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
733 builder.CreateCondBr (cond, conv_error, normal); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
734 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
735 builder.SetInsertPoint (conv_error); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
736 builder.CreateCall (ginvalid_index); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
737 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
738 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
739 builder.SetInsertPoint (normal); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
740 llvm::Value *len = builder.CreateExtractValue (mat, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
741 llvm::ArrayRef<unsigned> (2)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
742 cond = builder.CreateICmpSGT (int_idx, len); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
743 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
744 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
745 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
|
746 "bounds_error", |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
747 fn, done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
748 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
749 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
|
750 fn, done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
751 builder.CreateCondBr (cond, bounds_error, success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
752 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
753 builder.SetInsertPoint (bounds_error); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
754 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
|
755 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
756 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
757 builder.SetInsertPoint (success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
758 llvm::Value *data = builder.CreateExtractValue (mat, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
759 llvm::ArrayRef<unsigned> (1)); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
760 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
|
761 llvm::Value *ret = builder.CreateLoad (gep); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
762 builder.CreateBr (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
763 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
764 builder.SetInsertPoint (done); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
765 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
766 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
|
767 builder.Insert (merge); |
14967
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
768 merge->addIncoming (undef, conv_error); |
0cfe0cf55a02
Simplify matrix handling in JIT
Max Brister <max@2bass.com>
parents:
14966
diff
changeset
|
769 merge->addIncoming (undef, bounds_error); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
770 merge->addIncoming (ret, success); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
771 builder.CreateRet (merge); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
772 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
773 llvm::verifyFunction (*fn); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
774 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
|
775 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
776 // paren subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
777 paren_subsasgn_fn.stash_name ("()subsasgn"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
778 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
779 llvm::Function *resize_paren_subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
780 = 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
|
781 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
|
782 engine->addGlobalMapping (resize_paren_subsasgn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
783 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
|
784 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
785 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
|
786 scalar); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
787 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
|
788 builder.SetInsertPoint (body); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
789 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
790 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
|
791 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
792 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
|
793 llvm::Value *mat = args++; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
794 llvm::Value *idx = args++; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
795 llvm::Value *value = args; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
796 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
797 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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
803 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
|
804 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
805 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
|
806 "conv_error", fn, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
807 done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
808 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
|
809 done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
810 builder.CreateCondBr (cond, conv_error, normal); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
811 builder.SetInsertPoint (conv_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
812 builder.CreateCall (ginvalid_index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
813 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
814 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
815 builder.SetInsertPoint (normal); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
816 llvm::Value *len = builder.CreateExtractValue (mat, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
817 llvm::ArrayRef<unsigned> (2)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
818 cond0 = builder.CreateICmpSGT (int_idx, len); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
819 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
820 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
|
821 rcount = builder.CreateLoad (rcount); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
822 cond1 = builder.CreateICmpSGT (rcount, one); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
823 cond = builder.CreateOr (cond0, cond1); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
824 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
825 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
|
826 "bounds_error", |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
827 fn, done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
828 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
829 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
|
830 fn, done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
831 builder.CreateCondBr (cond, bounds_error, success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
832 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
833 // resize on out of bounds access |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
834 builder.SetInsertPoint (bounds_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
835 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
|
836 builder.CreateStore (mat, resize_result); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
837 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
|
838 resize_result = builder.CreateLoad (resize_result); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
839 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
840 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
841 builder.SetInsertPoint (success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
842 llvm::Value *data = builder.CreateExtractValue (mat, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
843 llvm::ArrayRef<unsigned> (1)); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
844 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
|
845 builder.CreateStore (value, gep); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
846 builder.CreateBr (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
847 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
848 builder.SetInsertPoint (done); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
849 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
850 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
|
851 builder.Insert (merge); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
852 merge->addIncoming (mat, conv_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
853 merge->addIncoming (resize_result, bounds_error); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
854 merge->addIncoming (mat, success); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
855 builder.CreateRet (merge); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
856 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
857 llvm::verifyFunction (*fn); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
858 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
|
859 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
860 // paren_subsasgn |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
861 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
862 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
|
863 casts[scalar->type_id ()].stash_name ("(scalar)"); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
864 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
865 // cast any <- matrix |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
866 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
|
867 matrix_t->getPointerTo ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
868 engine->addGlobalMapping (fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
869 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
|
870 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
|
871 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
872 // cast matrix <- any |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
873 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
|
874 matrix_t->getPointerTo (), any_t); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
875 engine->addGlobalMapping (fn, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
876 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
|
877 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
|
878 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
879 // cast any <- scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
880 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
|
881 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_any_scalar)); |
14945 | 882 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
|
883 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
884 // cast scalar <- any |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
885 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
|
886 engine->addGlobalMapping (fn, reinterpret_cast<void*> (&octave_jit_cast_scalar_any)); |
14945 | 887 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
|
888 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
889 // cast any <- any |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
890 fn = create_identity (any); |
14945 | 891 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
|
892 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
893 // cast scalar <- scalar |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
894 fn = create_identity (scalar); |
14945 | 895 casts[scalar->type_id ()].add_overload (fn, false, scalar, scalar); |
14903 | 896 } |
897 | |
898 void | |
899 jit_typeinfo::add_print (jit_type *ty, void *call) | |
900 { | |
901 std::stringstream name; | |
902 name << "octave_jit_print_" << ty->name (); | |
903 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
904 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
|
905 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
|
906 llvm::Type::getInt8PtrTy (context), |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
907 ty->to_llvm ()); |
14903 | 908 engine->addGlobalMapping (fn, call); |
909 | |
14945 | 910 jit_function::overload ol (fn, false, 0, string, ty); |
14903 | 911 print_fn.add_overload (ol); |
912 } | |
913 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
914 // FIXME: cp between add_binary_op, add_binary_icmp, and add_binary_fcmp |
14903 | 915 void |
916 jit_typeinfo::add_binary_op (jit_type *ty, int op, int llvm_op) | |
917 { | |
918 std::stringstream fname; | |
919 octave_value::binary_op ov_op = static_cast<octave_value::binary_op>(op); | |
920 fname << "octave_jit_" << octave_value::binary_op_as_string (ov_op) | |
921 << "_" << ty->name (); | |
14906 | 922 |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
923 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
|
924 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
|
925 builder.SetInsertPoint (block); |
14903 | 926 llvm::Instruction::BinaryOps temp |
927 = 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
|
928 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
|
929 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
930 builder.CreateRet (ret); |
14903 | 931 llvm::verifyFunction (*fn); |
932 | |
14945 | 933 jit_function::overload ol(fn, false, ty, ty, ty); |
14903 | 934 binary_ops[op].add_overload (ol); |
935 } | |
936 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
937 void |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
938 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
|
939 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
940 std::stringstream fname; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
941 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
|
942 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
|
943 << "_" << ty->name (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
944 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
945 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
|
946 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
|
947 builder.SetInsertPoint (block); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
948 llvm::CmpInst::Predicate temp |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
949 = 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
|
950 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
|
951 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
952 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
953 llvm::verifyFunction (*fn); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
954 |
14945 | 955 jit_function::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
|
956 binary_ops[op].add_overload (ol); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
957 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
958 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
959 void |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
960 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
|
961 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
962 std::stringstream fname; |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
963 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
|
964 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
|
965 << "_" << ty->name (); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
966 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
967 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
|
968 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
|
969 builder.SetInsertPoint (block); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
970 llvm::CmpInst::Predicate temp |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
971 = 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
|
972 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
|
973 ++fn->arg_begin ()); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
974 builder.CreateRet (ret); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
975 llvm::verifyFunction (*fn); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
976 |
14945 | 977 jit_function::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
|
978 binary_ops[op].add_overload (ol); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
979 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
980 |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
981 llvm::Function * |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
982 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
|
983 const std::vector<llvm::Type *>& args) |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
984 { |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
985 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
|
986 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
|
987 llvm::Function::ExternalLinkage, |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
988 name, module); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
989 fn->addFnAttr (llvm::Attribute::AlwaysInline); |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
990 return fn; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
991 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
992 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
993 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
994 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
|
995 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
996 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
|
997 if (id >= identities.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
998 identities.resize (id + 1, 0); |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
999 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1000 if (! identities[id]) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1001 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1002 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
|
1003 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
|
1004 builder.SetInsertPoint (body); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1005 builder.CreateRet (fn->arg_begin ()); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1006 llvm::verifyFunction (*fn); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1007 identities[id] = fn; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1008 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1009 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1010 return identities[id]; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1011 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1012 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1013 llvm::Value * |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1014 jit_typeinfo::do_insert_error_check (void) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1015 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1016 return builder.CreateLoad (lerror_state); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1017 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1018 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1019 jit_type * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1020 jit_typeinfo::do_type_of (const octave_value &ov) const |
14903 | 1021 { |
14924 | 1022 if (ov.is_function ()) |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1023 return 0; // functions are not supported |
14903 | 1024 |
14906 | 1025 if (ov.is_range ()) |
1026 return get_range (); | |
1027 | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1028 if (ov.is_double_type ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1029 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1030 if (ov.is_real_scalar ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1031 return get_scalar (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1032 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1033 if (ov.is_matrix_type ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1034 return get_matrix (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1035 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1036 |
14903 | 1037 return get_any (); |
1038 } | |
1039 | |
1040 jit_type* | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1041 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
|
1042 llvm::Type *llvm_type) |
14903 | 1043 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1044 jit_type *ret = new jit_type (name, parent, llvm_type, next_id++); |
14903 | 1045 id_to_type.push_back (ret); |
1046 return ret; | |
1047 } | |
1048 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1049 // -------------------- jit_use -------------------- |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1050 jit_block * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1051 jit_use::user_parent (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1052 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1053 return muser->parent (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1054 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1055 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1056 // -------------------- jit_value -------------------- |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1057 jit_value::~jit_value (void) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1058 {} |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1059 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1060 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1061 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
|
1062 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1063 while (first_use ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1064 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1065 jit_instruction *user = first_use ()->user (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1066 size_t idx = first_use ()->index (); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1067 user->stash_argument (idx, value); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1068 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1069 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1070 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1071 #define JIT_METH(clname) \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1072 void \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1073 jit_ ## clname::accept (jit_ir_walker& walker) \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1074 { \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1075 walker.visit (*this); \ |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1076 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1077 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1078 JIT_VISIT_IR_NOTEMPLATE |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1079 #undef JIT_METH |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1080 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1081 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1082 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
|
1083 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1084 return value.short_print (os); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1085 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1086 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1087 std::ostream& |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1088 jit_print (std::ostream& os, jit_value *avalue) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1089 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1090 if (avalue) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1091 return avalue->print (os); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1092 return os << "NULL"; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1093 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1094 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1095 // -------------------- jit_instruction -------------------- |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1096 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1097 jit_instruction::remove (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1098 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1099 if (mparent) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1100 mparent->remove (mlocation); |
14945 | 1101 resize_arguments (0); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1102 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1103 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1104 llvm::BasicBlock * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1105 jit_instruction::parent_llvm (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1106 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1107 return mparent->to_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1108 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1109 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1110 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1111 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
|
1112 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1113 if (type ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1114 jit_print (os, type ()) << ": "; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1115 return os << "#" << mid; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1116 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1117 |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1118 void |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1119 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
|
1120 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1121 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
|
1122 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1123 jit_value *arg = argument (i); |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1124 jit_variable *var = dynamic_cast<jit_variable *> (arg); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
1125 if (var && var->has_top ()) |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1126 stash_argument (i, var->top ()); |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1127 } |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1128 } |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1129 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1130 // -------------------- jit_block -------------------- |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1131 void |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1132 jit_block::replace_with (jit_value *value) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1133 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1134 assert (isa<jit_block> (value)); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1135 jit_block *block = static_cast<jit_block *> (value); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1136 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1137 jit_value::replace_with (block); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1138 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1139 while (ILIST_T::first_use ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1140 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1141 jit_phi_incomming *incomming = ILIST_T::first_use (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1142 incomming->stash_value (block); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1143 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1144 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1145 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1146 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1147 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
|
1148 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1149 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
|
1150 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
|
1151 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1152 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
|
1153 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
|
1154 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1155 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
|
1156 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
|
1157 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1158 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1159 |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1160 jit_block * |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1161 jit_block::maybe_merge () |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1162 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1163 if (successor_count () == 1 && successor (0) != this |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1164 && (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
|
1165 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1166 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
|
1167 merge (*to_merge); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1168 return to_merge; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1169 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1170 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1171 return 0; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1172 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1173 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1174 void |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1175 jit_block::merge (jit_block& block) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1176 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1177 // 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
|
1178 jit_terminator *old_term = terminator (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1179 if (old_term) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1180 old_term->remove (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1181 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1182 bool was_empty = end () == begin (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1183 iterator merge_begin = end (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1184 if (! was_empty) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1185 --merge_begin; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1186 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1187 instructions.splice (end (), block.instructions); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1188 if (was_empty) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1189 merge_begin = begin (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1190 else |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1191 ++merge_begin; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1192 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1193 // 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
|
1194 // update their parent information |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1195 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
|
1196 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1197 jit_instruction *instr = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1198 instr->stash_parent (this, iter); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1199 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1200 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1201 block.replace_with (this); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1202 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
1203 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1204 jit_instruction * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1205 jit_block::prepend (jit_instruction *instr) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1206 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1207 instructions.push_front (instr); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1208 instr->stash_parent (this, instructions.begin ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1209 return instr; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1210 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1211 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1212 jit_instruction * |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1213 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
|
1214 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1215 // FIXME: Make this O(1) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1216 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
|
1217 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1218 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
|
1219 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
|
1220 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1221 insert_before (iter, instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1222 return instr; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1223 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1224 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1225 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1226 return append (instr); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1227 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1228 |
14945 | 1229 void |
1230 jit_block::internal_append (jit_instruction *instr) | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1231 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1232 instructions.push_back (instr); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1233 instr->stash_parent (this, --instructions.end ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1234 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1235 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1236 jit_instruction * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1237 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
|
1238 { |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1239 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
|
1240 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
|
1241 return instr; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1242 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1243 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1244 jit_instruction * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1245 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
|
1246 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1247 ++loc; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1248 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
|
1249 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
|
1250 return instr; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1251 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1252 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1253 jit_terminator * |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1254 jit_block::terminator (void) const |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1255 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1256 assert (this); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1257 if (instructions.empty ()) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1258 return 0; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1259 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1260 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
|
1261 return dynamic_cast<jit_terminator *> (last); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1262 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1263 |
14945 | 1264 bool |
1265 jit_block::branch_alive (jit_block *asucc) const | |
1266 { | |
1267 return terminator ()->alive (asucc); | |
1268 } | |
1269 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1270 jit_block * |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1271 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
|
1272 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1273 jit_terminator *term = terminator (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1274 return term->successor (i); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1275 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1276 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1277 size_t |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1278 jit_block::successor_count (void) const |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1279 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1280 jit_terminator *term = terminator (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1281 return term ? term->successor_count () : 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1282 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1283 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1284 llvm::BasicBlock * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1285 jit_block::to_llvm (void) const |
14903 | 1286 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1287 return llvm::cast<llvm::BasicBlock> (llvm_value); |
14903 | 1288 } |
1289 | |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1290 std::ostream& |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1291 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
|
1292 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1293 short_print (os); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1294 os << ":\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1295 os << " mid: " << mid << std::endl; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1296 os << " predecessors: "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1297 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
|
1298 os << *use->user_parent () << " "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1299 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1300 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1301 os << " successors: "; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1302 for (size_t i = 0; i < successor_count (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1303 os << *successor (i) << " "; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1304 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1305 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1306 os << " idom: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1307 if (idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1308 os << *idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1309 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1310 os << "NULL"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1311 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1312 os << " df: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1313 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
|
1314 os << **iter << " "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1315 os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1316 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1317 os << " dom_succ: "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1318 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
|
1319 os << *dom_succ[i] << " "; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1320 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1321 return os << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1322 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1323 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1324 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1325 jit_block::compute_df (size_t visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1326 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1327 if (mvisit_count > visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1328 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1329 ++mvisit_count; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1330 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1331 if (use_count () >= 2) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1332 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1333 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
|
1334 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1335 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
|
1336 while (runner != idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1337 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1338 runner->mdf.insert (this); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1339 runner = runner->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1340 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1341 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1342 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1343 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1344 for (size_t i = 0; i < successor_count (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1345 successor (i)->compute_df (visit_count); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1346 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1347 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1348 bool |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1349 jit_block::update_idom (size_t visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1350 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1351 if (mvisit_count > visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1352 return false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1353 ++mvisit_count; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1354 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1355 if (! use_count ()) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1356 return false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1357 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1358 bool changed = false; |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1359 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
|
1360 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1361 jit_block *pred = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1362 changed = pred->update_idom (visit_count) || changed; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1363 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1364 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1365 jit_use *use = first_use (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1366 jit_block *new_idom = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1367 use = use->next (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1368 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1369 for (; use; use = use->next ()) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1370 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1371 jit_block *pred = use->user_parent (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1372 jit_block *pidom = pred->idom; |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1373 if (pidom) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1374 new_idom = pidom->idom_intersect (new_idom); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1375 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1376 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1377 if (idom != new_idom) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1378 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1379 idom = new_idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1380 return true; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1381 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1382 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1383 return changed; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1384 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1385 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1386 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1387 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
|
1388 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1389 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
|
1390 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1391 jit_instruction *instr = *iter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1392 instr->pop_variable (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1393 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1394 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1395 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1396 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
|
1397 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
|
1398 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1399 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
|
1400 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1401 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
|
1402 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
|
1403 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
|
1404 |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1405 // try to place splits where they make sense |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1406 if (id () < asuccessor->id ()) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1407 convert.insert_before (asuccessor, split); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1408 else |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1409 convert.insert_after (this, split); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1410 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1411 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
|
1412 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
|
1413 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
|
1414 |
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
|
1415 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
|
1416 { |
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
|
1417 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
|
1418 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
|
1419 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1420 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1421 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
|
1422 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1423 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1424 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
|
1425 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1426 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1427 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1428 jit_block::create_dom_tree (size_t visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1429 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1430 if (mvisit_count > visit_count) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1431 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1432 ++mvisit_count; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1433 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1434 if (idom != this) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1435 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
|
1436 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1437 for (size_t i = 0; i < successor_count (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1438 successor (i)->create_dom_tree (visit_count); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1439 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1440 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1441 jit_block * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1442 jit_block::idom_intersect (jit_block *b) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1443 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1444 jit_block *i = this; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1445 jit_block *j = b; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1446 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1447 while (i != j) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1448 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1449 while (i->id () > j->id ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1450 i = i->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1451 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1452 while (j->id () > i->id ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1453 j = j->idom; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1454 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1455 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1456 return i; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1457 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1458 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1459 // -------------------- 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
|
1460 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1461 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
|
1462 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
|
1463 { 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
|
1464 |
14945 | 1465 // -------------------- jit_phi -------------------- |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1466 bool |
14945 | 1467 jit_phi::prune (void) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1468 { |
14945 | 1469 jit_block *p = parent (); |
1470 size_t new_idx = 0; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1471 jit_value *unique = argument (1); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1472 |
14945 | 1473 for (size_t i = 0; i < argument_count (); ++i) |
1474 { | |
1475 jit_block *inc = incomming (i); | |
1476 if (inc->branch_alive (p)) | |
1477 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1478 if (unique != argument (i)) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1479 unique = 0; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1480 |
14945 | 1481 if (new_idx != i) |
1482 { | |
1483 stash_argument (new_idx, argument (i)); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1484 mincomming[new_idx].stash_value (inc); |
14945 | 1485 } |
1486 | |
1487 ++new_idx; | |
1488 } | |
1489 } | |
1490 | |
1491 if (new_idx != argument_count ()) | |
1492 { | |
1493 resize_arguments (new_idx); | |
1494 mincomming.resize (new_idx); | |
1495 } | |
1496 | |
1497 assert (argument_count () > 0); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1498 if (unique) |
14945 | 1499 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1500 replace_with (unique); |
14945 | 1501 return true; |
1502 } | |
1503 | |
1504 return false; | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1505 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1506 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1507 bool |
14945 | 1508 jit_phi::infer (void) |
1509 { | |
1510 jit_block *p = parent (); | |
1511 if (! p->alive ()) | |
1512 return false; | |
1513 | |
1514 jit_type *infered = 0; | |
1515 for (size_t i = 0; i < argument_count (); ++i) | |
1516 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1517 jit_block *inc = incomming (i); |
14945 | 1518 if (inc->branch_alive (p)) |
1519 infered = jit_typeinfo::join (infered, argument_type (i)); | |
1520 } | |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1521 |
14945 | 1522 if (infered != type ()) |
1523 { | |
1524 stash_type (infered); | |
1525 return true; | |
1526 } | |
1527 | |
1528 return false; | |
1529 } | |
1530 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1531 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
|
1532 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
|
1533 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1534 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
|
1535 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1536 |
14945 | 1537 // -------------------- jit_terminator -------------------- |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1538 size_t |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1539 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
|
1540 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1541 size_t scount = successor_count (); |
14945 | 1542 for (size_t i = 0; i < scount; ++i) |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1543 if (successor (i) == asuccessor) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1544 return i; |
14945 | 1545 |
1546 panic_impossible (); | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1547 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1548 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1549 bool |
14945 | 1550 jit_terminator::infer (void) |
1551 { | |
1552 if (! parent ()->alive ()) | |
1553 return false; | |
1554 | |
1555 bool changed = false; | |
1556 for (size_t i = 0; i < malive.size (); ++i) | |
1557 if (! malive[i] && check_alive (i)) | |
1558 { | |
1559 changed = true; | |
1560 malive[i] = true; | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1561 successor (i)->mark_alive (); |
14945 | 1562 } |
1563 | |
1564 return changed; | |
1565 } | |
1566 | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1567 llvm::TerminatorInst * |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1568 jit_terminator::to_llvm (void) const |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1569 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1570 return llvm::cast<llvm::TerminatorInst> (jit_value::to_llvm ()); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1571 } |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
1572 |
14945 | 1573 // -------------------- jit_call -------------------- |
1574 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1575 jit_call::infer (void) |
14903 | 1576 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1577 // FIXME: explain algorithm |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1578 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
|
1579 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1580 already_infered[i] = argument_type (i); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1581 if (! already_infered[i]) |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1582 return false; |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1583 } |
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1584 |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1585 jit_type *infered = mfunction.get_result (already_infered); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1586 if (! infered && use_count ()) |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1587 { |
14922
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1588 std::stringstream ss; |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1589 ss << "Missing overload in type inference for "; |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1590 print (ss, 0); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1591 fail (ss.str ()); |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1592 } |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1593 |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1594 if (infered != type ()) |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1595 { |
2e6f83b2f2b9
Cleanup of some type inference functions
Max Brister <max@2bass.com>
parents:
14920
diff
changeset
|
1596 stash_type (infered); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1597 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1598 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1599 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1600 return false; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1601 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1602 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1603 // -------------------- jit_convert -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1604 jit_convert::jit_convert (llvm::Module *module, tree &tee) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1605 : iterator_count (0), breaking (false) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1606 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1607 jit_instruction::reset_ids (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1608 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1609 entry_block = create<jit_block> ("body"); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1610 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
|
1611 append (entry_block); |
14945 | 1612 entry_block->mark_alive (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1613 block = entry_block; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1614 visit (tee); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1615 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1616 // 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
|
1617 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1618 assert (breaks.empty ()); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1619 assert (continues.empty ()); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1620 |
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
|
1621 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
|
1622 append (final_block); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1623 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1624 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
|
1625 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1626 jit_variable *var = iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1627 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
|
1628 if (name.size () && name[0] != '#') |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1629 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
|
1630 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1631 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1632 construct_ssa (); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1633 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1634 // 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
|
1635 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
|
1636 iter != constants.end (); ++iter) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1637 append_users (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1638 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1639 // FIXME: Describe algorithm here |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1640 while (worklist.size ()) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1641 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1642 jit_instruction *next = worklist.front (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1643 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
|
1644 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
|
1645 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1646 if (next->infer ()) |
14945 | 1647 { |
1648 // terminators need to be handles specially | |
1649 if (jit_terminator *term = dynamic_cast<jit_terminator *> (next)) | |
1650 append_users_term (term); | |
1651 else | |
1652 append_users (next); | |
1653 } | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1654 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1655 |
14945 | 1656 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
|
1657 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
|
1658 final_block->label (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1659 place_releases (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1660 simplify_phi (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
1661 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1662 #ifdef OCTAVE_JIT_DEBUG |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
1663 final_block->label (); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1664 std::cout << "-------------------- Compiling tree --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1665 std::cout << tee.str_print_code () << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1666 print_blocks ("octave jit ir"); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1667 #endif |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1668 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1669 // 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
|
1670 // more interesting |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1671 for (jit_block::iterator iter = entry_block->begin (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1672 iter != entry_block->end (); ++iter) |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1673 if (jit_extract_argument *extract |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1674 = 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
|
1675 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
|
1676 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
1677 convert_llvm to_llvm (*this); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1678 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
|
1679 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1680 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1681 std::cout << "-------------------- llvm ir --------------------"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1682 llvm::raw_os_ostream llvm_cout (std::cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1683 function->print (llvm_cout); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1684 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1685 llvm::verifyFunction (*function); |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
1686 #endif |
14906 | 1687 } |
1688 | |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1689 jit_convert::~jit_convert (void) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1690 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1691 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
|
1692 iter != all_values.end (); ++iter) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1693 delete *iter; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1694 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1695 |
14906 | 1696 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1697 jit_convert::visit_anon_fcn_handle (tree_anon_fcn_handle&) |
14903 | 1698 { |
1699 fail (); | |
1700 } | |
1701 | |
1702 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1703 jit_convert::visit_argument_list (tree_argument_list&) |
14903 | 1704 { |
1705 fail (); | |
1706 } | |
1707 | |
1708 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1709 jit_convert::visit_binary_expression (tree_binary_expression& be) |
14903 | 1710 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1711 if (be.op_type () >= octave_value::num_binary_ops) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1712 // this is the case for bool_or and bool_and |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1713 fail (); |
14903 | 1714 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1715 tree_expression *lhs = be.lhs (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1716 jit_value *lhsv = visit (lhs); |
14903 | 1717 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1718 tree_expression *rhs = be.rhs (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1719 jit_value *rhsv = visit (rhs); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1720 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1721 const jit_function& fn = jit_typeinfo::binary_op (be.op_type ()); |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
1722 result = create_checked (fn, lhsv, rhsv); |
14903 | 1723 } |
1724 | |
1725 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1726 jit_convert::visit_break_command (tree_break_command&) |
14903 | 1727 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1728 breaks.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1729 breaking = true; |
14903 | 1730 } |
1731 | |
1732 void | |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1733 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
|
1734 { |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1735 // 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
|
1736 jit_value *base = visit (expr.base ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1737 jit_value *limit = visit (expr.limit ()); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1738 jit_value *increment; |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1739 tree_expression *tinc = expr.increment (); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1740 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1741 if (tinc) |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1742 increment = visit (tinc); |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1743 else |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1744 increment = create<jit_const_scalar> (1); |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1745 |
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
1746 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
|
1747 limit, increment)); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1748 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1749 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1750 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1751 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
|
1752 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1753 continues.push_back (block); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1754 breaking = true; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1755 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1756 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1757 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1758 jit_convert::visit_global_command (tree_global_command&) |
14903 | 1759 { |
1760 fail (); | |
1761 } | |
1762 | |
1763 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1764 jit_convert::visit_persistent_command (tree_persistent_command&) |
14903 | 1765 { |
1766 fail (); | |
1767 } | |
1768 | |
1769 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1770 jit_convert::visit_decl_elt (tree_decl_elt&) |
14903 | 1771 { |
1772 fail (); | |
1773 } | |
1774 | |
1775 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1776 jit_convert::visit_decl_init_list (tree_decl_init_list&) |
14903 | 1777 { |
1778 fail (); | |
1779 } | |
1780 | |
1781 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1782 jit_convert::visit_simple_for_command (tree_simple_for_command& cmd) |
14903 | 1783 { |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1784 // 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
|
1785 // 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
|
1786 // 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
|
1787 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1788 // 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
|
1789 assert (! breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1790 unwind_protect prot; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1791 prot.protect_var (breaks); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1792 prot.protect_var (continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1793 prot.protect_var (breaking); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1794 breaks.clear (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1795 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1796 // 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
|
1797 std::stringstream ss; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1798 ss << "#iter" << iterator_count++; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1799 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
|
1800 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
|
1801 vmap[iter_name] = iterator; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1802 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1803 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
|
1804 append (body); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1805 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1806 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
|
1807 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1808 // 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
|
1809 jit_value *control = visit (cmd.control_expr ()); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1810 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
|
1811 block->append (init_iter); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1812 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
|
1813 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1814 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
|
1815 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
|
1816 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
|
1817 block = body; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1818 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1819 // compute the syntactical iterator |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1820 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
|
1821 iterator); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1822 block->append (idx_rhs); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
1823 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
|
1824 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1825 // do loop |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1826 tree_statement_list *pt_body = cmd.body (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1827 pt_body->accept (*this); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1828 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1829 if (breaking && continues.empty ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1830 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1831 // 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
|
1832 // 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
|
1833 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
|
1834 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1835 block = tail; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1836 return; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1837 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1838 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1839 // 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
|
1840 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
|
1841 append (check_block); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1842 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1843 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
|
1844 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
|
1845 finish_breaks (check_block, continues); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1846 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1847 block = check_block; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1848 const jit_function& 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
|
1849 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
|
1850 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
|
1851 block->append (iter_inc); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
1852 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
|
1853 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
|
1854 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
|
1855 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
|
1856 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1857 // 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
|
1858 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1859 finish_breaks (tail, breaks); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
1860 block = tail; |
14903 | 1861 } |
1862 | |
1863 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1864 jit_convert::visit_complex_for_command (tree_complex_for_command&) |
14903 | 1865 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1866 fail (); |
14903 | 1867 } |
1868 | |
1869 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1870 jit_convert::visit_octave_user_script (octave_user_script&) |
14903 | 1871 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1872 fail (); |
14903 | 1873 } |
1874 | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14913
diff
changeset
|
1875 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1876 jit_convert::visit_octave_user_function (octave_user_function&) |
14903 | 1877 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1878 fail (); |
14899 | 1879 } |
1880 | |
14903 | 1881 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1882 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
|
1883 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1884 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1885 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1886 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1887 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1888 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
|
1889 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1890 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1891 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1892 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1893 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1894 jit_convert::visit_function_def (tree_function_def&) |
14899 | 1895 { |
14903 | 1896 fail (); |
1897 } | |
14899 | 1898 |
14903 | 1899 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1900 jit_convert::visit_identifier (tree_identifier& ti) |
14903 | 1901 { |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
1902 result = get_variable (ti.name ()); |
14899 | 1903 } |
1904 | |
1905 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
1906 jit_convert::visit_if_clause (tree_if_clause&) |
14903 | 1907 { |
1908 fail (); | |
14899 | 1909 } |
1910 | |
1911 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1912 jit_convert::visit_if_command (tree_if_command& cmd) |
14903 | 1913 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1914 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
|
1915 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
|
1916 lst->accept (*this); |
14903 | 1917 } |
1918 | |
1919 void | |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1920 jit_convert::visit_if_command_list (tree_if_command_list& lst) |
14903 | 1921 { |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1922 tree_if_clause *last = lst.back (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1923 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
|
1924 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1925 // 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
|
1926 // 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
|
1927 // 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
|
1928 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
|
1929 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
|
1930 entry_blocks[0] = block; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1931 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1932 // 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
|
1933 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
|
1934 ++iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1935 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
|
1936 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1937 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1938 if (tic->is_else_clause ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1939 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
|
1940 else |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1941 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
|
1942 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1943 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
1944 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
|
1945 if (! last_else) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1946 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
|
1947 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1948 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
|
1949 iter = lst.begin (); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1950 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
|
1951 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1952 tree_if_clause *tic = *iter; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1953 block = entry_blocks[i]; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1954 assert (block); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1955 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1956 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
|
1957 append (entry_blocks[i]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1958 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1959 if (! tic->is_else_clause ()) |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1960 { |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1961 tree_expression *expr = tic->condition (); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1962 jit_value *cond = visit (expr); |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
1963 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
|
1964 cond); |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
1965 block->append (check); |
14943
8efcaf5aa233
Prevent crash when using scalars as conditionals
Max Brister <max@2bass.com>
parents:
14941
diff
changeset
|
1966 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
1967 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
|
1968 : "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
|
1969 append (body); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1970 |
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
|
1971 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
|
1972 entry_blocks[i + 1]); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1973 block->append (br); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1974 block = body; |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1975 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1976 |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1977 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
|
1978 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
|
1979 stmt_lst->accept (*this); |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1980 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1981 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1982 breaking = false; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1983 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1984 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1985 ++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
|
1986 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
|
1987 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1988 } |
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1989 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1990 if (num_incomming || ! last_else) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1991 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
1992 append (tail); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1993 block = tail; |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
1994 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1995 else |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
1996 // 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
|
1997 breaking = true; |
14903 | 1998 } |
1999 | |
2000 void | |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2001 jit_convert::visit_index_expression (tree_index_expression& exp) |
14903 | 2002 { |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2003 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
|
2004 jit_value *object = res.first; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2005 jit_value *index = res.second; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2006 |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
2007 result = create_checked (jit_typeinfo::paren_subsref, object, index); |
14903 | 2008 } |
2009 | |
2010 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2011 jit_convert::visit_matrix (tree_matrix&) |
14899 | 2012 { |
2013 fail (); | |
2014 } | |
2015 | |
2016 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2017 jit_convert::visit_cell (tree_cell&) |
14906 | 2018 { |
2019 fail (); | |
2020 } | |
2021 | |
2022 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2023 jit_convert::visit_multi_assignment (tree_multi_assignment&) |
14899 | 2024 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2025 fail (); |
14903 | 2026 } |
2027 | |
2028 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2029 jit_convert::visit_no_op_command (tree_no_op_command&) |
14906 | 2030 { |
2031 fail (); | |
2032 } | |
2033 | |
2034 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2035 jit_convert::visit_constant (tree_constant& tc) |
14903 | 2036 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2037 octave_value v = tc.rvalue1 (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2038 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
|
2039 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2040 double dv = v.double_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2041 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
|
2042 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2043 else if (v.is_range ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2044 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2045 Range rv = v.range_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2046 result = create<jit_const_range> (rv); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2047 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2048 else |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2049 fail ("Unknown constant"); |
14903 | 2050 } |
14899 | 2051 |
14903 | 2052 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2053 jit_convert::visit_fcn_handle (tree_fcn_handle&) |
14903 | 2054 { |
2055 fail (); | |
2056 } | |
14899 | 2057 |
14903 | 2058 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2059 jit_convert::visit_parameter_list (tree_parameter_list&) |
14906 | 2060 { |
2061 fail (); | |
2062 } | |
2063 | |
2064 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2065 jit_convert::visit_postfix_expression (tree_postfix_expression&) |
14903 | 2066 { |
2067 fail (); | |
2068 } | |
14899 | 2069 |
14903 | 2070 void |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2071 jit_convert::visit_prefix_expression (tree_prefix_expression&) |
14899 | 2072 { |
2073 fail (); | |
2074 } | |
2075 | |
2076 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2077 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
|
2078 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2079 fail (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2080 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2081 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2082 void |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2083 jit_convert::visit_return_list (tree_return_list&) |
14899 | 2084 { |
2085 fail (); | |
2086 } | |
2087 | |
2088 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2089 jit_convert::visit_simple_assignment (tree_simple_assignment& tsa) |
14899 | 2090 { |
14953 | 2091 if (tsa.op_type () != octave_value::op_asn_eq) |
2092 fail ("Unsupported assign"); | |
2093 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2094 // resolve rhs |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2095 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
|
2096 jit_value *rhsv = visit (rhs); |
14899 | 2097 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2098 do_assign (tsa.left_hand_side (), rhsv); |
14899 | 2099 } |
2100 | |
2101 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2102 jit_convert::visit_statement (tree_statement& stmt) |
14899 | 2103 { |
2104 tree_command *cmd = stmt.command (); | |
2105 tree_expression *expr = stmt.expression (); | |
2106 | |
2107 if (cmd) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2108 visit (cmd); |
14899 | 2109 else |
2110 { | |
2111 // stolen from tree_evaluator::visit_statement | |
2112 bool do_bind_ans = false; | |
2113 | |
2114 if (expr->is_identifier ()) | |
2115 { | |
2116 tree_identifier *id = dynamic_cast<tree_identifier *> (expr); | |
2117 | |
2118 do_bind_ans = (! id->is_variable ()); | |
2119 } | |
2120 else | |
2121 do_bind_ans = (! expr->is_assignment_expression ()); | |
2122 | |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2123 jit_value *expr_result = visit (expr); |
14899 | 2124 |
2125 if (do_bind_ans) | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2126 do_assign ("ans", expr_result, expr->print_result ()); |
14899 | 2127 else if (expr->is_identifier () && expr->print_result ()) |
2128 { | |
2129 // FIXME: ugly hack, we need to come up with a way to pass | |
2130 // nargout to visit_identifier | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2131 const jit_function& fn = jit_typeinfo::print_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2132 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
|
2133 block->append (create<jit_call> (fn, name, expr_result)); |
14899 | 2134 } |
2135 } | |
2136 } | |
2137 | |
2138 void | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2139 jit_convert::visit_statement_list (tree_statement_list& lst) |
14906 | 2140 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2141 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
|
2142 ++iter) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2143 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2144 tree_statement *elt = *iter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2145 // jwe: Can this ever be null? |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2146 assert (elt); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2147 elt->accept (*this); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2148 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2149 if (breaking) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2150 break; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2151 } |
14906 | 2152 } |
2153 | |
2154 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2155 jit_convert::visit_switch_case (tree_switch_case&) |
14906 | 2156 { |
2157 fail (); | |
2158 } | |
2159 | |
2160 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2161 jit_convert::visit_switch_case_list (tree_switch_case_list&) |
14899 | 2162 { |
2163 fail (); | |
2164 } | |
2165 | |
2166 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2167 jit_convert::visit_switch_command (tree_switch_command&) |
14906 | 2168 { |
2169 fail (); | |
2170 } | |
2171 | |
2172 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2173 jit_convert::visit_try_catch_command (tree_try_catch_command&) |
14899 | 2174 { |
2175 fail (); | |
2176 } | |
2177 | |
2178 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2179 jit_convert::visit_unwind_protect_command (tree_unwind_protect_command&) |
14899 | 2180 { |
2181 fail (); | |
2182 } | |
2183 | |
2184 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2185 jit_convert::visit_while_command (tree_while_command&) |
14906 | 2186 { |
2187 fail (); | |
2188 } | |
2189 | |
2190 void | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2191 jit_convert::visit_do_until_command (tree_do_until_command&) |
14899 | 2192 { |
2193 fail (); | |
2194 } | |
2195 | |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2196 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2197 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
|
2198 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2199 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
|
2200 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
|
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 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2203 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2204 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
|
2205 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2206 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
|
2207 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
|
2208 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2209 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2210 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2211 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
|
2212 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2213 ++iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2214 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
|
2215 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2216 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2217 jit_variable * |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2218 jit_convert::get_variable (const std::string& vname) |
14899 | 2219 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2220 vmap_t::iterator iter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2221 iter = vmap.find (vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2222 if (iter != vmap.end ()) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2223 return iter->second; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2224 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2225 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
|
2226 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
|
2227 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
|
2228 jit_extract_argument *extract; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2229 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
|
2230 entry_block->prepend (extract); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2231 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2232 return vmap[vname] = var; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2233 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2234 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2235 std::pair<jit_value *, jit_value *> |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2236 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
|
2237 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2238 std::string type = exp.type_tags (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2239 if (! (type.size () == 1 && type[0] == '(')) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2240 fail ("Unsupported index operation"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2241 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2242 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
|
2243 if (args.size () != 1) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2244 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
|
2245 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2246 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
|
2247 if (! arg_list) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2248 fail ("null argument list"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2249 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2250 if (arg_list->size () != 1) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2251 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
|
2252 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2253 tree_expression *tree_object = exp.expression (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2254 jit_value *object = visit (tree_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2255 tree_expression *arg0 = arg_list->front (); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2256 jit_value *index = visit (arg0); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2257 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2258 return std::make_pair (object, index); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2259 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2260 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2261 jit_value * |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2262 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
|
2263 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2264 if (! exp) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2265 fail ("NULL lhs in assign"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2266 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2267 if (isa<tree_identifier> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2268 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
|
2269 else if (tree_index_expression *idx |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2270 = dynamic_cast<tree_index_expression *> (exp)) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2271 { |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2272 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
|
2273 jit_value *object = res.first; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2274 jit_value *index = res.second; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2275 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
|
2276 object, index, rhs); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2277 block->append (new_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2278 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
|
2279 create_check (new_object); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2280 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2281 // 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
|
2282 return rhs; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2283 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2284 else |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2285 fail ("Unsupported assignment"); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2286 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2287 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2288 jit_value * |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2289 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
|
2290 bool print, bool artificial) |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2291 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2292 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
|
2293 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
|
2294 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2295 if (artificial) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2296 assign->mark_artificial (); |
14906 | 2297 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2298 if (print) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2299 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2300 const jit_function& print_fn = jit_typeinfo::print_value (); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2301 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
|
2302 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
|
2303 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2304 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2305 return var; |
14917
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 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2308 jit_value * |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2309 jit_convert::visit (tree& tee) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2310 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2311 result = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2312 tee.accept (*this); |
14906 | 2313 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2314 jit_value *ret = result; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2315 result = 0; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2316 return ret; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2317 } |
14906 | 2318 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2319 void |
14945 | 2320 jit_convert::append_users_term (jit_terminator *term) |
2321 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2322 for (size_t i = 0; i < term->successor_count (); ++i) |
14945 | 2323 { |
2324 if (term->alive (i)) | |
2325 { | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2326 jit_block *succ = term->successor (i); |
14945 | 2327 for (jit_block::iterator iter = succ->begin (); iter != succ->end () |
2328 && 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
|
2329 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
|
2330 |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2331 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
|
2332 if (sterm) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
2333 push_worklist (sterm); |
14945 | 2334 } |
2335 } | |
2336 } | |
2337 | |
2338 void | |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2339 jit_convert::merge_blocks (void) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2340 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2341 std::vector<jit_block *> dead; |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2342 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
|
2343 ++iter) |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2344 { |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2345 jit_block *b = *iter; |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2346 jit_block *merged = b->maybe_merge (); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2347 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2348 if (merged) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2349 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2350 if (merged == final_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2351 final_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2352 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2353 if (merged == entry_block) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2354 entry_block = b; |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2355 |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2356 dead.push_back (merged); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2357 } |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2358 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2359 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2360 for (size_t i = 0; i < dead.size (); ++i) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2361 blocks.erase (dead[i]->location ()); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2362 } |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2363 |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2364 void |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2365 jit_convert::construct_ssa (void) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2366 { |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2367 merge_blocks (); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2368 final_block->label (); |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
2369 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
|
2370 entry_block->compute_df (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2371 entry_block->create_dom_tree (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2372 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2373 // 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
|
2374 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
|
2375 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2376 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
|
2377 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
|
2378 iter->second->use_blocks (visited); |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2379 ssa_worklist.insert (ssa_worklist.begin (), visited.begin (), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2380 visited.end ()); |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2381 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2382 while (ssa_worklist.size ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2383 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2384 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
|
2385 ssa_worklist.pop_front (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2386 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2387 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
|
2388 diter != b->df_end (); ++diter) |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2389 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2390 jit_block *dblock = *diter; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2391 if (! added_phi.count (dblock)) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2392 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2393 jit_phi *phi = create<jit_phi> (iter->second, |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2394 dblock->use_count ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2395 dblock->prepend (phi); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2396 added_phi.insert (dblock); |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2397 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14924
diff
changeset
|
2398 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2399 if (! visited.count (dblock)) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2400 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2401 ssa_worklist.push_back (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2402 visited.insert (dblock); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2403 } |
14923
168cb10bb9c5
If, ifelse, and else statements JIT compile now
Max Brister <max@2bass.com>
parents:
14922
diff
changeset
|
2404 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2405 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2406 } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2407 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2408 entry_block->visit_dom (&jit_convert::do_construct_ssa, &jit_block::pop_all); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2409 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2410 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2411 void |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2412 jit_convert::do_construct_ssa (jit_block& block) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2413 { |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2414 // replace variables with their current SSA value |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2415 for (jit_block::iterator iter = block.begin (); iter != block.end (); ++iter) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2416 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2417 jit_instruction *instr = *iter; |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2418 instr->construct_ssa (); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2419 instr->push_variable (); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2420 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2421 |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2422 // finish phi nodes of successors |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2423 for (size_t i = 0; i < block.successor_count (); ++i) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2424 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2425 jit_block *finish = block.successor (i); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2426 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2427 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
|
2428 && isa<jit_phi> (*iter);) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2429 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2430 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
|
2431 jit_variable *var = phi->dest (); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2432 if (var->has_top ()) |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2433 { |
14945 | 2434 phi->add_incomming (&block, var->top ()); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2435 ++iter; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2436 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2437 else |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2438 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2439 // 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
|
2440 assert (! phi->use_count ()); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2441 assert (var->name ().size () && var->name ()[0] == '#'); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2442 iter = finish->remove (iter); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2443 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2444 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2445 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2446 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2447 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2448 void |
14945 | 2449 jit_convert::remove_dead () |
2450 { | |
2451 block_list::iterator biter; | |
2452 for (biter = blocks.begin (); biter != blocks.end (); ++biter) | |
2453 { | |
2454 jit_block *b = *biter; | |
2455 if (b->alive ()) | |
2456 { | |
2457 for (jit_block::iterator iter = b->begin (); iter != b->end () | |
2458 && isa<jit_phi> (*iter);) | |
2459 { | |
2460 jit_phi *phi = static_cast<jit_phi *> (*iter); | |
2461 if (phi->prune ()) | |
2462 iter = b->remove (iter); | |
2463 else | |
2464 ++iter; | |
2465 } | |
2466 } | |
2467 } | |
2468 | |
2469 for (biter = blocks.begin (); biter != blocks.end ();) | |
2470 { | |
2471 jit_block *b = *biter; | |
2472 if (b->alive ()) | |
2473 { | |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
2474 // FIXME: A special case for jit_error_check, if we generalize to |
14945 | 2475 // we will need to change! |
2476 jit_terminator *term = b->terminator (); | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2477 if (term && term->successor_count () == 2 && ! term->alive (0)) |
14945 | 2478 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2479 jit_block *succ = term->successor (1); |
14945 | 2480 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
|
2481 jit_branch *abreak = b->append (create<jit_branch> (succ)); |
14945 | 2482 abreak->infer (); |
2483 } | |
2484 | |
2485 ++biter; | |
2486 } | |
2487 else | |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2488 { |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2489 jit_terminator *term = b->terminator (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2490 if (term) |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2491 term->remove (); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2492 biter = blocks.erase (biter); |
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2493 } |
14945 | 2494 } |
2495 } | |
2496 | |
2497 void | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2498 jit_convert::place_releases (void) |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2499 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2500 compute_temp tinfo (*this); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2501 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2502 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
|
2503 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2504 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2505 jit_block& ablock = **iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2506 if (ablock.id () != jit_block::NO_ID) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2507 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2508 release_temp (ablock, tinfo.temp_out (ablock)); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2509 release_dead_phi (ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2510 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2511 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2512 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2513 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2514 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2515 void |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2516 jit_convert::release_temp (jit_block& ablock, const instr_set& temp) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2517 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2518 if (! temp.size ()) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2519 return; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2520 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2521 jit_block *split = ablock.maybe_split (*this, final_block); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2522 jit_terminator *term = split->terminator (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2523 for (instr_set::const_iterator iter = temp.begin (); iter != temp.end (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2524 ++iter) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2525 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2526 jit_instruction *instr = *iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2527 jit_call *release = create<jit_call> (&jit_typeinfo::release, instr); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2528 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2529 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2530 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2531 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2532 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2533 void |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2534 jit_convert::release_dead_phi (jit_block& ablock) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2535 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2536 jit_block::iterator iter = ablock.begin (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2537 while (iter != ablock.end () && isa<jit_phi> (*iter)) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2538 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2539 jit_phi *phi = static_cast<jit_phi *> (*iter); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2540 ++iter; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2541 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2542 jit_use *use = phi->first_use (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2543 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
|
2544 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2545 // 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
|
2546 // this can get rid of casts inside loops |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2547 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
|
2548 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2549 jit_value *arg = phi->argument (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2550 jit_block *inc = phi->incomming (i); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2551 jit_block *split = inc->maybe_split (*this, ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2552 jit_terminator *term = split->terminator (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2553 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
|
2554 release->infer (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2555 split->insert_before (term, release); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2556 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2557 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2558 phi->replace_with (0); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2559 phi->remove (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2560 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2561 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2562 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2563 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2564 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2565 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
|
2566 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2567 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
|
2568 ++biter) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2569 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2570 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
|
2571 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
|
2572 && 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
|
2573 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
|
2574 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2575 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2576 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2577 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2578 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
|
2579 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2580 jit_block& pblock = *phi.parent (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2581 const jit_function& cast_fn = jit_typeinfo::cast (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
|
2582 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
|
2583 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
|
2584 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2585 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
|
2586 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
|
2587 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2588 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
|
2589 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
|
2590 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
|
2591 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
|
2592 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
|
2593 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2594 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
|
2595 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
|
2596 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
|
2597 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
|
2598 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
|
2599 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2600 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2601 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2602 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2603 void |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2604 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
|
2605 { |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2606 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
|
2607 ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2608 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2609 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
|
2610 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
|
2611 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2612 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2613 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2614 // -------------------- jit_convert::compute_temp -------------------- |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2615 jit_convert::compute_temp::compute_temp (jit_convert& aconvert) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2616 : convert (aconvert), mtemp_out (aconvert.final_block->id () + 1) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2617 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2618 block_list& blocks = convert.blocks; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2619 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2620 // initialze mtemp_out |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2621 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
|
2622 ++biter) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2623 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2624 jit_block& block = **biter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2625 instr_set& tout = temp_out (block); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2626 for (jit_block::iterator iter = block.begin (); iter != block.end (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2627 ++iter) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2628 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2629 jit_instruction *instr = *iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2630 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2631 // check for temporaries that require release and live across |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2632 // multiple blocks |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2633 if (instr->needs_release () |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2634 && instr->use_count () >= 1) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2635 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2636 bool parent_in_block = false; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2637 jit_use *use = instr->first_use (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2638 while (use) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2639 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2640 // skip error checks, as they do not release their use |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2641 if (! isa<jit_error_check> (use->user ()) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2642 && use->user_parent () == &block) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2643 { |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2644 parent_in_block = true; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2645 break; |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2646 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2647 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2648 use = use->next (); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2649 } |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2650 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2651 if (! parent_in_block) |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2652 tout.insert (instr); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2653 } |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2654 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2655 if (isa<jit_call> (instr)) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2656 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2657 // place releases for temporary arguments |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2658 for (size_t i = 0; i < instr->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
|
2659 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2660 jit_value *arg = instr->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
|
2661 if (arg->needs_release ()) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2662 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2663 jit_call *release |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2664 = convert.create<jit_call> (&jit_typeinfo::release, |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2665 arg); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2666 release->infer (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2667 block.insert_after (iter, release); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2668 ++iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2669 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2670 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2671 } |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2672 } |
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 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2674 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2675 do |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2676 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2677 changed = false; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2678 convert.entry_block->visit_dom (*this, 0); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2679 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2680 while (changed); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2681 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2682 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2683 void |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2684 jit_convert::compute_temp::operator() (jit_block& block) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2685 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2686 instr_set& tout = temp_out (block); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2687 for (jit_use *use = block.first_use (); use; use = use->next ()) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2688 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2689 jit_block& pred = *use->user_parent (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2690 instr_set& pred_tout = temp_out (pred); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2691 for (instr_set::iterator iter = pred_tout.begin (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2692 iter != pred_tout.end (); ++ iter) |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2693 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2694 jit_instruction *instr = *iter; |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2695 jit_block *use_in = instr->parent (); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2696 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2697 // FIXME: Only valid until we support try/catch or unwind_protect |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2698 if (use_in != &block && &block != convert.final_block) |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2699 changed = changed || tout.insert (instr).second; |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2700 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2701 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2702 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2703 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2704 // -------------------- jit_convert::convert_llvm -------------------- |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2705 llvm::Function * |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2706 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
|
2707 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
|
2708 const std::list<jit_block *>& blocks, |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2709 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
|
2710 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2711 jit_type *any = jit_typeinfo::get_any (); |
14899 | 2712 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2713 // 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
|
2714 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
|
2715 arg_type = arg_type->getPointerTo (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2716 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
|
2717 arg_type, false); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2718 function = llvm::Function::Create (ft, llvm::Function::ExternalLinkage, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2719 "foobar", module); |
14906 | 2720 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2721 try |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2722 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
2723 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
|
2724 builder.SetInsertPoint (prelude); |
14906 | 2725 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2726 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
|
2727 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
|
2728 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2729 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
|
2730 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
|
2731 } |
14906 | 2732 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2733 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
|
2734 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
|
2735 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2736 jit_block *jblock = *biter; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2737 llvm::BasicBlock *block = llvm::BasicBlock::Create (context, |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2738 jblock->name (), |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2739 function); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2740 jblock->stash_llvm (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2741 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2742 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2743 jit_block *first = *blocks.begin (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2744 builder.CreateBr (first->to_llvm ()); |
14906 | 2745 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2746 // 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
|
2747 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
|
2748 iter != constants.end (); ++iter) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2749 if (! isa<jit_instruction> (*iter)) |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2750 visit (*iter); |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
2751 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2752 // convert all instructions |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2753 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
|
2754 visit (*biter); |
14906 | 2755 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2756 // now finish phi nodes |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2757 for (biter = blocks.begin (); biter != blocks.end (); ++biter) |
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 jit_block& block = **biter; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2760 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
|
2761 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
|
2762 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2763 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
|
2764 finish_phi (static_cast<jit_phi *> (phi)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2765 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2766 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2767 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2768 jit_block *last = blocks.back (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2769 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
|
2770 builder.CreateRetVoid (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2771 } 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
|
2772 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2773 function->eraseFromParent (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2774 throw; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2775 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2776 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2777 return function; |
14899 | 2778 } |
2779 | |
2780 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
|
2781 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
|
2782 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2783 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
|
2784 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
|
2785 { |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
2786 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
|
2787 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
|
2788 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2789 } |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2790 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
2791 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2792 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
|
2793 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2794 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
|
2795 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2796 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2797 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2798 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
|
2799 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2800 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
|
2801 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2802 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2803 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
|
2804 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2805 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
|
2806 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2807 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2808 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2809 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
|
2810 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2811 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
|
2812 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
|
2813 llvm::Type *idx = jit_typeinfo::get_index_llvm (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2814 const jit_range& rng = cr.value (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2815 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2816 llvm::Constant *constants[4]; |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2817 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
|
2818 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
|
2819 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
|
2820 constants[3] = llvm::ConstantInt::get (idx, rng.nelem); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2821 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2822 llvm::Value *as_llvm; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2823 as_llvm = llvm::ConstantStruct::get (stype, |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2824 llvm::makeArrayRef (constants, 4)); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2825 cr.stash_llvm (as_llvm); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2826 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2827 |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2828 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2829 jit_convert::convert_llvm::visit (jit_block& b) |
14899 | 2830 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2831 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
|
2832 builder.SetInsertPoint (block); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2833 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
|
2834 visit (*iter); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2835 } |
14903 | 2836 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2837 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
|
2838 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
|
2839 { |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2840 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
|
2841 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2842 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2843 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
|
2844 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
|
2845 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2846 llvm::Value *cond = cb.cond_llvm (); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2847 llvm::Value *br; |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2848 br = builder.CreateCondBr (cond, cb.successor_llvm (0), |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
2849 cb.successor_llvm (1)); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2850 cb.stash_llvm (br); |
14899 | 2851 } |
2852 | |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
2853 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2854 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
|
2855 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2856 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
|
2857 call.stash_llvm (ret); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
2858 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
2859 |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
2860 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2861 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
|
2862 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2863 llvm::Value *arg = arguments[extract.name ()]; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2864 assert (arg); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2865 arg = builder.CreateLoad (arg); |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2866 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2867 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
|
2868 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
|
2869 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2870 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
2871 void |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2872 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
|
2873 { |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2874 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
|
2875 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2876 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
|
2877 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
|
2878 } |
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
2879 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2880 void |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2881 jit_convert::convert_llvm::visit (jit_phi& phi) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2882 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2883 // 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
|
2884 // set incomming branches now |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2885 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
|
2886 phi.argument_count ()); |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2887 builder.Insert (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2888 phi.stash_llvm (node); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2889 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
2890 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2891 void |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2892 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
|
2893 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2894 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
|
2895 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14925
diff
changeset
|
2896 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2897 void |
14960
c959136f8c3e
Rename jit_check_error to jit_error_check
Max Brister <max@2bass.com>
parents:
14959
diff
changeset
|
2898 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
|
2899 { |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2900 llvm::Value *cond = jit_typeinfo::insert_error_check (); |
14948
006570a76b90
Cleanup and optimization of JIT
Max Brister <max@2bass.com>
parents:
14946
diff
changeset
|
2901 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
|
2902 check.successor_llvm (1)); |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2903 check.stash_llvm (br); |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2904 } |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2905 |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2906 void |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2907 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
|
2908 { |
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2909 assign.stash_llvm (assign.src ()->to_llvm ()); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2910 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2911 if (assign.artificial ()) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2912 return; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
2913 |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2914 jit_value *new_value = assign.src (); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2915 if (isa<jit_assign_base> (new_value)) |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2916 { |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2917 const jit_function::overload& ol |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2918 = jit_typeinfo::get_grab (new_value->type ()); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2919 if (ol.function) |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
2920 assign.stash_llvm (create_call (ol, new_value)); |
14965
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2921 } |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2922 |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2923 jit_value *overwrite = assign.overwrite (); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2924 if (isa<jit_assign_base> (overwrite)) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2925 { |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2926 const jit_function::overload& ol |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2927 = jit_typeinfo::get_release (overwrite->type ()); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2928 if (ol.function) |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2929 create_call (ol, overwrite); |
f2117a963c54
Place grab/release for assignments
Max Brister <max@2bass.com>
parents:
14964
diff
changeset
|
2930 } |
14962
90a7a2af2cd5
Keep track of variables after SSA construction
Max Brister <max@2bass.com>
parents:
14961
diff
changeset
|
2931 } |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
2932 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2933 void |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2934 jit_convert::convert_llvm::visit (jit_argument&) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2935 {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2936 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2937 llvm::Value * |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2938 jit_convert::convert_llvm::create_call (const jit_function::overload& ol, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2939 const std::vector<jit_value *>& jargs) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2940 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
2941 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
|
2942 |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2943 llvm::Function *fun = ol.function; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2944 if (! fun) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2945 fail ("Missing overload"); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2946 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2947 const llvm::Function::ArgumentListType& alist = fun->getArgumentList (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2948 size_t nargs = alist.size (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2949 bool sret = false; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2950 if (nargs != jargs.size ()) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2951 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2952 // first argument is the structure return value |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2953 assert (nargs == jargs.size () + 1); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2954 sret = true; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2955 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2956 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2957 std::vector<llvm::Value *> args (nargs); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2958 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
|
2959 if (sret) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2960 { |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
2961 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
|
2962 ++llvm_arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2963 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2964 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2965 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
|
2966 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2967 llvm::Value *arg = jargs[i]->to_llvm (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2968 llvm::Type *arg_type = arg->getType (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2969 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
|
2970 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2971 if (arg_type == llvm_arg_type) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2972 args[i + sret] = arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2973 else |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2974 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2975 // pass structure by pointer |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2976 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
|
2977 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
|
2978 builder.CreateStore (arg, new_arg); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2979 args[i + sret] = new_arg; |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2980 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2981 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2982 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2983 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
|
2984 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
|
2985 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2986 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2987 llvm::Value * |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2988 jit_convert::convert_llvm::create_call (const jit_function::overload& ol, |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2989 const std::vector<jit_use>& uses) |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2990 { |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2991 std::vector<jit_value *> values (uses.size ()); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2992 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
|
2993 values[i] = uses[i].value (); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2994 |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2995 return create_call (ol, values); |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2996 } |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14949
diff
changeset
|
2997 |
14906 | 2998 // -------------------- tree_jit -------------------- |
2999 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3000 tree_jit::tree_jit (void) : module (0), engine (0) |
14906 | 3001 { |
3002 } | |
3003 | |
3004 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
|
3005 {} |
14906 | 3006 |
3007 bool | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3008 tree_jit::execute (tree_simple_for_command& cmd) |
14906 | 3009 { |
3010 if (! initialize ()) | |
3011 return false; | |
3012 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3013 jit_info *info = cmd.get_info (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3014 if (! info || ! info->match ()) |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3015 { |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3016 delete info; |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3017 info = new jit_info (*this, cmd); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3018 cmd.stash_info (info); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3019 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3020 |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3021 return info->execute (); |
14906 | 3022 } |
3023 | |
3024 bool | |
3025 tree_jit::initialize (void) | |
14903 | 3026 { |
14906 | 3027 if (engine) |
3028 return true; | |
3029 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3030 if (! module) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3031 { |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3032 llvm::InitializeNativeTarget (); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3033 module = new llvm::Module ("octave", context); |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3034 } |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3035 |
14906 | 3036 // sometimes this fails pre main |
3037 engine = llvm::ExecutionEngine::createJIT (module); | |
3038 | |
3039 if (! engine) | |
3040 return false; | |
3041 | |
3042 module_pass_manager = new llvm::PassManager (); | |
3043 module_pass_manager->add (llvm::createAlwaysInlinerPass ()); | |
3044 | |
3045 pass_manager = new llvm::FunctionPassManager (module); | |
3046 pass_manager->add (new llvm::TargetData(*engine->getTargetData ())); | |
3047 pass_manager->add (llvm::createBasicAliasAnalysisPass ()); | |
3048 pass_manager->add (llvm::createPromoteMemoryToRegisterPass ()); | |
3049 pass_manager->add (llvm::createInstructionCombiningPass ()); | |
3050 pass_manager->add (llvm::createReassociatePass ()); | |
3051 pass_manager->add (llvm::createGVNPass ()); | |
3052 pass_manager->add (llvm::createCFGSimplificationPass ()); | |
3053 pass_manager->doInitialization (); | |
3054 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3055 jit_typeinfo::initialize (module, engine); |
14906 | 3056 |
3057 return true; | |
3058 } | |
3059 | |
3060 | |
3061 void | |
3062 tree_jit::optimize (llvm::Function *fn) | |
3063 { | |
3064 module_pass_manager->run (*module); | |
3065 pass_manager->run (*fn); | |
3066 } | |
3067 | |
3068 // -------------------- jit_info -------------------- | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3069 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
|
3070 : engine (tjit.get_engine ()), llvm_function (0) |
14906 | 3071 { |
14903 | 3072 try |
3073 { | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3074 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
|
3075 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
|
3076 arguments = conv.get_arguments (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3077 bounds = conv.get_bounds (); |
14903 | 3078 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3079 catch (const jit_fail_exception& e) |
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3080 { |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3081 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3082 if (e.known ()) |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3083 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
|
3084 #endif |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
3085 } |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3086 |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3087 if (! llvm_function) |
14903 | 3088 { |
3089 function = 0; | |
3090 return; | |
3091 } | |
3092 | |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3093 tjit.optimize (llvm_function); |
14906 | 3094 |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3095 #ifdef OCTAVE_JIT_DEBUG |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3096 std::cout << "-------------------- optimized llvm ir --------------------\n"; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3097 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
|
3098 llvm_function->print (llvm_cout); |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3099 std::cout << std::endl; |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3100 #endif |
14903 | 3101 |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3102 void *void_fn = engine->getPointerToFunction (llvm_function); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
3103 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
|
3104 } |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3105 |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3106 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
|
3107 { |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3108 if (llvm_function) |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14954
diff
changeset
|
3109 llvm_function->eraseFromParent (); |
14903 | 3110 } |
3111 | |
3112 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3113 jit_info::execute (void) const |
14899 | 3114 { |
3115 if (! function) | |
3116 return false; | |
3117 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3118 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
|
3119 for (size_t i = 0; i < arguments.size (); ++i) |
14899 | 3120 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3121 if (arguments[i].second) |
14899 | 3122 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3123 octave_value current = symbol_table::varval (arguments[i].first); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3124 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
|
3125 obv->grab (); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3126 real_arguments[i] = obv; |
14899 | 3127 } |
3128 } | |
3129 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3130 function (&real_arguments[0]); |
14899 | 3131 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3132 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
|
3133 symbol_table::varref (arguments[i].first) = real_arguments[i]; |
14910
a8f1e08de8fc
Simplified llvm::GenericValue creation
Max Brister <max@2bass.com>
parents:
14906
diff
changeset
|
3134 |
14899 | 3135 return true; |
3136 } | |
14903 | 3137 |
3138 bool | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3139 jit_info::match (void) const |
14903 | 3140 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3141 if (! function) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3142 return true; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3143 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3144 for (size_t i = 0; i < bounds.size (); ++i) |
14903 | 3145 { |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3146 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
|
3147 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
|
3148 jit_type *type = jit_typeinfo::type_of (value); |
14906 | 3149 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3150 // 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
|
3151 if (type != bounds[i].first) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
3152 return false; |
14903 | 3153 } |
3154 | |
3155 return true; | |
3156 } | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
3157 #endif |