Mercurial > hg > octave-nkf
annotate src/pt-jit.h @ 15023:75d1bc2fd6d2
Compile top level while loops in JIT.
* src/pt-eval.cc (tree_evaluator::visit_while_command): Try compile while loops.
* src/pt-jit.cc (jit_convert::jit_convert): Add first terminator to worklist.
(tree_jit::execute): New overload.
* src/pt-jit.h (tree_jit::execute): New overload.
* src/pt-loop.cc (tree_while_command::~tree_while_command): Delete compiled.
(tree_simple_for_command::~tree_simple_for_command): Only delete compiled if JIT
is enabled.
* src/pt-loop.h (tree_while_command::get_info, tree_while_command::stash_info):
New function.
author | Max Brister <max@2bass.com> |
---|---|
date | Thu, 26 Jul 2012 12:17:56 -0500 |
parents | 005cb78e1dd1 |
children | 741d2dbcc117 |
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 #if !defined (octave_tree_jit_h) | |
24 #define octave_tree_jit_h 1 | |
25 | |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
26 #ifdef HAVE_LLVM |
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
27 |
15016
005cb78e1dd1
Split pt-jit into multiple files.
Max Brister <max@2bass.com>
parents:
15014
diff
changeset
|
28 #include "jit-ir.h" |
14899 | 29 |
30 #include "pt-walk.h" | |
31 | |
14903 | 32 // -------------------- Current status -------------------- |
33 // Simple binary operations (+-*/) on octave_scalar's (doubles) are optimized. | |
34 // a = 5; | |
35 // b = a * 5 + a; | |
36 // | |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
37 // Indexing matrices with scalars works. |
14906 | 38 // |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
39 // if, elseif, else, break, continue, and for compile. Compilation is triggered |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
40 // at the start of a simple for loop. |
14906 | 41 // |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
42 // The octave low level IR is a linear IR, it works by converting everything to |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14980
diff
changeset
|
43 // calls to jit_operations. This turns expressions like c = a + b into |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
44 // c = call binary+ (a, b) |
14983
a5f75de0dab1
Rename jit_function to jit_operation
Max Brister <max@2bass.com>
parents:
14980
diff
changeset
|
45 // The jit_operations contain information about overloads for different types. |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
46 // For, example, if we know a and b are scalars, then c must also be a scalar. |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
47 // |
14973 | 48 // Support for function calls is in progress. Currently, calls to sin with a |
49 // scalar argument will compile. | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
50 // |
14906 | 51 // TODO: |
14973 | 52 // 1. Function calls (In progress) |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
53 // 2. Cleanup/documentation |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
54 // 3. ... |
14903 | 55 // --------------------------------------------------------- |
14899 | 56 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
57 // convert between IRs |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
58 // FIXME: Class relationships are messy from here on down. They need to be |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
59 // cleaned up. |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
60 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
61 jit_convert : public tree_walker |
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 public: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
64 typedef std::pair<jit_type *, std::string> type_bound; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
65 typedef std::vector<type_bound> type_bound_vector; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
66 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
67 jit_convert (llvm::Module *module, tree &tee); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
68 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
69 ~jit_convert (void); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
70 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
71 llvm::Function *get_function (void) const { return function; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
72 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
73 const std::vector<std::pair<std::string, bool> >& get_arguments(void) const |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
74 { return arguments; } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
75 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
76 const type_bound_vector& get_bounds (void) const { return bounds; } |
14906 | 77 |
78 void visit_anon_fcn_handle (tree_anon_fcn_handle&); | |
79 | |
80 void visit_argument_list (tree_argument_list&); | |
81 | |
82 void visit_binary_expression (tree_binary_expression&); | |
83 | |
84 void visit_break_command (tree_break_command&); | |
85 | |
86 void visit_colon_expression (tree_colon_expression&); | |
87 | |
88 void visit_continue_command (tree_continue_command&); | |
89 | |
90 void visit_global_command (tree_global_command&); | |
91 | |
92 void visit_persistent_command (tree_persistent_command&); | |
93 | |
94 void visit_decl_elt (tree_decl_elt&); | |
95 | |
96 void visit_decl_init_list (tree_decl_init_list&); | |
97 | |
98 void visit_simple_for_command (tree_simple_for_command&); | |
99 | |
100 void visit_complex_for_command (tree_complex_for_command&); | |
101 | |
102 void visit_octave_user_script (octave_user_script&); | |
103 | |
104 void visit_octave_user_function (octave_user_function&); | |
105 | |
106 void visit_octave_user_function_header (octave_user_function&); | |
107 | |
108 void visit_octave_user_function_trailer (octave_user_function&); | |
109 | |
110 void visit_function_def (tree_function_def&); | |
111 | |
112 void visit_identifier (tree_identifier&); | |
113 | |
114 void visit_if_clause (tree_if_clause&); | |
115 | |
116 void visit_if_command (tree_if_command&); | |
117 | |
118 void visit_if_command_list (tree_if_command_list&); | |
119 | |
120 void visit_index_expression (tree_index_expression&); | |
121 | |
122 void visit_matrix (tree_matrix&); | |
123 | |
124 void visit_cell (tree_cell&); | |
125 | |
126 void visit_multi_assignment (tree_multi_assignment&); | |
127 | |
128 void visit_no_op_command (tree_no_op_command&); | |
129 | |
130 void visit_constant (tree_constant&); | |
131 | |
132 void visit_fcn_handle (tree_fcn_handle&); | |
133 | |
134 void visit_parameter_list (tree_parameter_list&); | |
135 | |
136 void visit_postfix_expression (tree_postfix_expression&); | |
137 | |
138 void visit_prefix_expression (tree_prefix_expression&); | |
139 | |
140 void visit_return_command (tree_return_command&); | |
141 | |
142 void visit_return_list (tree_return_list&); | |
143 | |
144 void visit_simple_assignment (tree_simple_assignment&); | |
145 | |
146 void visit_statement (tree_statement&); | |
147 | |
148 void visit_statement_list (tree_statement_list&); | |
149 | |
150 void visit_switch_case (tree_switch_case&); | |
151 | |
152 void visit_switch_case_list (tree_switch_case_list&); | |
153 | |
154 void visit_switch_command (tree_switch_command&); | |
155 | |
156 void visit_try_catch_command (tree_try_catch_command&); | |
157 | |
158 void visit_unwind_protect_command (tree_unwind_protect_command&); | |
159 | |
160 void visit_while_command (tree_while_command&); | |
161 | |
162 void visit_do_until_command (tree_do_until_command&); | |
14915
cba58541954c
Add if support and fix leak with any
Max Brister <max@2bass.com>
parents:
14914
diff
changeset
|
163 |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
164 // this would be easier with variadic templates |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
165 template <typename T> |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
166 T *create (void) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
167 { |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
168 T *ret = new T(); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
169 track_value (ret); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
170 return ret; |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
171 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
172 |
14980
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
173 #define DECL_ARG(n) const ARG ## n& arg ## n |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
174 #define JIT_CREATE(N) \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
175 template <typename T, OCT_MAKE_DECL_LIST (typename, ARG, N)> \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
176 T *create (OCT_MAKE_LIST (DECL_ARG, N)) \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
177 { \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
178 T *ret = new T (OCT_MAKE_ARG_LIST (arg, N)); \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
179 track_value (ret); \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
180 return ret; \ |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
181 } |
14936
32deb562ae77
Allow for construction of ranges during jit
Max Brister <max@2bass.com>
parents:
14935
diff
changeset
|
182 |
14980
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
183 JIT_CREATE (1) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
184 JIT_CREATE (2) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
185 JIT_CREATE (3) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
186 JIT_CREATE (4) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
187 |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
188 #undef JIT_CREATE |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
189 |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
190 #define JIT_CREATE_CHECKED(N) \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
191 template <OCT_MAKE_DECL_LIST (typename, ARG, N)> \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
192 jit_call *create_checked (OCT_MAKE_LIST (DECL_ARG, N)) \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
193 { \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
194 jit_call *ret = create<jit_call> (OCT_MAKE_ARG_LIST (arg, N)); \ |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
195 return create_checked_impl (ret); \ |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
196 } |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
197 |
14980
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
198 JIT_CREATE_CHECKED (1) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
199 JIT_CREATE_CHECKED (2) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
200 JIT_CREATE_CHECKED (3) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
201 JIT_CREATE_CHECKED (4) |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
202 |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
203 #undef JIT_CREATE_CHECKED |
bb1f3a9bb122
Reduce code duplication in JIT
Max Brister <max@2bass.com>
parents:
14978
diff
changeset
|
204 #undef DECL_ARG |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
205 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
206 typedef std::list<jit_block *> block_list; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
207 typedef block_list::iterator block_iterator; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
208 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
209 void 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
|
210 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
211 void 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
|
212 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
213 void insert_before (jit_block *loc, 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
|
214 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
215 insert_before (loc->location (), ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
216 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
217 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
218 void 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
|
219 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
220 void insert_after (jit_block *loc, 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
|
221 { |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
222 insert_after (loc->location (), ablock); |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
223 } |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
224 private: |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
225 std::vector<std::pair<std::string, bool> > arguments; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
226 type_bound_vector bounds; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
227 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
228 // used instead of return values from visit_* functions |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
229 jit_value *result; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
230 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
231 jit_block *entry_block; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
232 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
233 jit_block *final_block; |
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
234 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
235 jit_block *block; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
236 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
237 llvm::Function *function; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
238 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
239 std::list<jit_block *> blocks; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
240 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
241 std::list<jit_instruction *> worklist; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
242 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
243 std::list<jit_value *> constants; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
244 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
245 std::list<jit_value *> all_values; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
246 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
247 size_t iterator_count; |
14978
f649b66ef1af
Add short circult operators to JIT
Max Brister <max@2bass.com>
parents:
14976
diff
changeset
|
248 size_t short_count; |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
249 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
250 typedef std::map<std::string, jit_variable *> vmap_t; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
251 vmap_t vmap; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
252 |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
253 jit_call *create_checked_impl (jit_call *ret) |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
254 { |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
255 block->append (ret); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
256 create_check (ret); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
257 return ret; |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
258 } |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
259 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
260 jit_error_check *create_check (jit_call *call) |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
261 { |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
262 jit_block *normal = create<jit_block> (block->name ()); |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
263 jit_error_check *ret |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
264 = block->append (create<jit_error_check> (call, normal, 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
|
265 append (normal); |
14961
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
266 block = normal; |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
267 |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
268 return ret; |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
269 } |
903a5ee2cdde
Simplify the creation of error checks in jit
Max Brister <max@2bass.com>
parents:
14960
diff
changeset
|
270 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
271 jit_variable *get_variable (const std::string& vname); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
272 |
14969
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
273 std::pair<jit_value *, jit_value *> resolve (tree_index_expression& exp); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
274 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
275 jit_value *do_assign (tree_expression *exp, jit_value *rhs, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
276 bool artificial = false); |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
277 |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
278 jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print, |
bbeef7b8ea2e
Add support for matrix indexed assignment to JIT
Max Brister <max@2bass.com>
parents:
14968
diff
changeset
|
279 bool artificial = false); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
280 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
281 jit_value *visit (tree *tee) { return visit (*tee); } |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
282 |
14944
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
283 jit_value *visit (tree& tee); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
284 |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
285 void push_worklist (jit_instruction *instr) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
286 { |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
287 if (! instr->in_worklist ()) |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
288 { |
14959
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
289 instr->stash_in_worklist (true); |
12fd4a62d633
Fix whitespace issues and update documentation
Max Brister <max@2bass.com>
parents:
14958
diff
changeset
|
290 worklist.push_back (instr); |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
291 } |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
292 } |
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
293 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
294 void append_users (jit_value *v) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
295 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
296 for (jit_use *use = v->first_use (); use; use = use->next ()) |
14946
3564bb141396
Only add items to worklist in type inferece if not already there
Max Brister <max@2bass.com>
parents:
14945
diff
changeset
|
297 push_worklist (use->user ()); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
298 } |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
299 |
14945 | 300 void append_users_term (jit_terminator *term); |
301 | |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
302 void track_value (jit_value *value) |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
303 { |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
304 if (value->type ()) |
14925
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
305 constants.push_back (value); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
306 all_values.push_back (value); |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
307 } |
8697e3e9d77a
Properly cleanup the low level IR
Max Brister <max@2bass.com>
parents:
14923
diff
changeset
|
308 |
14939
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
309 void merge_blocks (void); |
4488022820c9
No longer segfault when compiling nested for loops
Max Brister <max@2bass.com>
parents:
14938
diff
changeset
|
310 |
14938
bab44e3ee291
Adding basic error support to JIT
Max Brister <max@2bass.com>
parents:
14937
diff
changeset
|
311 void construct_ssa (void); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
312 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
313 void do_construct_ssa (jit_block& block, size_t avisit_count); |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
314 |
14945 | 315 void remove_dead (); |
316 | |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
317 void place_releases (void); |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
318 |
14971
b23a98ca0e43
Remove jit_block::visit_dom and simplify release placement
Max Brister <max@2bass.com>
parents:
14969
diff
changeset
|
319 void release_temp (jit_block& ablock, std::set<jit_value *>& temp); |
14966
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
320 |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
321 void release_dead_phi (jit_block& ablock); |
b7b647bc4b90
Place releases for temporaries on error
Max Brister <max@2bass.com>
parents:
14965
diff
changeset
|
322 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
323 void 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
|
324 |
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
325 void 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
|
326 |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
327 void print_blocks (const std::string& header) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
328 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
329 std::cout << "-------------------- " << header << " --------------------\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
330 for (std::list<jit_block *>::iterator iter = blocks.begin (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
331 iter != blocks.end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
332 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
333 assert (*iter); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
334 (*iter)->print (std::cout, 0); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
335 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
336 std::cout << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
337 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
338 |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
339 void print_dom (void) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
340 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
341 std::cout << "-------------------- dom info --------------------\n"; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
342 for (std::list<jit_block *>::iterator iter = blocks.begin (); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
343 iter != blocks.end (); ++iter) |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
344 { |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
345 assert (*iter); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
346 (*iter)->print_dom (std::cout); |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
347 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
348 std::cout << std::endl; |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
349 } |
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
350 |
14935
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
351 bool breaking; // true if we are breaking OR continuing |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
352 block_list breaks; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
353 block_list continues; |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
354 |
5801e031a3b5
Place releases after last use and generalize dom visiting
Max Brister <max@2bass.com>
parents:
14932
diff
changeset
|
355 void finish_breaks (jit_block *dest, const block_list& lst); |
14928
39d52aa37a08
Use standard SSA construction algorithm, and support break/continue
Max Brister <max@2bass.com>
parents:
14926
diff
changeset
|
356 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
357 // this case is much simpler, just convert from the jit ir to llvm |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
358 class |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
359 convert_llvm : public jit_ir_walker |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
360 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
361 public: |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
362 convert_llvm (jit_convert& jc) : jthis (jc) {} |
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
363 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
364 llvm::Function *convert (llvm::Module *module, |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
365 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
|
366 const std::list<jit_block *>& blocks, |
c0a5ab3b9278
jit_const no longer inherits from jit_instruction
Max Brister <max@2bass.com>
parents:
14943
diff
changeset
|
367 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
|
368 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
369 #define JIT_METH(clname) \ |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
370 virtual void visit (jit_ ## clname&); |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
371 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
372 JIT_VISIT_IR_CLASSES; |
14906 | 373 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
374 #undef JIT_METH |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
375 private: |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
376 // name -> llvm argument |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
377 std::map<std::string, llvm::Value *> arguments; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
378 |
14963
709f50069722
Change algorithm for placing releases and simplify PHIs in low level Octave IR
Max Brister <max@2bass.com>
parents:
14962
diff
changeset
|
379 void finish_phi (jit_phi *phi); |
14906 | 380 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
381 void visit (jit_value *jvalue) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
382 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
383 return visit (*jvalue); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
384 } |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
385 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
386 void visit (jit_value &jvalue) |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
387 { |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
388 jvalue.accept (*this); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
389 } |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
390 private: |
14951
4c9fd3e31436
Start of jit support for double matricies
Max Brister <max@2bass.com>
parents:
14948
diff
changeset
|
391 jit_convert &jthis; |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
392 llvm::Function *function; |
14968
7f60cdfcc0e5
Do not smash stack when passing structures in JIT
Max Brister <max@2bass.com>
parents:
14967
diff
changeset
|
393 llvm::BasicBlock *prelude; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
394 }; |
14906 | 395 }; |
396 | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
397 class jit_info; |
14903 | 398 |
14899 | 399 class |
14903 | 400 tree_jit |
14899 | 401 { |
402 public: | |
403 tree_jit (void); | |
404 | |
405 ~tree_jit (void); | |
406 | |
14920
51d4b1018efb
For loops compile with new IR
Max Brister <max@2bass.com>
parents:
14918
diff
changeset
|
407 bool execute (tree_simple_for_command& cmd); |
14903 | 408 |
15023
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
409 bool execute (tree_while_command& cmd); |
75d1bc2fd6d2
Compile top level while loops in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
410 |
14906 | 411 llvm::ExecutionEngine *get_engine (void) const { return engine; } |
14903 | 412 |
14906 | 413 llvm::Module *get_module (void) const { return module; } |
14903 | 414 |
14906 | 415 void optimize (llvm::Function *fn); |
416 private: | |
417 bool initialize (void); | |
14899 | 418 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
419 // FIXME: Temorary hack to test |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
420 typedef std::map<tree *, jit_info *> compiled_map; |
14899 | 421 llvm::Module *module; |
14903 | 422 llvm::PassManager *module_pass_manager; |
14899 | 423 llvm::FunctionPassManager *pass_manager; |
424 llvm::ExecutionEngine *engine; | |
14906 | 425 }; |
14903 | 426 |
14906 | 427 class |
428 jit_info | |
429 { | |
430 public: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
431 jit_info (tree_jit& tjit, tree& tee); |
14913
c7071907a641
Use symbol_record_ref instead of names in JIT
Max Brister <max@2bass.com>
parents:
14911
diff
changeset
|
432 |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14951
diff
changeset
|
433 ~jit_info (void); |
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14951
diff
changeset
|
434 |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
435 bool execute (void) const; |
14906 | 436 |
437 bool match (void) const; | |
438 private: | |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
439 typedef jit_convert::type_bound type_bound; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
440 typedef jit_convert::type_bound_vector type_bound_vector; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
441 typedef void (*jited_function)(octave_base_value**); |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
442 |
14906 | 443 llvm::ExecutionEngine *engine; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
444 jited_function function; |
14955
609dcc297db5
src/pt-jit.cc (jit_info::~jit_info): New function
Max Brister <max@2bass.com>
parents:
14951
diff
changeset
|
445 llvm::Function *llvm_function; |
14917
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
446 |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
447 std::vector<std::pair<std::string, bool> > arguments; |
232d8ab07932
Rewrite pt-jit.* adding new low level octave IR
Max Brister <max@2bass.com>
parents:
14915
diff
changeset
|
448 type_bound_vector bounds; |
14899 | 449 }; |
14937
78e1457c5bf5
Remove some macros from pt-jit.h and pt-jit.cc
Max Brister <max@2bass.com>
parents:
14936
diff
changeset
|
450 |
14899 | 451 #endif |
14932
1f914446157d
Locate and link with LLVM properly
Max Brister <max@2bass.com>
parents:
14928
diff
changeset
|
452 #endif |