Mercurial > hg > octave-lyh
annotate libinterp/interp-core/jit-ir.h @ 16660:cbb1bb7a5c3d
Added tag ss-3-7-5 for changeset 608e307b4914
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 May 2013 05:23:53 -0400 |
parents | 44272909d926 |
children | e2de3c8882be |
rev | line source |
---|---|
15016 | 1 /* |
2 | |
3 Copyright (C) 2012 Max Brister <max@2bass.com> | |
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_jit_ir_h) | |
24 #define octave_jit_ir_h 1 | |
25 | |
26 #ifdef HAVE_LLVM | |
27 | |
28 #include <list> | |
29 #include <stack> | |
30 #include <set> | |
31 | |
32 #include "jit-typeinfo.h" | |
33 | |
34 // The low level octave jit ir | |
35 // this ir is close to llvm, but contains information for doing type inference. | |
36 // We convert the octave parse tree to this IR directly. | |
37 | |
38 #define JIT_VISIT_IR_NOTEMPLATE \ | |
39 JIT_METH(block); \ | |
40 JIT_METH(branch); \ | |
41 JIT_METH(cond_branch); \ | |
42 JIT_METH(call); \ | |
43 JIT_METH(extract_argument); \ | |
44 JIT_METH(store_argument); \ | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
45 JIT_METH(return); \ |
15016 | 46 JIT_METH(phi); \ |
47 JIT_METH(variable); \ | |
48 JIT_METH(error_check); \ | |
49 JIT_METH(assign) \ | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
50 JIT_METH(argument) \ |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
51 JIT_METH(magic_end) |
15016 | 52 |
53 #define JIT_VISIT_IR_CONST \ | |
54 JIT_METH(const_bool); \ | |
55 JIT_METH(const_scalar); \ | |
56 JIT_METH(const_complex); \ | |
57 JIT_METH(const_index); \ | |
58 JIT_METH(const_string); \ | |
59 JIT_METH(const_range) | |
60 | |
61 #define JIT_VISIT_IR_CLASSES \ | |
62 JIT_VISIT_IR_NOTEMPLATE \ | |
63 JIT_VISIT_IR_CONST | |
64 | |
65 // forward declare all ir classes | |
66 #define JIT_METH(cname) \ | |
67 class jit_ ## cname; | |
68 | |
69 JIT_VISIT_IR_NOTEMPLATE | |
70 | |
71 #undef JIT_METH | |
72 | |
73 // ABCs which aren't included in JIT_VISIT_IR_ALL | |
74 class jit_instruction; | |
75 class jit_terminator; | |
76 | |
77 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T = T, | |
78 bool QUOTE=false> | |
79 class jit_const; | |
80 | |
81 typedef jit_const<bool, jit_typeinfo::get_bool> jit_const_bool; | |
82 typedef jit_const<double, jit_typeinfo::get_scalar> jit_const_scalar; | |
83 typedef jit_const<Complex, jit_typeinfo::get_complex> jit_const_complex; | |
84 typedef jit_const<octave_idx_type, jit_typeinfo::get_index> jit_const_index; | |
85 | |
86 typedef jit_const<std::string, jit_typeinfo::get_string, const std::string&, | |
87 true> jit_const_string; | |
88 typedef jit_const<jit_range, jit_typeinfo::get_range, const jit_range&> | |
89 jit_const_range; | |
90 | |
91 class jit_ir_walker; | |
92 class jit_use; | |
93 | |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
94 // Creates and tracks memory for jit_value and subclasses. |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
95 // Memory managment is simple, all values that are created live as long as the |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
96 // factory. |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
97 class |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
98 jit_factory |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
99 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
100 typedef std::list<jit_value *> value_list; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
101 public: |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
102 ~jit_factory (void); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
103 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
104 const value_list& constants (void) const { return mconstants; } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
105 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
106 template <typename T> |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
107 T *create (void) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
108 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
109 T *ret = new T (); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
110 track_value (ret); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
111 return ret; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
112 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
113 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
114 #define DECL_ARG(n) const ARG ## n& arg ## n |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
115 #define JIT_CREATE(N) \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
116 template <typename T, OCT_MAKE_DECL_LIST (typename, ARG, N)> \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
117 T *create (OCT_MAKE_LIST (DECL_ARG, N)) \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
118 { \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
119 T *ret = new T (OCT_MAKE_ARG_LIST (arg, N)); \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
120 track_value (ret); \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
121 return ret; \ |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
122 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
123 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
124 JIT_CREATE (1) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
125 JIT_CREATE (2) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
126 JIT_CREATE (3) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
127 JIT_CREATE (4) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
128 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
129 #undef JIT_CREATE |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
130 #undef DECL_ARG |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
131 private: |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
132 void track_value (jit_value *v); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
133 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
134 value_list all_values; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
135 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
136 value_list mconstants; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
137 }; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
138 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
139 // A list of basic blocks (jit_block) which form some body of code. |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
140 // |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
141 // We do not directly inherit from std::list because we need to update the |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
142 // blocks stashed location in push_back and insert. |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
143 class |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
144 jit_block_list |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
145 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
146 public: |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
147 typedef std::list<jit_block *>::iterator iterator; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
148 typedef std::list<jit_block *>::const_iterator const_iterator; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
149 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
150 jit_block *back (void) const { return mlist.back (); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
151 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
152 iterator begin (void) { return mlist.begin (); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
153 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
154 const_iterator begin (void) const { return mlist.begin (); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
155 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
156 iterator end (void) { return mlist.end (); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
157 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
158 const_iterator end (void) const { return mlist.end (); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
159 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
160 iterator erase (iterator iter) { return mlist.erase (iter); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
161 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
162 jit_block *front (void) const { return mlist.front (); } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
163 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
164 void insert_after (iterator iter, jit_block *ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
165 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
166 void insert_after (jit_block *loc, jit_block *ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
167 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
168 void insert_before (iterator iter, jit_block *ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
169 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
170 void insert_before (jit_block *loc, jit_block *ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
171 |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15594
diff
changeset
|
172 void label (void); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15594
diff
changeset
|
173 |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
174 std::ostream& print (std::ostream& os, const std::string& header) const; |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
175 |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
176 std::ostream& print_dom (std::ostream& os) const; |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
177 |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
178 void push_back (jit_block *b); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
179 private: |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
180 std::list<jit_block *> mlist; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
181 }; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
182 |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
183 std::ostream& operator<<(std::ostream& os, const jit_block_list& blocks); |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
184 |
15016 | 185 class |
186 jit_value : public jit_internal_list<jit_value, jit_use> | |
187 { | |
188 public: | |
189 jit_value (void) : llvm_value (0), ty (0), mlast_use (0), | |
190 min_worklist (false) {} | |
191 | |
192 virtual ~jit_value (void); | |
193 | |
194 bool in_worklist (void) const | |
195 { | |
196 return min_worklist; | |
197 } | |
198 | |
199 void stash_in_worklist (bool ain_worklist) | |
200 { | |
201 min_worklist = ain_worklist; | |
202 } | |
203 | |
204 // The block of the first use which is not a jit_error_check | |
205 // So this is not necessarily first_use ()->parent (). | |
206 jit_block *first_use_block (void); | |
207 | |
208 // replace all uses with | |
209 virtual void replace_with (jit_value *value); | |
210 | |
211 jit_type *type (void) const { return ty; } | |
212 | |
213 llvm::Type *type_llvm (void) const | |
214 { | |
215 return ty ? ty->to_llvm () : 0; | |
216 } | |
217 | |
218 const std::string& type_name (void) const | |
219 { | |
220 return ty->name (); | |
221 } | |
222 | |
223 void stash_type (jit_type *new_ty) { ty = new_ty; } | |
224 | |
225 std::string print_string (void) | |
226 { | |
227 std::stringstream ss; | |
228 print (ss); | |
229 return ss.str (); | |
230 } | |
231 | |
232 jit_instruction *last_use (void) const { return mlast_use; } | |
233 | |
234 void stash_last_use (jit_instruction *alast_use) | |
235 { | |
236 mlast_use = alast_use; | |
237 } | |
238 | |
239 virtual bool needs_release (void) const { return false; } | |
240 | |
241 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const = 0; | |
242 | |
243 virtual std::ostream& short_print (std::ostream& os) const | |
244 { return print (os); } | |
245 | |
246 virtual void accept (jit_ir_walker& walker) = 0; | |
247 | |
248 bool has_llvm (void) const | |
249 { | |
250 return llvm_value; | |
251 } | |
252 | |
253 llvm::Value *to_llvm (void) const | |
254 { | |
255 assert (llvm_value); | |
256 return llvm_value; | |
257 } | |
258 | |
259 void stash_llvm (llvm::Value *compiled) | |
260 { | |
261 llvm_value = compiled; | |
262 } | |
263 | |
264 protected: | |
265 std::ostream& print_indent (std::ostream& os, size_t indent = 0) const | |
266 { | |
267 for (size_t i = 0; i < indent * 8; ++i) | |
268 os << " "; | |
269 return os; | |
270 } | |
271 | |
272 llvm::Value *llvm_value; | |
273 private: | |
274 jit_type *ty; | |
275 jit_instruction *mlast_use; | |
276 bool min_worklist; | |
277 }; | |
278 | |
279 std::ostream& operator<< (std::ostream& os, const jit_value& value); | |
280 std::ostream& jit_print (std::ostream& os, jit_value *avalue); | |
281 | |
282 class | |
283 jit_use : public jit_internal_node<jit_value, jit_use> | |
284 { | |
285 public: | |
15231
8442131a391a
jit-ir.h (jit_use::stash_value): Explicitly specify parent template types
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
286 // some compilers don't allow us to use jit_internal_node without template |
8442131a391a
jit-ir.h (jit_use::stash_value): Explicitly specify parent template types
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
287 // paremeters |
8442131a391a
jit-ir.h (jit_use::stash_value): Explicitly specify parent template types
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
288 typedef jit_internal_node<jit_value, jit_use> PARENT_T; |
8442131a391a
jit-ir.h (jit_use::stash_value): Explicitly specify parent template types
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
289 |
15016 | 290 jit_use (void) : muser (0), mindex (0) {} |
291 | |
292 // we should really have a move operator, but not until c++11 :( | |
293 jit_use (const jit_use& use) : muser (0), mindex (0) | |
294 { | |
295 *this = use; | |
296 } | |
297 | |
298 jit_use& operator= (const jit_use& use) | |
299 { | |
300 stash_value (use.value (), use.user (), use.index ()); | |
301 return *this; | |
302 } | |
303 | |
304 size_t index (void) const { return mindex; } | |
305 | |
306 jit_instruction *user (void) const { return muser; } | |
307 | |
308 jit_block *user_parent (void) const; | |
309 | |
310 std::list<jit_block *> user_parent_location (void) const; | |
311 | |
312 void stash_value (jit_value *avalue, jit_instruction *auser = 0, | |
313 size_t aindex = -1) | |
314 { | |
15231
8442131a391a
jit-ir.h (jit_use::stash_value): Explicitly specify parent template types
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
315 PARENT_T::stash_value (avalue); |
15016 | 316 mindex = aindex; |
317 muser = auser; | |
318 } | |
319 private: | |
320 jit_instruction *muser; | |
321 size_t mindex; | |
322 }; | |
323 | |
324 class | |
325 jit_instruction : public jit_value | |
326 { | |
327 public: | |
328 // FIXME: this code could be so much pretier with varadic templates... | |
329 jit_instruction (void) : mid (next_id ()), mparent (0) | |
330 {} | |
331 | |
332 jit_instruction (size_t nargs) : mid (next_id ()), mparent (0) | |
333 { | |
334 already_infered.reserve (nargs); | |
335 marguments.reserve (nargs); | |
336 } | |
337 | |
338 #define STASH_ARG(i) stash_argument (i, arg ## i); | |
339 #define JIT_INSTRUCTION_CTOR(N) \ | |
340 jit_instruction (OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ | |
341 : already_infered (N), marguments (N), mid (next_id ()), mparent (0) \ | |
342 { \ | |
343 OCT_ITERATE_MACRO (STASH_ARG, N); \ | |
344 } | |
345 | |
346 JIT_INSTRUCTION_CTOR(1) | |
347 JIT_INSTRUCTION_CTOR(2) | |
348 JIT_INSTRUCTION_CTOR(3) | |
349 JIT_INSTRUCTION_CTOR(4) | |
350 | |
351 #undef STASH_ARG | |
352 #undef JIT_INSTRUCTION_CTOR | |
353 | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
354 jit_instruction (const std::vector<jit_value *>& aarguments) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
355 : already_infered (aarguments.size ()), marguments (aarguments.size ()), |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
356 mid (next_id ()), mparent (0) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
357 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
358 for (size_t i = 0; i < aarguments.size (); ++i) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
359 stash_argument (i, aarguments[i]); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
360 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
361 |
15016 | 362 static void reset_ids (void) |
363 { | |
364 next_id (true); | |
365 } | |
366 | |
367 jit_value *argument (size_t i) const | |
368 { | |
369 return marguments[i].value (); | |
370 } | |
371 | |
372 llvm::Value *argument_llvm (size_t i) const | |
373 { | |
374 assert (argument (i)); | |
375 return argument (i)->to_llvm (); | |
376 } | |
377 | |
378 jit_type *argument_type (size_t i) const | |
379 { | |
380 return argument (i)->type (); | |
381 } | |
382 | |
383 llvm::Type *argument_type_llvm (size_t i) const | |
384 { | |
385 assert (argument (i)); | |
386 return argument_type (i)->to_llvm (); | |
387 } | |
388 | |
389 std::ostream& print_argument (std::ostream& os, size_t i) const | |
390 { | |
391 if (argument (i)) | |
392 return argument (i)->short_print (os); | |
393 else | |
394 return os << "NULL"; | |
395 } | |
396 | |
397 void stash_argument (size_t i, jit_value *arg) | |
398 { | |
399 marguments[i].stash_value (arg, this, i); | |
400 } | |
401 | |
402 void push_argument (jit_value *arg) | |
403 { | |
404 marguments.push_back (jit_use ()); | |
405 stash_argument (marguments.size () - 1, arg); | |
406 already_infered.push_back (0); | |
407 } | |
408 | |
409 size_t argument_count (void) const | |
410 { | |
411 return marguments.size (); | |
412 } | |
413 | |
414 void resize_arguments (size_t acount, jit_value *adefault = 0) | |
415 { | |
416 size_t old = marguments.size (); | |
417 marguments.resize (acount); | |
418 already_infered.resize (acount); | |
419 | |
420 if (adefault) | |
421 for (size_t i = old; i < acount; ++i) | |
422 stash_argument (i, adefault); | |
423 } | |
424 | |
425 const std::vector<jit_use>& arguments (void) const { return marguments; } | |
426 | |
427 // argument types which have been infered already | |
428 const std::vector<jit_type *>& argument_types (void) const | |
429 { return already_infered; } | |
430 | |
431 virtual void push_variable (void) {} | |
432 | |
433 virtual void pop_variable (void) {} | |
434 | |
435 virtual void construct_ssa (void) | |
436 { | |
437 do_construct_ssa (0, argument_count ()); | |
438 } | |
439 | |
440 virtual bool infer (void) { return false; } | |
441 | |
442 void remove (void); | |
443 | |
444 virtual std::ostream& short_print (std::ostream& os) const; | |
445 | |
446 jit_block *parent (void) const { return mparent; } | |
447 | |
448 std::list<jit_instruction *>::iterator location (void) const | |
449 { | |
450 return mlocation; | |
451 } | |
452 | |
453 llvm::BasicBlock *parent_llvm (void) const; | |
454 | |
455 void stash_parent (jit_block *aparent, | |
456 std::list<jit_instruction *>::iterator alocation) | |
457 { | |
458 mparent = aparent; | |
459 mlocation = alocation; | |
460 } | |
461 | |
462 size_t id (void) const { return mid; } | |
463 protected: | |
464 | |
465 // Do SSA replacement on arguments in [start, end) | |
466 void do_construct_ssa (size_t start, size_t end); | |
467 | |
468 std::vector<jit_type *> already_infered; | |
469 private: | |
470 static size_t next_id (bool reset = false) | |
471 { | |
472 static size_t ret = 0; | |
473 if (reset) | |
474 return ret = 0; | |
475 | |
476 return ret++; | |
477 } | |
478 | |
479 std::vector<jit_use> marguments; | |
480 | |
481 size_t mid; | |
482 jit_block *mparent; | |
483 std::list<jit_instruction *>::iterator mlocation; | |
484 }; | |
485 | |
486 // defnie accept methods for subclasses | |
487 #define JIT_VALUE_ACCEPT \ | |
488 virtual void accept (jit_ir_walker& walker); | |
489 | |
490 // for use as a dummy argument during conversion to LLVM | |
491 class | |
492 jit_argument : public jit_value | |
493 { | |
494 public: | |
495 jit_argument (jit_type *atype, llvm::Value *avalue) | |
496 { | |
497 stash_type (atype); | |
498 stash_llvm (avalue); | |
499 } | |
500 | |
501 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
502 { | |
503 print_indent (os, indent); | |
504 return jit_print (os, type ()) << ": DUMMY"; | |
505 } | |
506 | |
507 JIT_VALUE_ACCEPT; | |
508 }; | |
509 | |
510 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T, | |
511 bool QUOTE> | |
512 class | |
513 jit_const : public jit_value | |
514 { | |
515 public: | |
516 typedef PASS_T pass_t; | |
517 | |
518 jit_const (PASS_T avalue) : mvalue (avalue) | |
519 { | |
520 stash_type (EXTRACT_T ()); | |
521 } | |
522 | |
523 PASS_T value (void) const { return mvalue; } | |
524 | |
525 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
526 { | |
527 print_indent (os, indent); | |
528 jit_print (os, type ()) << ": "; | |
529 if (QUOTE) | |
530 os << "\""; | |
531 os << mvalue; | |
532 if (QUOTE) | |
533 os << "\""; | |
534 return os; | |
535 } | |
536 | |
537 JIT_VALUE_ACCEPT; | |
538 private: | |
539 T mvalue; | |
540 }; | |
541 | |
542 class jit_phi_incomming; | |
543 | |
544 class | |
545 jit_block : public jit_value, public jit_internal_list<jit_block, | |
546 jit_phi_incomming> | |
547 { | |
548 typedef jit_internal_list<jit_block, jit_phi_incomming> ILIST_T; | |
549 public: | |
550 typedef std::list<jit_instruction *> instruction_list; | |
551 typedef instruction_list::iterator iterator; | |
552 typedef instruction_list::const_iterator const_iterator; | |
553 | |
554 typedef std::set<jit_block *> df_set; | |
555 typedef df_set::const_iterator df_iterator; | |
556 | |
557 static const size_t NO_ID = static_cast<size_t> (-1); | |
558 | |
559 jit_block (const std::string& aname, size_t avisit_count = 0) | |
560 : mvisit_count (avisit_count), mid (NO_ID), idom (0), mname (aname), | |
561 malive (false) | |
562 {} | |
563 | |
564 virtual void replace_with (jit_value *value); | |
565 | |
566 void replace_in_phi (jit_block *ablock, jit_block *with); | |
567 | |
568 // we have a new internal list, but we want to stay compatable with jit_value | |
569 jit_use *first_use (void) const { return jit_value::first_use (); } | |
570 | |
571 size_t use_count (void) const { return jit_value::use_count (); } | |
572 | |
573 // if a block is alive, then it might be visited during execution | |
574 bool alive (void) const { return malive; } | |
575 | |
576 void mark_alive (void) { malive = true; } | |
577 | |
578 // If we can merge with a successor, do so and return the now empty block | |
579 jit_block *maybe_merge (); | |
580 | |
581 // merge another block into this block, leaving the merge block empty | |
582 void merge (jit_block& merge); | |
583 | |
584 const std::string& name (void) const { return mname; } | |
585 | |
586 jit_instruction *prepend (jit_instruction *instr); | |
587 | |
588 jit_instruction *prepend_after_phi (jit_instruction *instr); | |
589 | |
590 template <typename T> | |
591 T *append (T *instr) | |
592 { | |
593 internal_append (instr); | |
594 return instr; | |
595 } | |
596 | |
597 jit_instruction *insert_before (iterator loc, jit_instruction *instr); | |
598 | |
599 jit_instruction *insert_before (jit_instruction *loc, jit_instruction *instr) | |
600 { | |
601 return insert_before (loc->location (), instr); | |
602 } | |
603 | |
604 jit_instruction *insert_after (iterator loc, jit_instruction *instr); | |
605 | |
606 jit_instruction *insert_after (jit_instruction *loc, jit_instruction *instr) | |
607 { | |
608 return insert_after (loc->location (), instr); | |
609 } | |
610 | |
611 iterator remove (iterator iter) | |
612 { | |
613 jit_instruction *instr = *iter; | |
614 iter = instructions.erase (iter); | |
615 instr->stash_parent (0, instructions.end ()); | |
616 return iter; | |
617 } | |
618 | |
619 jit_terminator *terminator (void) const; | |
620 | |
621 // is the jump from pred alive? | |
622 bool branch_alive (jit_block *asucc) const; | |
623 | |
624 jit_block *successor (size_t i) const; | |
625 | |
626 size_t successor_count (void) const; | |
627 | |
628 iterator begin (void) { return instructions.begin (); } | |
629 | |
630 const_iterator begin (void) const { return instructions.begin (); } | |
631 | |
632 iterator end (void) { return instructions.end (); } | |
633 | |
634 const_iterator end (void) const { return instructions.end (); } | |
635 | |
636 iterator phi_begin (void); | |
637 | |
638 iterator phi_end (void); | |
639 | |
640 iterator nonphi_begin (void); | |
641 | |
642 // must label before id is valid | |
643 size_t id (void) const { return mid; } | |
644 | |
645 // dominance frontier | |
646 const df_set& df (void) const { return mdf; } | |
647 | |
648 df_iterator df_begin (void) const { return mdf.begin (); } | |
649 | |
650 df_iterator df_end (void) const { return mdf.end (); } | |
651 | |
652 // label with a RPO walk | |
653 void label (void) | |
654 { | |
655 size_t number = 0; | |
656 label (mvisit_count, number); | |
657 } | |
658 | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15594
diff
changeset
|
659 void label (size_t avisit_count, size_t& number); |
15016 | 660 |
661 // See for idom computation algorithm | |
662 // Cooper, Keith D.; Harvey, Timothy J; and Kennedy, Ken (2001). | |
663 // "A Simple, Fast Dominance Algorithm" | |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
664 void compute_idom (jit_block& entry_block) |
15016 | 665 { |
666 bool changed; | |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
667 entry_block.idom = &entry_block; |
15016 | 668 do |
669 changed = update_idom (mvisit_count); | |
670 while (changed); | |
671 } | |
672 | |
673 // compute dominance frontier | |
674 void compute_df (void) | |
675 { | |
676 compute_df (mvisit_count); | |
677 } | |
678 | |
679 void create_dom_tree (void) | |
680 { | |
681 create_dom_tree (mvisit_count); | |
682 } | |
683 | |
684 jit_block *dom_successor (size_t idx) const | |
685 { | |
686 return dom_succ[idx]; | |
687 } | |
688 | |
689 size_t dom_successor_count (void) const | |
690 { | |
691 return dom_succ.size (); | |
692 } | |
693 | |
694 // call pop_varaible on all instructions | |
695 void pop_all (void); | |
696 | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15594
diff
changeset
|
697 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const; |
15016 | 698 |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
699 jit_block *maybe_split (jit_factory& factory, jit_block_list& blocks, |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
700 jit_block *asuccessor); |
15016 | 701 |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
702 jit_block *maybe_split (jit_factory& factory, jit_block_list& blocks, |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
703 jit_block& asuccessor) |
15016 | 704 { |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
705 return maybe_split (factory, blocks, &asuccessor); |
15016 | 706 } |
707 | |
708 // print dominator infomration | |
709 std::ostream& print_dom (std::ostream& os) const; | |
710 | |
711 virtual std::ostream& short_print (std::ostream& os) const | |
712 { | |
713 os << mname; | |
714 if (mid != NO_ID) | |
715 os << mid; | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15594
diff
changeset
|
716 else |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15594
diff
changeset
|
717 os << "!"; |
15016 | 718 return os; |
719 } | |
720 | |
721 llvm::BasicBlock *to_llvm (void) const; | |
722 | |
723 std::list<jit_block *>::iterator location (void) const | |
724 { return mlocation; } | |
725 | |
726 void stash_location (std::list<jit_block *>::iterator alocation) | |
727 { mlocation = alocation; } | |
728 | |
729 // used to prevent visiting the same node twice in the graph | |
730 size_t visit_count (void) const { return mvisit_count; } | |
731 | |
732 // check if this node has been visited yet at the given visit count. If we | |
733 // have not been visited yet, mark us as visited. | |
734 bool visited (size_t avisit_count) | |
735 { | |
736 if (mvisit_count <= avisit_count) | |
737 { | |
738 mvisit_count = avisit_count + 1; | |
739 return false; | |
740 } | |
741 | |
742 return true; | |
743 } | |
744 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
745 jit_instruction *front (void) { return instructions.front (); } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
746 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
747 jit_instruction *back (void) { return instructions.back (); } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
748 |
15016 | 749 JIT_VALUE_ACCEPT; |
750 private: | |
751 void internal_append (jit_instruction *instr); | |
752 | |
753 void compute_df (size_t avisit_count); | |
754 | |
755 bool update_idom (size_t avisit_count); | |
756 | |
757 void create_dom_tree (size_t avisit_count); | |
758 | |
759 static jit_block *idom_intersect (jit_block *i, jit_block *j); | |
760 | |
761 size_t mvisit_count; | |
762 size_t mid; | |
763 jit_block *idom; | |
764 df_set mdf; | |
765 std::vector<jit_block *> dom_succ; | |
766 std::string mname; | |
767 instruction_list instructions; | |
768 bool malive; | |
769 std::list<jit_block *>::iterator mlocation; | |
770 }; | |
771 | |
772 // keeps track of phi functions that use a block on incomming edges | |
773 class | |
774 jit_phi_incomming : public jit_internal_node<jit_block, jit_phi_incomming> | |
775 { | |
776 public: | |
777 jit_phi_incomming (void) : muser (0) {} | |
778 | |
779 jit_phi_incomming (jit_phi *auser) : muser (auser) {} | |
780 | |
15232
2c0259dc1a82
jit-ir.h (jit_phi_incomming::jit_phi_incomming): Remove extraneous parent initialization
Max Brister <max@2bass.com>
parents:
15231
diff
changeset
|
781 jit_phi_incomming (const jit_phi_incomming& use) |
15016 | 782 { |
783 *this = use; | |
784 } | |
785 | |
786 jit_phi_incomming& operator= (const jit_phi_incomming& use) | |
787 { | |
788 stash_value (use.value ()); | |
789 muser = use.muser; | |
790 return *this; | |
791 } | |
792 | |
793 jit_phi *user (void) const { return muser; } | |
794 | |
795 jit_block *user_parent (void) const; | |
796 private: | |
797 jit_phi *muser; | |
798 }; | |
799 | |
800 // A non-ssa variable | |
801 class | |
802 jit_variable : public jit_value | |
803 { | |
804 public: | |
805 jit_variable (const std::string& aname) : mname (aname), mlast_use (0) {} | |
806 | |
807 const std::string &name (void) const { return mname; } | |
808 | |
809 // manipulate the value_stack, for use during SSA construction. The top of the | |
810 // value stack represents the current value for this variable | |
811 bool has_top (void) const | |
812 { | |
813 return ! value_stack.empty (); | |
814 } | |
815 | |
816 jit_value *top (void) const | |
817 { | |
818 return value_stack.top (); | |
819 } | |
820 | |
821 void push (jit_instruction *v) | |
822 { | |
823 value_stack.push (v); | |
824 mlast_use = v; | |
825 } | |
826 | |
827 void pop (void) | |
828 { | |
829 value_stack.pop (); | |
830 } | |
831 | |
832 jit_instruction *last_use (void) const | |
833 { | |
834 return mlast_use; | |
835 } | |
836 | |
837 void stash_last_use (jit_instruction *instr) | |
838 { | |
839 mlast_use = instr; | |
840 } | |
841 | |
842 // blocks in which we are used | |
843 void use_blocks (jit_block::df_set& result) | |
844 { | |
845 jit_use *use = first_use (); | |
846 while (use) | |
847 { | |
848 result.insert (use->user_parent ()); | |
849 use = use->next (); | |
850 } | |
851 } | |
852 | |
853 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
854 { | |
855 return print_indent (os, indent) << mname; | |
856 } | |
857 | |
858 JIT_VALUE_ACCEPT; | |
859 private: | |
860 std::string mname; | |
861 std::stack<jit_value *> value_stack; | |
862 jit_instruction *mlast_use; | |
863 }; | |
864 | |
865 class | |
866 jit_assign_base : public jit_instruction | |
867 { | |
868 public: | |
869 jit_assign_base (jit_variable *adest) : jit_instruction (), mdest (adest) {} | |
870 | |
871 jit_assign_base (jit_variable *adest, size_t npred) : jit_instruction (npred), | |
872 mdest (adest) {} | |
873 | |
874 jit_assign_base (jit_variable *adest, jit_value *arg0, jit_value *arg1) | |
875 : jit_instruction (arg0, arg1), mdest (adest) {} | |
876 | |
877 jit_variable *dest (void) const { return mdest; } | |
878 | |
879 virtual void push_variable (void) | |
880 { | |
881 mdest->push (this); | |
882 } | |
883 | |
884 virtual void pop_variable (void) | |
885 { | |
886 mdest->pop (); | |
887 } | |
888 | |
889 virtual std::ostream& short_print (std::ostream& os) const | |
890 { | |
891 if (type ()) | |
892 jit_print (os, type ()) << ": "; | |
893 | |
894 dest ()->short_print (os); | |
895 return os << "#" << id (); | |
896 } | |
897 private: | |
898 jit_variable *mdest; | |
899 }; | |
900 | |
901 class | |
902 jit_assign : public jit_assign_base | |
903 { | |
904 public: | |
905 jit_assign (jit_variable *adest, jit_value *asrc) | |
906 : jit_assign_base (adest, adest, asrc), martificial (false) {} | |
907 | |
908 jit_value *overwrite (void) const | |
909 { | |
910 return argument (0); | |
911 } | |
912 | |
913 jit_value *src (void) const | |
914 { | |
915 return argument (1); | |
916 } | |
917 | |
918 // variables don't get modified in an SSA, but COW requires we modify | |
919 // variables. An artificial assign is for when a variable gets modified. We | |
920 // need an assign in the SSA, but the reference counts shouldn't be updated. | |
921 bool artificial (void) const { return martificial; } | |
922 | |
923 void mark_artificial (void) { martificial = true; } | |
924 | |
925 virtual bool infer (void) | |
926 { | |
927 jit_type *stype = src ()->type (); | |
928 if (stype != type()) | |
929 { | |
930 stash_type (stype); | |
931 return true; | |
932 } | |
933 | |
934 return false; | |
935 } | |
936 | |
937 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
938 { | |
939 print_indent (os, indent) << *this << " = " << *src (); | |
940 | |
941 if (artificial ()) | |
942 os << " [artificial]"; | |
943 | |
944 return os; | |
945 } | |
946 | |
947 JIT_VALUE_ACCEPT; | |
948 private: | |
949 bool martificial; | |
950 }; | |
951 | |
952 class | |
953 jit_phi : public jit_assign_base | |
954 { | |
955 public: | |
956 jit_phi (jit_variable *adest, size_t npred) | |
957 : jit_assign_base (adest, npred) | |
958 { | |
959 mincomming.reserve (npred); | |
960 } | |
961 | |
962 // removes arguments form dead incomming jumps | |
963 bool prune (void); | |
964 | |
965 void add_incomming (jit_block *from, jit_value *value) | |
966 { | |
967 push_argument (value); | |
968 mincomming.push_back (jit_phi_incomming (this)); | |
969 mincomming[mincomming.size () - 1].stash_value (from); | |
970 } | |
971 | |
972 jit_block *incomming (size_t i) const | |
973 { | |
974 return mincomming[i].value (); | |
975 } | |
976 | |
977 llvm::BasicBlock *incomming_llvm (size_t i) const | |
978 { | |
979 return incomming (i)->to_llvm (); | |
980 } | |
981 | |
982 virtual void construct_ssa (void) {} | |
983 | |
984 virtual bool infer (void); | |
985 | |
986 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
987 { | |
988 std::stringstream ss; | |
989 print_indent (ss, indent); | |
990 short_print (ss) << " phi "; | |
991 std::string ss_str = ss.str (); | |
992 std::string indent_str (ss_str.size (), ' '); | |
993 os << ss_str; | |
994 | |
995 for (size_t i = 0; i < argument_count (); ++i) | |
996 { | |
997 if (i > 0) | |
998 os << indent_str; | |
999 os << "| "; | |
1000 | |
1001 os << *incomming (i) << " -> "; | |
1002 os << *argument (i); | |
1003 | |
1004 if (i + 1 < argument_count ()) | |
1005 os << std::endl; | |
1006 } | |
1007 | |
1008 return os; | |
1009 } | |
1010 | |
1011 llvm::PHINode *to_llvm (void) const; | |
1012 | |
1013 JIT_VALUE_ACCEPT; | |
1014 private: | |
1015 std::vector<jit_phi_incomming> mincomming; | |
1016 }; | |
1017 | |
1018 class | |
1019 jit_terminator : public jit_instruction | |
1020 { | |
1021 public: | |
1022 #define JIT_TERMINATOR_CONST(N) \ | |
1023 jit_terminator (size_t asuccessor_count, \ | |
1024 OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ | |
1025 : jit_instruction (OCT_MAKE_ARG_LIST (arg, N)), \ | |
1026 malive (asuccessor_count, false) {} | |
1027 | |
1028 JIT_TERMINATOR_CONST (1) | |
1029 JIT_TERMINATOR_CONST (2) | |
1030 JIT_TERMINATOR_CONST (3) | |
1031 | |
1032 #undef JIT_TERMINATOR_CONST | |
1033 | |
1034 jit_block *successor (size_t idx = 0) const | |
1035 { | |
1036 return static_cast<jit_block *> (argument (idx)); | |
1037 } | |
1038 | |
1039 llvm::BasicBlock *successor_llvm (size_t idx = 0) const | |
1040 { | |
1041 return successor (idx)->to_llvm (); | |
1042 } | |
1043 | |
1044 size_t successor_index (const jit_block *asuccessor) const; | |
1045 | |
1046 std::ostream& print_successor (std::ostream& os, size_t idx = 0) const | |
1047 { | |
1048 if (alive (idx)) | |
1049 os << "[live] "; | |
1050 else | |
1051 os << "[dead] "; | |
1052 | |
1053 return successor (idx)->short_print (os); | |
1054 } | |
1055 | |
1056 // Check if the jump to successor is live | |
1057 bool alive (const jit_block *asuccessor) const | |
1058 { | |
1059 return alive (successor_index (asuccessor)); | |
1060 } | |
1061 | |
1062 bool alive (size_t idx) const { return malive[idx]; } | |
1063 | |
1064 bool alive (int idx) const { return malive[idx]; } | |
1065 | |
1066 size_t successor_count (void) const { return malive.size (); } | |
1067 | |
1068 virtual bool infer (void); | |
1069 | |
1070 llvm::TerminatorInst *to_llvm (void) const; | |
1071 protected: | |
1072 virtual bool check_alive (size_t) const { return true; } | |
1073 private: | |
1074 std::vector<bool> malive; | |
1075 }; | |
1076 | |
1077 class | |
1078 jit_branch : public jit_terminator | |
1079 { | |
1080 public: | |
1081 jit_branch (jit_block *succ) : jit_terminator (1, succ) {} | |
1082 | |
1083 virtual size_t successor_count (void) const { return 1; } | |
1084 | |
1085 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
1086 { | |
1087 print_indent (os, indent) << "branch: "; | |
1088 return print_successor (os); | |
1089 } | |
1090 | |
1091 JIT_VALUE_ACCEPT; | |
1092 }; | |
1093 | |
1094 class | |
1095 jit_cond_branch : public jit_terminator | |
1096 { | |
1097 public: | |
1098 jit_cond_branch (jit_value *c, jit_block *ctrue, jit_block *cfalse) | |
1099 : jit_terminator (2, ctrue, cfalse, c) {} | |
1100 | |
1101 jit_value *cond (void) const { return argument (2); } | |
1102 | |
1103 std::ostream& print_cond (std::ostream& os) const | |
1104 { | |
1105 return cond ()->short_print (os); | |
1106 } | |
1107 | |
1108 llvm::Value *cond_llvm (void) const | |
1109 { | |
1110 return cond ()->to_llvm (); | |
1111 } | |
1112 | |
1113 virtual size_t successor_count (void) const { return 2; } | |
1114 | |
1115 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
1116 { | |
1117 print_indent (os, indent) << "cond_branch: "; | |
1118 print_cond (os) << ", "; | |
1119 print_successor (os, 0) << ", "; | |
1120 return print_successor (os, 1); | |
1121 } | |
1122 | |
1123 JIT_VALUE_ACCEPT; | |
1124 }; | |
1125 | |
1126 class | |
1127 jit_call : public jit_instruction | |
1128 { | |
1129 public: | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1130 jit_call (const jit_operation& (*aoperation) (void)) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1131 : moperation (aoperation ()) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1132 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1133 const jit_function& ol = overload (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1134 if (ol.valid ()) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1135 stash_type (ol.result ()); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1136 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1137 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1138 jit_call (const jit_operation& aoperation) : moperation (aoperation) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1139 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1140 const jit_function& ol = overload (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1141 if (ol.valid ()) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1142 stash_type (ol.result ()); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1143 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1144 |
15016 | 1145 #define JIT_CALL_CONST(N) \ |
1146 jit_call (const jit_operation& aoperation, \ | |
1147 OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ | |
1148 : jit_instruction (OCT_MAKE_ARG_LIST (arg, N)), moperation (aoperation) {} \ | |
1149 \ | |
1150 jit_call (const jit_operation& (*aoperation) (void), \ | |
1151 OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ | |
1152 : jit_instruction (OCT_MAKE_ARG_LIST (arg, N)), moperation (aoperation ()) \ | |
1153 {} | |
1154 | |
1155 JIT_CALL_CONST (1) | |
1156 JIT_CALL_CONST (2) | |
1157 JIT_CALL_CONST (3) | |
1158 JIT_CALL_CONST (4) | |
1159 | |
1160 #undef JIT_CALL_CONST | |
1161 | |
15067 | 1162 jit_call (const jit_operation& aoperation, |
1163 const std::vector<jit_value *>& args) | |
1164 : jit_instruction (args), moperation (aoperation) | |
1165 {} | |
15016 | 1166 |
1167 const jit_operation& operation (void) const { return moperation; } | |
1168 | |
1169 bool can_error (void) const | |
1170 { | |
1171 return overload ().can_error (); | |
1172 } | |
1173 | |
1174 const jit_function& overload (void) const | |
1175 { | |
1176 return moperation.overload (argument_types ()); | |
1177 } | |
1178 | |
15603 | 1179 virtual bool needs_release (void) const; |
15016 | 1180 |
1181 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
1182 { | |
1183 print_indent (os, indent); | |
1184 | |
1185 if (use_count ()) | |
1186 short_print (os) << " = "; | |
1187 os << "call " << moperation.name () << " ("; | |
1188 | |
1189 for (size_t i = 0; i < argument_count (); ++i) | |
1190 { | |
1191 print_argument (os, i); | |
1192 if (i + 1 < argument_count ()) | |
1193 os << ", "; | |
1194 } | |
1195 return os << ")"; | |
1196 } | |
1197 | |
1198 virtual bool infer (void); | |
1199 | |
1200 JIT_VALUE_ACCEPT; | |
1201 private: | |
1202 const jit_operation& moperation; | |
1203 }; | |
1204 | |
1205 // FIXME: This is just ugly... | |
15594
a7b22144318a
jit-ir.h: Fix typo in comment
Max Brister <max@2bass.com>
parents:
15337
diff
changeset
|
1206 // checks error_state, if error_state is false then goto the normal branch, |
15016 | 1207 // otherwise goto the error branch |
1208 class | |
1209 jit_error_check : public jit_terminator | |
1210 { | |
1211 public: | |
15603 | 1212 // Which variable is the error check for? |
1213 enum variable | |
1214 { | |
1215 var_error_state, | |
1216 var_interrupt | |
1217 }; | |
1218 | |
1219 static std::string variable_to_string (variable v); | |
1220 | |
1221 jit_error_check (variable var, jit_call *acheck_for, jit_block *normal, | |
1222 jit_block *error) | |
1223 : jit_terminator (2, error, normal, acheck_for), mvariable (var) {} | |
1224 | |
1225 jit_error_check (variable var, jit_block *normal, jit_block *error) | |
1226 : jit_terminator (2, error, normal), mvariable (var) {} | |
1227 | |
1228 variable check_variable (void) const { return mvariable; } | |
1229 | |
1230 bool has_check_for (void) const | |
1231 { | |
1232 return argument_count () == 3; | |
1233 } | |
15016 | 1234 |
1235 jit_call *check_for (void) const | |
1236 { | |
15603 | 1237 assert (has_check_for ()); |
15016 | 1238 return static_cast<jit_call *> (argument (2)); |
1239 } | |
1240 | |
15603 | 1241 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const; |
15016 | 1242 |
1243 JIT_VALUE_ACCEPT; | |
1244 protected: | |
1245 virtual bool check_alive (size_t idx) const | |
1246 { | |
15603 | 1247 if (! has_check_for ()) |
1248 return true; | |
15016 | 1249 return idx == 1 ? true : check_for ()->can_error (); |
1250 } | |
15603 | 1251 private: |
1252 variable mvariable; | |
15016 | 1253 }; |
1254 | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1255 // for now only handles the 1D case |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1256 class |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1257 jit_magic_end : public jit_instruction |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1258 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1259 public: |
15067 | 1260 class |
1261 context | |
1262 { | |
1263 public: | |
1264 context (void) : value (0), index (0), count (0) | |
1265 {} | |
1266 | |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
1267 context (jit_factory& factory, jit_value *avalue, size_t aindex, |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1268 size_t acount); |
15067 | 1269 |
1270 jit_value *value; | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1271 jit_const_index *index; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1272 jit_const_index *count; |
15067 | 1273 }; |
1274 | |
1275 jit_magic_end (const std::vector<context>& full_context); | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1276 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1277 virtual bool infer (void); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1278 |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1279 const jit_function& overload () const; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1280 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1281 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1282 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1283 context resolve_context (void) const; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1284 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1285 virtual std::ostream& short_print (std::ostream& os) const |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1286 { |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1287 return os << "magic_end" << "#" << id (); |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1288 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1289 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1290 JIT_VALUE_ACCEPT; |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1291 private: |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
1292 std::vector<context> contexts; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1293 }; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
1294 |
15016 | 1295 class |
1296 jit_extract_argument : public jit_assign_base | |
1297 { | |
1298 public: | |
1299 jit_extract_argument (jit_type *atype, jit_variable *adest) | |
1300 : jit_assign_base (adest) | |
1301 { | |
1302 stash_type (atype); | |
1303 } | |
1304 | |
1305 const std::string& name (void) const | |
1306 { | |
1307 return dest ()->name (); | |
1308 } | |
1309 | |
1310 const jit_function& overload (void) const | |
1311 { | |
1312 return jit_typeinfo::cast (type (), jit_typeinfo::get_any ()); | |
1313 } | |
1314 | |
1315 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
1316 { | |
1317 print_indent (os, indent); | |
1318 | |
1319 return short_print (os) << " = extract " << name (); | |
1320 } | |
1321 | |
1322 JIT_VALUE_ACCEPT; | |
1323 }; | |
1324 | |
1325 class | |
1326 jit_store_argument : public jit_instruction | |
1327 { | |
1328 public: | |
1329 jit_store_argument (jit_variable *var) | |
1330 : jit_instruction (var), dest (var) | |
1331 {} | |
1332 | |
1333 const std::string& name (void) const | |
1334 { | |
1335 return dest->name (); | |
1336 } | |
1337 | |
1338 const jit_function& overload (void) const | |
1339 { | |
1340 return jit_typeinfo::cast (jit_typeinfo::get_any (), result_type ()); | |
1341 } | |
1342 | |
1343 jit_value *result (void) const | |
1344 { | |
1345 return argument (0); | |
1346 } | |
1347 | |
1348 jit_type *result_type (void) const | |
1349 { | |
1350 return result ()->type (); | |
1351 } | |
1352 | |
1353 llvm::Value *result_llvm (void) const | |
1354 { | |
1355 return result ()->to_llvm (); | |
1356 } | |
1357 | |
1358 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const | |
1359 { | |
1360 jit_value *res = result (); | |
1361 print_indent (os, indent) << "store "; | |
1362 dest->short_print (os); | |
1363 | |
1364 if (! isa<jit_variable> (res)) | |
1365 { | |
1366 os << " = "; | |
1367 res->short_print (os); | |
1368 } | |
1369 | |
1370 return os; | |
1371 } | |
1372 | |
1373 JIT_VALUE_ACCEPT; | |
1374 private: | |
1375 jit_variable *dest; | |
1376 }; | |
1377 | |
1378 class | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1379 jit_return : public jit_instruction |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1380 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1381 public: |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1382 jit_return (void) {} |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1383 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1384 jit_return (jit_value *retval) : jit_instruction (retval) {} |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1385 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1386 jit_value *result (void) const |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1387 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1388 return argument_count () ? argument (0) : 0; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1389 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1390 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1391 jit_type *result_type (void) const |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1392 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1393 jit_value *res = result (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1394 return res ? res->type () : 0; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1395 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1396 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1397 virtual std::ostream& print (std::ostream& os, size_t indent = 0) const |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1398 { |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1399 print_indent (os, indent) << "return"; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1400 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1401 if (result ()) |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1402 os << " " << *result (); |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1403 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1404 return os; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1405 } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1406 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1407 JIT_VALUE_ACCEPT; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1408 }; |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1409 |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15232
diff
changeset
|
1410 class |
15016 | 1411 jit_ir_walker |
1412 { | |
1413 public: | |
1414 virtual ~jit_ir_walker () {} | |
1415 | |
1416 #define JIT_METH(clname) \ | |
1417 virtual void visit (jit_ ## clname&) = 0; | |
1418 | |
1419 JIT_VISIT_IR_CLASSES; | |
1420 | |
1421 #undef JIT_METH | |
1422 }; | |
1423 | |
1424 template <typename T, jit_type *(*EXTRACT_T)(void), typename PASS_T, bool QUOTE> | |
1425 void | |
1426 jit_const<T, EXTRACT_T, PASS_T, QUOTE>::accept (jit_ir_walker& walker) | |
1427 { | |
1428 walker.visit (*this); | |
1429 } | |
1430 | |
1431 #undef JIT_VALUE_ACCEPT | |
1432 | |
1433 #endif | |
1434 #endif |