Mercurial > octave-nkf
annotate libinterp/corefcn/jit-ir.cc @ 18600:67445219aee2 draft
-Werror at JIT related files
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 21 Mar 2014 14:59:39 -0400 |
parents | d63878346099 |
children |
rev | line source |
---|---|
18600 | 1 #pragma GCC diagnostic push |
2 #pragma GCC diagnostic error "-Werror" | |
15016 | 3 /* |
4 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17164
diff
changeset
|
5 Copyright (C) 2012-2013 Max Brister |
15016 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
11 Free Software Foundation; either version 3 of the License, or (at your | |
12 option) any later version. | |
13 | |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with Octave; see the file COPYING. If not, see | |
21 <http://www.gnu.org/licenses/>. | |
22 | |
23 */ | |
24 | |
16768 | 25 // Author: Max Brister <max@2bass.com> |
26 | |
15016 | 27 // defines required by llvm |
28 #define __STDC_LIMIT_MACROS | |
29 #define __STDC_CONSTANT_MACROS | |
30 | |
31 #ifdef HAVE_CONFIG_H | |
32 #include <config.h> | |
33 #endif | |
34 | |
35 #ifdef HAVE_LLVM | |
36 | |
37 #include "jit-ir.h" | |
38 | |
17164 | 39 #ifdef HAVE_LLVM_IR_FUNCTION_H |
40 #include <llvm/IR/BasicBlock.h> | |
41 #include <llvm/IR/Instructions.h> | |
42 #else | |
15016 | 43 #include <llvm/BasicBlock.h> |
44 #include <llvm/Instructions.h> | |
17164 | 45 #endif |
15016 | 46 |
47 #include "error.h" | |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
48 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
49 // -------------------- jit_factory -------------------- |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
50 jit_factory::~jit_factory (void) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
51 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
52 for (value_list::iterator iter = all_values.begin (); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
53 iter != all_values.end (); ++iter) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
54 delete *iter; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
55 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
56 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
57 void |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
58 jit_factory::track_value (jit_value *value) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
59 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
60 if (value->type ()) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
61 mconstants.push_back (value); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
62 all_values.push_back (value); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
63 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
64 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
65 // -------------------- jit_block_list -------------------- |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
66 void |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
67 jit_block_list::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:
15171
diff
changeset
|
68 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
69 ++iter; |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
70 insert_before (iter, ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
71 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
72 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
73 void |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
74 jit_block_list::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:
15171
diff
changeset
|
75 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
76 insert_after (loc->location (), ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
77 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
78 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
79 void |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
80 jit_block_list::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:
15171
diff
changeset
|
81 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
82 iter = mlist.insert (iter, ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
83 ablock->stash_location (iter); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
84 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
85 |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
86 void |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
87 jit_block_list::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:
15171
diff
changeset
|
88 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
89 insert_before (loc->location (), ablock); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
90 } |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
91 |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
92 void |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
93 jit_block_list::label (void) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
94 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
95 if (mlist.size ()) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
96 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
97 jit_block *block = mlist.back (); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
98 block->label (); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
99 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
100 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
101 |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
102 std::ostream& |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
103 jit_block_list::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
|
104 { |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
105 os << "-------------------- " << header << " --------------------\n"; |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
106 return os << *this; |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
107 } |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
108 |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
109 std::ostream& |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
110 jit_block_list::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
|
111 { |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
112 os << "-------------------- dom info --------------------\n"; |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
113 for (const_iterator iter = begin (); iter != end (); ++iter) |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
114 { |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
115 assert (*iter); |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
116 (*iter)->print_dom (os); |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
117 } |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
118 os << std::endl; |
15259
4f1a4923a19e
Add missing return value in JIT code.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15195
diff
changeset
|
119 |
4f1a4923a19e
Add missing return value in JIT code.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15195
diff
changeset
|
120 return os; |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
121 } |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
122 |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
123 void |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
124 jit_block_list::push_back (jit_block *b) |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
125 { |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
126 mlist.push_back (b); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
127 iterator iter = mlist.end (); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
128 b->stash_location (--iter); |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
129 } |
15016 | 130 |
15191
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
131 std::ostream& |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
132 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
|
133 { |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
134 for (jit_block_list::const_iterator iter = blocks.begin (); |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
135 iter != blocks.end (); ++iter) |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
136 { |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
137 assert (*iter); |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
138 (*iter)->print (os, 0); |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
139 } |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
140 return os << std::endl; |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
141 } |
ed4f4fb78586
Move type inference from jit_convert to jit_infer
Max Brister <max@2bass.com>
parents:
15182
diff
changeset
|
142 |
15016 | 143 // -------------------- jit_use -------------------- |
144 jit_block * | |
145 jit_use::user_parent (void) const | |
146 { | |
147 return muser->parent (); | |
148 } | |
149 | |
150 // -------------------- jit_value -------------------- | |
151 jit_value::~jit_value (void) | |
152 {} | |
153 | |
154 jit_block * | |
155 jit_value::first_use_block (void) | |
156 { | |
157 jit_use *use = first_use (); | |
158 while (use) | |
159 { | |
160 if (! isa<jit_error_check> (use->user ())) | |
161 return use->user_parent (); | |
162 | |
163 use = use->next (); | |
164 } | |
165 | |
166 return 0; | |
167 } | |
168 | |
169 void | |
170 jit_value::replace_with (jit_value *value) | |
171 { | |
172 while (first_use ()) | |
173 { | |
174 jit_instruction *user = first_use ()->user (); | |
175 size_t idx = first_use ()->index (); | |
176 user->stash_argument (idx, value); | |
177 } | |
178 } | |
179 | |
180 #define JIT_METH(clname) \ | |
181 void \ | |
182 jit_ ## clname::accept (jit_ir_walker& walker) \ | |
183 { \ | |
184 walker.visit (*this); \ | |
185 } | |
186 | |
187 JIT_VISIT_IR_NOTEMPLATE | |
188 #undef JIT_METH | |
189 | |
190 std::ostream& | |
191 operator<< (std::ostream& os, const jit_value& value) | |
192 { | |
193 return value.short_print (os); | |
194 } | |
195 | |
196 std::ostream& | |
197 jit_print (std::ostream& os, jit_value *avalue) | |
198 { | |
199 if (avalue) | |
200 return avalue->print (os); | |
201 return os << "NULL"; | |
202 } | |
203 | |
204 // -------------------- jit_instruction -------------------- | |
205 void | |
206 jit_instruction::remove (void) | |
207 { | |
208 if (mparent) | |
209 mparent->remove (mlocation); | |
210 resize_arguments (0); | |
211 } | |
212 | |
213 llvm::BasicBlock * | |
214 jit_instruction::parent_llvm (void) const | |
215 { | |
216 return mparent->to_llvm (); | |
217 } | |
218 | |
219 std::ostream& | |
220 jit_instruction::short_print (std::ostream& os) const | |
221 { | |
222 if (type ()) | |
223 jit_print (os, type ()) << ": "; | |
224 return os << "#" << mid; | |
225 } | |
226 | |
227 void | |
228 jit_instruction::do_construct_ssa (size_t start, size_t end) | |
229 { | |
230 for (size_t i = start; i < end; ++i) | |
231 { | |
232 jit_value *arg = argument (i); | |
233 jit_variable *var = dynamic_cast<jit_variable *> (arg); | |
234 if (var && var->has_top ()) | |
235 stash_argument (i, var->top ()); | |
236 } | |
237 } | |
238 | |
239 // -------------------- jit_block -------------------- | |
240 void | |
241 jit_block::replace_with (jit_value *value) | |
242 { | |
243 assert (isa<jit_block> (value)); | |
244 jit_block *block = static_cast<jit_block *> (value); | |
245 | |
246 jit_value::replace_with (block); | |
247 | |
248 while (ILIST_T::first_use ()) | |
249 { | |
250 jit_phi_incomming *incomming = ILIST_T::first_use (); | |
251 incomming->stash_value (block); | |
252 } | |
253 } | |
254 | |
255 void | |
256 jit_block::replace_in_phi (jit_block *ablock, jit_block *with) | |
257 { | |
258 jit_phi_incomming *node = ILIST_T::first_use (); | |
259 while (node) | |
260 { | |
261 jit_phi_incomming *prev = node; | |
262 node = node->next (); | |
263 | |
264 if (prev->user_parent () == ablock) | |
265 prev->stash_value (with); | |
266 } | |
267 } | |
268 | |
269 jit_block * | |
270 jit_block::maybe_merge () | |
271 { | |
272 if (successor_count () == 1 && successor (0) != this | |
273 && (successor (0)->use_count () == 1 || instructions.size () == 1)) | |
274 { | |
275 jit_block *to_merge = successor (0); | |
276 merge (*to_merge); | |
277 return to_merge; | |
278 } | |
279 | |
280 return 0; | |
281 } | |
282 | |
283 void | |
284 jit_block::merge (jit_block& block) | |
285 { | |
286 // the merge block will contain a new terminator | |
287 jit_terminator *old_term = terminator (); | |
288 if (old_term) | |
289 old_term->remove (); | |
290 | |
291 bool was_empty = end () == begin (); | |
292 iterator merge_begin = end (); | |
293 if (! was_empty) | |
294 --merge_begin; | |
295 | |
296 instructions.splice (end (), block.instructions); | |
297 if (was_empty) | |
298 merge_begin = begin (); | |
299 else | |
300 ++merge_begin; | |
301 | |
302 // now merge_begin points to the start of the new instructions, we must | |
303 // update their parent information | |
304 for (iterator iter = merge_begin; iter != end (); ++iter) | |
305 { | |
306 jit_instruction *instr = *iter; | |
307 instr->stash_parent (this, iter); | |
308 } | |
309 | |
310 block.replace_with (this); | |
311 } | |
312 | |
313 jit_instruction * | |
314 jit_block::prepend (jit_instruction *instr) | |
315 { | |
316 instructions.push_front (instr); | |
317 instr->stash_parent (this, instructions.begin ()); | |
318 return instr; | |
319 } | |
320 | |
321 jit_instruction * | |
322 jit_block::prepend_after_phi (jit_instruction *instr) | |
323 { | |
324 // FIXME: Make this O(1) | |
325 for (iterator iter = begin (); iter != end (); ++iter) | |
326 { | |
327 jit_instruction *temp = *iter; | |
328 if (! isa<jit_phi> (temp)) | |
329 { | |
330 insert_before (iter, instr); | |
331 return instr; | |
332 } | |
333 } | |
334 | |
335 return append (instr); | |
336 } | |
337 | |
338 void | |
339 jit_block::internal_append (jit_instruction *instr) | |
340 { | |
341 instructions.push_back (instr); | |
342 instr->stash_parent (this, --instructions.end ()); | |
343 } | |
344 | |
345 jit_instruction * | |
346 jit_block::insert_before (iterator loc, jit_instruction *instr) | |
347 { | |
348 iterator iloc = instructions.insert (loc, instr); | |
349 instr->stash_parent (this, iloc); | |
350 return instr; | |
351 } | |
352 | |
353 jit_instruction * | |
354 jit_block::insert_after (iterator loc, jit_instruction *instr) | |
355 { | |
356 ++loc; | |
357 iterator iloc = instructions.insert (loc, instr); | |
358 instr->stash_parent (this, iloc); | |
359 return instr; | |
360 } | |
361 | |
362 jit_terminator * | |
363 jit_block::terminator (void) const | |
364 { | |
365 assert (this); | |
366 if (instructions.empty ()) | |
367 return 0; | |
368 | |
369 jit_instruction *last = instructions.back (); | |
370 return dynamic_cast<jit_terminator *> (last); | |
371 } | |
372 | |
373 bool | |
374 jit_block::branch_alive (jit_block *asucc) const | |
375 { | |
376 return terminator ()->alive (asucc); | |
377 } | |
378 | |
379 jit_block * | |
380 jit_block::successor (size_t i) const | |
381 { | |
382 jit_terminator *term = terminator (); | |
383 return term->successor (i); | |
384 } | |
385 | |
386 size_t | |
387 jit_block::successor_count (void) const | |
388 { | |
389 jit_terminator *term = terminator (); | |
390 return term ? term->successor_count () : 0; | |
391 } | |
392 | |
393 llvm::BasicBlock * | |
394 jit_block::to_llvm (void) const | |
395 { | |
396 return llvm::cast<llvm::BasicBlock> (llvm_value); | |
397 } | |
398 | |
399 std::ostream& | |
400 jit_block::print_dom (std::ostream& os) const | |
401 { | |
402 short_print (os); | |
403 os << ":\n"; | |
404 os << " mid: " << mid << std::endl; | |
405 os << " predecessors: "; | |
406 for (jit_use *use = first_use (); use; use = use->next ()) | |
407 os << *use->user_parent () << " "; | |
408 os << std::endl; | |
409 | |
410 os << " successors: "; | |
411 for (size_t i = 0; i < successor_count (); ++i) | |
412 os << *successor (i) << " "; | |
413 os << std::endl; | |
414 | |
415 os << " idom: "; | |
416 if (idom) | |
417 os << *idom; | |
418 else | |
419 os << "NULL"; | |
420 os << std::endl; | |
421 os << " df: "; | |
422 for (df_iterator iter = df_begin (); iter != df_end (); ++iter) | |
423 os << **iter << " "; | |
424 os << std::endl; | |
425 | |
426 os << " dom_succ: "; | |
427 for (size_t i = 0; i < dom_succ.size (); ++i) | |
428 os << *dom_succ[i] << " "; | |
429 | |
430 return os << std::endl; | |
431 } | |
432 | |
433 void | |
434 jit_block::compute_df (size_t avisit_count) | |
435 { | |
436 if (visited (avisit_count)) | |
437 return; | |
438 | |
439 if (use_count () >= 2) | |
440 { | |
441 for (jit_use *use = first_use (); use; use = use->next ()) | |
442 { | |
443 jit_block *runner = use->user_parent (); | |
444 while (runner != idom) | |
445 { | |
446 runner->mdf.insert (this); | |
447 runner = runner->idom; | |
448 } | |
449 } | |
450 } | |
451 | |
452 for (size_t i = 0; i < successor_count (); ++i) | |
453 successor (i)->compute_df (avisit_count); | |
454 } | |
455 | |
456 bool | |
457 jit_block::update_idom (size_t avisit_count) | |
458 { | |
459 if (visited (avisit_count) || ! use_count ()) | |
460 return false; | |
461 | |
462 bool changed = false; | |
463 for (jit_use *use = first_use (); use; use = use->next ()) | |
464 { | |
465 jit_block *pred = use->user_parent (); | |
466 changed = pred->update_idom (avisit_count) || changed; | |
467 } | |
468 | |
469 jit_use *use = first_use (); | |
470 jit_block *new_idom = use->user_parent (); | |
471 use = use->next (); | |
472 | |
473 for (; use; use = use->next ()) | |
474 { | |
475 jit_block *pred = use->user_parent (); | |
476 jit_block *pidom = pred->idom; | |
477 if (pidom) | |
478 new_idom = idom_intersect (pidom, new_idom); | |
479 } | |
480 | |
481 if (idom != new_idom) | |
482 { | |
483 idom = new_idom; | |
484 return true; | |
485 } | |
486 | |
487 return changed; | |
488 } | |
489 | |
490 void | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
491 jit_block::label (size_t avisit_count, size_t& number) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
492 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
493 if (visited (avisit_count)) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
494 return; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
495 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
496 for (jit_use *use = first_use (); use; use = use->next ()) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
497 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
498 jit_block *pred = use->user_parent (); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
499 pred->label (avisit_count, number); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
500 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
501 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
502 mid = number++; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
503 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
504 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
505 void |
15016 | 506 jit_block::pop_all (void) |
507 { | |
508 for (iterator iter = begin (); iter != end (); ++iter) | |
509 { | |
510 jit_instruction *instr = *iter; | |
511 instr->pop_variable (); | |
512 } | |
513 } | |
514 | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
515 std::ostream& |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
516 jit_block::print (std::ostream& os, size_t indent) const |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
517 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
518 print_indent (os, indent); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
519 short_print (os) << ": %pred = "; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
520 for (jit_use *use = first_use (); use; use = use->next ()) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
521 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
522 jit_block *pred = use->user_parent (); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
523 os << *pred; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
524 if (use->next ()) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
525 os << ", "; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
526 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
527 os << std::endl; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
528 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
529 for (const_iterator iter = begin (); iter != end (); ++iter) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
530 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
531 jit_instruction *instr = *iter; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
532 instr->print (os, indent + 1) << std::endl; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
533 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
534 return os; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
535 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
536 |
15016 | 537 jit_block * |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
538 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:
15171
diff
changeset
|
539 jit_block *asuccessor) |
15016 | 540 { |
541 if (successor_count () > 1) | |
542 { | |
543 jit_terminator *term = terminator (); | |
544 size_t idx = term->successor_index (asuccessor); | |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
545 jit_block *split = factory.create<jit_block> ("phi_split", mvisit_count); |
15016 | 546 |
15171
7a19e8275d41
Do not simplify the CFG during type inference
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
547 // place after this to ensure define before use in the blocks list |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
548 blocks.insert_after (this, split); |
15016 | 549 |
550 term->stash_argument (idx, split); | |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
551 jit_branch *br = split->append (factory.create<jit_branch> (asuccessor)); |
15016 | 552 replace_in_phi (asuccessor, split); |
553 | |
554 if (alive ()) | |
555 { | |
556 split->mark_alive (); | |
557 br->infer (); | |
558 } | |
559 | |
560 return split; | |
561 } | |
562 | |
563 return this; | |
564 } | |
565 | |
566 void | |
567 jit_block::create_dom_tree (size_t avisit_count) | |
568 { | |
569 if (visited (avisit_count)) | |
570 return; | |
571 | |
572 if (idom != this) | |
573 idom->dom_succ.push_back (this); | |
574 | |
575 for (size_t i = 0; i < successor_count (); ++i) | |
576 successor (i)->create_dom_tree (avisit_count); | |
577 } | |
578 | |
579 jit_block * | |
580 jit_block::idom_intersect (jit_block *i, jit_block *j) | |
581 { | |
582 while (i && j && i != j) | |
583 { | |
584 while (i && i->id () > j->id ()) | |
585 i = i->idom; | |
586 | |
587 while (i && j && j->id () > i->id ()) | |
588 j = j->idom; | |
589 } | |
590 | |
591 return i ? i : j; | |
592 } | |
593 | |
594 // -------------------- jit_phi_incomming -------------------- | |
595 | |
596 jit_block * | |
597 jit_phi_incomming::user_parent (void) const | |
598 { return muser->parent (); } | |
599 | |
600 // -------------------- jit_phi -------------------- | |
601 bool | |
602 jit_phi::prune (void) | |
603 { | |
604 jit_block *p = parent (); | |
605 size_t new_idx = 0; | |
606 jit_value *unique = argument (1); | |
607 | |
608 for (size_t i = 0; i < argument_count (); ++i) | |
609 { | |
610 jit_block *inc = incomming (i); | |
611 if (inc->branch_alive (p)) | |
612 { | |
613 if (unique != argument (i)) | |
614 unique = 0; | |
615 | |
616 if (new_idx != i) | |
617 { | |
618 stash_argument (new_idx, argument (i)); | |
619 mincomming[new_idx].stash_value (inc); | |
620 } | |
621 | |
622 ++new_idx; | |
623 } | |
624 } | |
625 | |
626 if (new_idx != argument_count ()) | |
627 { | |
628 resize_arguments (new_idx); | |
629 mincomming.resize (new_idx); | |
630 } | |
631 | |
632 assert (argument_count () > 0); | |
633 if (unique) | |
634 { | |
635 replace_with (unique); | |
636 return true; | |
637 } | |
638 | |
639 return false; | |
640 } | |
641 | |
642 bool | |
643 jit_phi::infer (void) | |
644 { | |
645 jit_block *p = parent (); | |
646 if (! p->alive ()) | |
647 return false; | |
648 | |
649 jit_type *infered = 0; | |
650 for (size_t i = 0; i < argument_count (); ++i) | |
651 { | |
652 jit_block *inc = incomming (i); | |
653 if (inc->branch_alive (p)) | |
654 infered = jit_typeinfo::join (infered, argument_type (i)); | |
655 } | |
656 | |
657 if (infered != type ()) | |
658 { | |
659 stash_type (infered); | |
660 return true; | |
661 } | |
662 | |
663 return false; | |
664 } | |
665 | |
666 llvm::PHINode * | |
667 jit_phi::to_llvm (void) const | |
668 { | |
669 return llvm::cast<llvm::PHINode> (jit_value::to_llvm ()); | |
670 } | |
671 | |
672 // -------------------- jit_terminator -------------------- | |
673 size_t | |
674 jit_terminator::successor_index (const jit_block *asuccessor) const | |
675 { | |
676 size_t scount = successor_count (); | |
677 for (size_t i = 0; i < scount; ++i) | |
678 if (successor (i) == asuccessor) | |
679 return i; | |
680 | |
681 panic_impossible (); | |
682 } | |
683 | |
684 bool | |
685 jit_terminator::infer (void) | |
686 { | |
687 if (! parent ()->alive ()) | |
688 return false; | |
689 | |
690 bool changed = false; | |
691 for (size_t i = 0; i < malive.size (); ++i) | |
692 if (! malive[i] && check_alive (i)) | |
693 { | |
694 changed = true; | |
695 malive[i] = true; | |
696 successor (i)->mark_alive (); | |
697 } | |
698 | |
699 return changed; | |
700 } | |
701 | |
702 llvm::TerminatorInst * | |
703 jit_terminator::to_llvm (void) const | |
704 { | |
705 return llvm::cast<llvm::TerminatorInst> (jit_value::to_llvm ()); | |
706 } | |
707 | |
708 // -------------------- jit_call -------------------- | |
709 bool | |
15603 | 710 jit_call::needs_release (void) const |
711 { | |
712 if (type () && jit_typeinfo::get_release (type ()).valid ()) | |
713 { | |
714 for (jit_use *use = first_use (); use; use = use->next ()) | |
715 { | |
716 jit_assign *assign = dynamic_cast<jit_assign *> (use->user ()); | |
717 if (assign && assign->artificial ()) | |
718 return false; | |
719 } | |
720 | |
721 return true; | |
722 } | |
723 return false; | |
724 } | |
725 | |
726 bool | |
15016 | 727 jit_call::infer (void) |
728 { | |
729 // FIXME: explain algorithm | |
730 for (size_t i = 0; i < argument_count (); ++i) | |
731 { | |
732 already_infered[i] = argument_type (i); | |
733 if (! already_infered[i]) | |
734 return false; | |
735 } | |
736 | |
737 jit_type *infered = moperation.result (already_infered); | |
738 if (! infered && use_count ()) | |
739 { | |
740 std::stringstream ss; | |
741 ss << "Missing overload in type inference for "; | |
742 print (ss, 0); | |
743 throw jit_fail_exception (ss.str ()); | |
744 } | |
745 | |
746 if (infered != type ()) | |
747 { | |
748 stash_type (infered); | |
749 return true; | |
750 } | |
751 | |
752 return false; | |
753 } | |
754 | |
15603 | 755 // -------------------- jit_error_check -------------------- |
756 std::string | |
757 jit_error_check::variable_to_string (variable v) | |
758 { | |
759 switch (v) | |
760 { | |
761 case var_error_state: | |
762 return "error_state"; | |
763 case var_interrupt: | |
764 return "interrupt"; | |
765 default: | |
766 panic_impossible (); | |
767 } | |
768 } | |
769 | |
770 std::ostream& | |
771 jit_error_check::print (std::ostream& os, size_t indent) const | |
772 { | |
773 print_indent (os, indent) << "error_check " << variable_to_string (mvariable) | |
774 << ", "; | |
775 | |
776 if (has_check_for ()) | |
777 os << "<for> " << *check_for () << ", "; | |
778 print_successor (os << "<normal> ", 1) << ", "; | |
779 return print_successor (os << "<error> ", 0); | |
780 } | |
781 | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
782 // -------------------- jit_magic_end -------------------- |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
783 jit_magic_end::context::context (jit_factory& factory, jit_value *avalue, |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
784 size_t aindex, size_t acount) |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
785 : value (avalue), index (factory.create<jit_const_index> (aindex)), |
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
786 count (factory.create<jit_const_index> (acount)) |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
787 {} |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
788 |
15067 | 789 jit_magic_end::jit_magic_end (const std::vector<context>& full_context) |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
790 : contexts (full_context) |
15067 | 791 { |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
792 resize_arguments (contexts.size ()); |
15067 | 793 |
794 size_t i; | |
795 std::vector<context>::const_iterator iter; | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
796 for (iter = contexts.begin (), i = 0; iter != contexts.end (); ++iter, ++i) |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
797 stash_argument (i, iter->value); |
15067 | 798 } |
799 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
800 jit_magic_end::context |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
801 jit_magic_end::resolve_context (void) const |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
802 { |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
803 size_t idx; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
804 for (idx = 0; idx < contexts.size (); ++idx) |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
805 { |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
806 jit_type *ctx_type = contexts[idx].value->type (); |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
807 if (! ctx_type || ctx_type->skip_paren ()) |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
808 break; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
809 } |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
810 |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
811 if (idx >= contexts.size ()) |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
812 idx = 0; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
813 |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
814 context ret = contexts[idx]; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
815 ret.value = argument (idx); |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
816 return ret; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
817 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
818 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
819 bool |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
820 jit_magic_end::infer (void) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
821 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
822 jit_type *new_type = overload ().result (); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
823 if (new_type != type ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
824 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
825 stash_type (new_type); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
826 return true; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
827 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
828 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
829 return false; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
830 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
831 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
832 std::ostream& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
833 jit_magic_end::print (std::ostream& os, size_t indent) const |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
834 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
835 context ctx = resolve_context (); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
836 short_print (print_indent (os, indent)) << " (" << *ctx.value << ", "; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
837 return os << *ctx.index << ", " << *ctx.count << ")"; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
838 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
839 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
840 const jit_function& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
841 jit_magic_end::overload () const |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
842 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
843 const context& ctx = resolve_context (); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
844 return jit_typeinfo::end (ctx.value, ctx.index, ctx.count); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
845 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
846 |
15016 | 847 #endif |
18600 | 848 |
849 #pragma GCC diagnostic pop |