Mercurial > octave-nkf
annotate libinterp/corefcn/jit-ir.cc @ 20654:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
15016 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 2012-2015 Max Brister |
15016 | 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 | |
16768 | 23 // Author: Max Brister <max@2bass.com> |
24 | |
15016 | 25 // defines required by llvm |
26 #define __STDC_LIMIT_MACROS | |
27 #define __STDC_CONSTANT_MACROS | |
28 | |
29 #ifdef HAVE_CONFIG_H | |
30 #include <config.h> | |
31 #endif | |
32 | |
20654 | 33 #ifdef HAVE_JIT |
15016 | 34 |
35 #include "jit-ir.h" | |
36 | |
20654 | 37 #if HAVE_LLVM |
17164 | 38 #ifdef HAVE_LLVM_IR_FUNCTION_H |
39 #include <llvm/IR/BasicBlock.h> | |
40 #include <llvm/IR/Instructions.h> | |
41 #else | |
15016 | 42 #include <llvm/BasicBlock.h> |
43 #include <llvm/Instructions.h> | |
17164 | 44 #endif |
20654 | 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 | |
20654 | 213 #if HAVE_LLVM |
15016 | 214 llvm::BasicBlock * |
215 jit_instruction::parent_llvm (void) const | |
216 { | |
217 return mparent->to_llvm (); | |
218 } | |
20654 | 219 #endif |
15016 | 220 |
221 std::ostream& | |
222 jit_instruction::short_print (std::ostream& os) const | |
223 { | |
224 if (type ()) | |
225 jit_print (os, type ()) << ": "; | |
226 return os << "#" << mid; | |
227 } | |
228 | |
229 void | |
230 jit_instruction::do_construct_ssa (size_t start, size_t end) | |
231 { | |
232 for (size_t i = start; i < end; ++i) | |
233 { | |
234 jit_value *arg = argument (i); | |
235 jit_variable *var = dynamic_cast<jit_variable *> (arg); | |
236 if (var && var->has_top ()) | |
237 stash_argument (i, var->top ()); | |
238 } | |
239 } | |
240 | |
241 // -------------------- jit_block -------------------- | |
242 void | |
243 jit_block::replace_with (jit_value *value) | |
244 { | |
245 assert (isa<jit_block> (value)); | |
246 jit_block *block = static_cast<jit_block *> (value); | |
247 | |
248 jit_value::replace_with (block); | |
249 | |
250 while (ILIST_T::first_use ()) | |
251 { | |
252 jit_phi_incomming *incomming = ILIST_T::first_use (); | |
253 incomming->stash_value (block); | |
254 } | |
255 } | |
256 | |
257 void | |
258 jit_block::replace_in_phi (jit_block *ablock, jit_block *with) | |
259 { | |
260 jit_phi_incomming *node = ILIST_T::first_use (); | |
261 while (node) | |
262 { | |
263 jit_phi_incomming *prev = node; | |
264 node = node->next (); | |
265 | |
266 if (prev->user_parent () == ablock) | |
267 prev->stash_value (with); | |
268 } | |
269 } | |
270 | |
271 jit_block * | |
272 jit_block::maybe_merge () | |
273 { | |
274 if (successor_count () == 1 && successor (0) != this | |
275 && (successor (0)->use_count () == 1 || instructions.size () == 1)) | |
276 { | |
277 jit_block *to_merge = successor (0); | |
278 merge (*to_merge); | |
279 return to_merge; | |
280 } | |
281 | |
282 return 0; | |
283 } | |
284 | |
285 void | |
286 jit_block::merge (jit_block& block) | |
287 { | |
288 // the merge block will contain a new terminator | |
289 jit_terminator *old_term = terminator (); | |
290 if (old_term) | |
291 old_term->remove (); | |
292 | |
293 bool was_empty = end () == begin (); | |
294 iterator merge_begin = end (); | |
295 if (! was_empty) | |
296 --merge_begin; | |
297 | |
298 instructions.splice (end (), block.instructions); | |
299 if (was_empty) | |
300 merge_begin = begin (); | |
301 else | |
302 ++merge_begin; | |
303 | |
304 // now merge_begin points to the start of the new instructions, we must | |
305 // update their parent information | |
306 for (iterator iter = merge_begin; iter != end (); ++iter) | |
307 { | |
308 jit_instruction *instr = *iter; | |
309 instr->stash_parent (this, iter); | |
310 } | |
311 | |
312 block.replace_with (this); | |
313 } | |
314 | |
315 jit_instruction * | |
316 jit_block::prepend (jit_instruction *instr) | |
317 { | |
318 instructions.push_front (instr); | |
319 instr->stash_parent (this, instructions.begin ()); | |
320 return instr; | |
321 } | |
322 | |
323 jit_instruction * | |
324 jit_block::prepend_after_phi (jit_instruction *instr) | |
325 { | |
326 // FIXME: Make this O(1) | |
327 for (iterator iter = begin (); iter != end (); ++iter) | |
328 { | |
329 jit_instruction *temp = *iter; | |
330 if (! isa<jit_phi> (temp)) | |
331 { | |
332 insert_before (iter, instr); | |
333 return instr; | |
334 } | |
335 } | |
336 | |
337 return append (instr); | |
338 } | |
339 | |
340 void | |
341 jit_block::internal_append (jit_instruction *instr) | |
342 { | |
343 instructions.push_back (instr); | |
344 instr->stash_parent (this, --instructions.end ()); | |
345 } | |
346 | |
347 jit_instruction * | |
348 jit_block::insert_before (iterator loc, jit_instruction *instr) | |
349 { | |
350 iterator iloc = instructions.insert (loc, instr); | |
351 instr->stash_parent (this, iloc); | |
352 return instr; | |
353 } | |
354 | |
355 jit_instruction * | |
356 jit_block::insert_after (iterator loc, jit_instruction *instr) | |
357 { | |
358 ++loc; | |
359 iterator iloc = instructions.insert (loc, instr); | |
360 instr->stash_parent (this, iloc); | |
361 return instr; | |
362 } | |
363 | |
364 jit_terminator * | |
365 jit_block::terminator (void) const | |
366 { | |
367 assert (this); | |
368 if (instructions.empty ()) | |
369 return 0; | |
370 | |
371 jit_instruction *last = instructions.back (); | |
372 return dynamic_cast<jit_terminator *> (last); | |
373 } | |
374 | |
375 bool | |
376 jit_block::branch_alive (jit_block *asucc) const | |
377 { | |
378 return terminator ()->alive (asucc); | |
379 } | |
380 | |
381 jit_block * | |
382 jit_block::successor (size_t i) const | |
383 { | |
384 jit_terminator *term = terminator (); | |
385 return term->successor (i); | |
386 } | |
387 | |
388 size_t | |
389 jit_block::successor_count (void) const | |
390 { | |
391 jit_terminator *term = terminator (); | |
392 return term ? term->successor_count () : 0; | |
393 } | |
394 | |
20654 | 395 #if HAVE_LLVM |
15016 | 396 llvm::BasicBlock * |
397 jit_block::to_llvm (void) const | |
398 { | |
399 return llvm::cast<llvm::BasicBlock> (llvm_value); | |
400 } | |
20654 | 401 #endif |
15016 | 402 |
403 std::ostream& | |
404 jit_block::print_dom (std::ostream& os) const | |
405 { | |
406 short_print (os); | |
407 os << ":\n"; | |
408 os << " mid: " << mid << std::endl; | |
409 os << " predecessors: "; | |
410 for (jit_use *use = first_use (); use; use = use->next ()) | |
411 os << *use->user_parent () << " "; | |
412 os << std::endl; | |
413 | |
414 os << " successors: "; | |
415 for (size_t i = 0; i < successor_count (); ++i) | |
416 os << *successor (i) << " "; | |
417 os << std::endl; | |
418 | |
419 os << " idom: "; | |
420 if (idom) | |
421 os << *idom; | |
422 else | |
423 os << "NULL"; | |
424 os << std::endl; | |
425 os << " df: "; | |
426 for (df_iterator iter = df_begin (); iter != df_end (); ++iter) | |
427 os << **iter << " "; | |
428 os << std::endl; | |
429 | |
430 os << " dom_succ: "; | |
431 for (size_t i = 0; i < dom_succ.size (); ++i) | |
432 os << *dom_succ[i] << " "; | |
433 | |
434 return os << std::endl; | |
435 } | |
436 | |
437 void | |
438 jit_block::compute_df (size_t avisit_count) | |
439 { | |
440 if (visited (avisit_count)) | |
441 return; | |
442 | |
443 if (use_count () >= 2) | |
444 { | |
445 for (jit_use *use = first_use (); use; use = use->next ()) | |
446 { | |
447 jit_block *runner = use->user_parent (); | |
448 while (runner != idom) | |
449 { | |
450 runner->mdf.insert (this); | |
451 runner = runner->idom; | |
452 } | |
453 } | |
454 } | |
455 | |
456 for (size_t i = 0; i < successor_count (); ++i) | |
457 successor (i)->compute_df (avisit_count); | |
458 } | |
459 | |
460 bool | |
461 jit_block::update_idom (size_t avisit_count) | |
462 { | |
463 if (visited (avisit_count) || ! use_count ()) | |
464 return false; | |
465 | |
466 bool changed = false; | |
467 for (jit_use *use = first_use (); use; use = use->next ()) | |
468 { | |
469 jit_block *pred = use->user_parent (); | |
470 changed = pred->update_idom (avisit_count) || changed; | |
471 } | |
472 | |
473 jit_use *use = first_use (); | |
474 jit_block *new_idom = use->user_parent (); | |
475 use = use->next (); | |
476 | |
477 for (; use; use = use->next ()) | |
478 { | |
479 jit_block *pred = use->user_parent (); | |
480 jit_block *pidom = pred->idom; | |
481 if (pidom) | |
482 new_idom = idom_intersect (pidom, new_idom); | |
483 } | |
484 | |
485 if (idom != new_idom) | |
486 { | |
487 idom = new_idom; | |
488 return true; | |
489 } | |
490 | |
491 return changed; | |
492 } | |
493 | |
494 void | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
495 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
|
496 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
497 if (visited (avisit_count)) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
498 return; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
499 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
500 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
|
501 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
502 jit_block *pred = use->user_parent (); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
503 pred->label (avisit_count, number); |
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 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
506 mid = number++; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
507 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
508 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
509 void |
15016 | 510 jit_block::pop_all (void) |
511 { | |
512 for (iterator iter = begin (); iter != end (); ++iter) | |
513 { | |
514 jit_instruction *instr = *iter; | |
515 instr->pop_variable (); | |
516 } | |
517 } | |
518 | |
15602
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
519 std::ostream& |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
520 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
|
521 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
522 print_indent (os, indent); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
523 short_print (os) << ": %pred = "; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
524 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
|
525 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
526 jit_block *pred = use->user_parent (); |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
527 os << *pred; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
528 if (use->next ()) |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
529 os << ", "; |
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 os << std::endl; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
532 |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
533 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
|
534 { |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
535 jit_instruction *instr = *iter; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
536 instr->print (os, indent + 1) << std::endl; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
537 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
538 return os; |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
539 } |
f3e339aee38f
Fix block labeling in JIT debug output
Max Brister <max@2bass.com>
parents:
15259
diff
changeset
|
540 |
15016 | 541 jit_block * |
15182
a7a56b436de2
Factor out jit_block_list and jit_factory from jit_convert
Max Brister <max@2bass.com>
parents:
15171
diff
changeset
|
542 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
|
543 jit_block *asuccessor) |
15016 | 544 { |
545 if (successor_count () > 1) | |
546 { | |
547 jit_terminator *term = terminator (); | |
548 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
|
549 jit_block *split = factory.create<jit_block> ("phi_split", mvisit_count); |
15016 | 550 |
15171
7a19e8275d41
Do not simplify the CFG during type inference
Max Brister <max@2bass.com>
parents:
15124
diff
changeset
|
551 // 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
|
552 blocks.insert_after (this, split); |
15016 | 553 |
554 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
|
555 jit_branch *br = split->append (factory.create<jit_branch> (asuccessor)); |
15016 | 556 replace_in_phi (asuccessor, split); |
557 | |
558 if (alive ()) | |
559 { | |
560 split->mark_alive (); | |
561 br->infer (); | |
562 } | |
563 | |
564 return split; | |
565 } | |
566 | |
567 return this; | |
568 } | |
569 | |
570 void | |
571 jit_block::create_dom_tree (size_t avisit_count) | |
572 { | |
573 if (visited (avisit_count)) | |
574 return; | |
575 | |
576 if (idom != this) | |
577 idom->dom_succ.push_back (this); | |
578 | |
579 for (size_t i = 0; i < successor_count (); ++i) | |
580 successor (i)->create_dom_tree (avisit_count); | |
581 } | |
582 | |
583 jit_block * | |
584 jit_block::idom_intersect (jit_block *i, jit_block *j) | |
585 { | |
586 while (i && j && i != j) | |
587 { | |
588 while (i && i->id () > j->id ()) | |
589 i = i->idom; | |
590 | |
591 while (i && j && j->id () > i->id ()) | |
592 j = j->idom; | |
593 } | |
594 | |
595 return i ? i : j; | |
596 } | |
597 | |
598 // -------------------- jit_phi_incomming -------------------- | |
599 | |
600 jit_block * | |
601 jit_phi_incomming::user_parent (void) const | |
602 { return muser->parent (); } | |
603 | |
604 // -------------------- jit_phi -------------------- | |
605 bool | |
606 jit_phi::prune (void) | |
607 { | |
608 jit_block *p = parent (); | |
609 size_t new_idx = 0; | |
610 jit_value *unique = argument (1); | |
611 | |
612 for (size_t i = 0; i < argument_count (); ++i) | |
613 { | |
614 jit_block *inc = incomming (i); | |
615 if (inc->branch_alive (p)) | |
616 { | |
617 if (unique != argument (i)) | |
618 unique = 0; | |
619 | |
620 if (new_idx != i) | |
621 { | |
622 stash_argument (new_idx, argument (i)); | |
623 mincomming[new_idx].stash_value (inc); | |
624 } | |
625 | |
626 ++new_idx; | |
627 } | |
628 } | |
629 | |
630 if (new_idx != argument_count ()) | |
631 { | |
632 resize_arguments (new_idx); | |
633 mincomming.resize (new_idx); | |
634 } | |
635 | |
636 assert (argument_count () > 0); | |
637 if (unique) | |
638 { | |
639 replace_with (unique); | |
640 return true; | |
641 } | |
642 | |
643 return false; | |
644 } | |
645 | |
646 bool | |
647 jit_phi::infer (void) | |
648 { | |
649 jit_block *p = parent (); | |
650 if (! p->alive ()) | |
651 return false; | |
652 | |
653 jit_type *infered = 0; | |
654 for (size_t i = 0; i < argument_count (); ++i) | |
655 { | |
656 jit_block *inc = incomming (i); | |
657 if (inc->branch_alive (p)) | |
658 infered = jit_typeinfo::join (infered, argument_type (i)); | |
659 } | |
660 | |
661 if (infered != type ()) | |
662 { | |
663 stash_type (infered); | |
664 return true; | |
665 } | |
666 | |
667 return false; | |
668 } | |
669 | |
20654 | 670 #if HAVE_LLVM |
15016 | 671 llvm::PHINode * |
672 jit_phi::to_llvm (void) const | |
673 { | |
674 return llvm::cast<llvm::PHINode> (jit_value::to_llvm ()); | |
675 } | |
20654 | 676 #endif |
15016 | 677 |
678 // -------------------- jit_terminator -------------------- | |
679 size_t | |
680 jit_terminator::successor_index (const jit_block *asuccessor) const | |
681 { | |
682 size_t scount = successor_count (); | |
683 for (size_t i = 0; i < scount; ++i) | |
684 if (successor (i) == asuccessor) | |
685 return i; | |
686 | |
687 panic_impossible (); | |
688 } | |
689 | |
690 bool | |
691 jit_terminator::infer (void) | |
692 { | |
693 if (! parent ()->alive ()) | |
694 return false; | |
695 | |
696 bool changed = false; | |
697 for (size_t i = 0; i < malive.size (); ++i) | |
698 if (! malive[i] && check_alive (i)) | |
699 { | |
700 changed = true; | |
701 malive[i] = true; | |
702 successor (i)->mark_alive (); | |
703 } | |
704 | |
705 return changed; | |
706 } | |
707 | |
20654 | 708 #if HAVE_LLVM |
15016 | 709 llvm::TerminatorInst * |
710 jit_terminator::to_llvm (void) const | |
711 { | |
712 return llvm::cast<llvm::TerminatorInst> (jit_value::to_llvm ()); | |
713 } | |
20654 | 714 #endif |
15016 | 715 |
716 // -------------------- jit_call -------------------- | |
717 bool | |
15603 | 718 jit_call::needs_release (void) const |
719 { | |
720 if (type () && jit_typeinfo::get_release (type ()).valid ()) | |
721 { | |
722 for (jit_use *use = first_use (); use; use = use->next ()) | |
723 { | |
724 jit_assign *assign = dynamic_cast<jit_assign *> (use->user ()); | |
725 if (assign && assign->artificial ()) | |
726 return false; | |
727 } | |
728 | |
729 return true; | |
730 } | |
731 return false; | |
732 } | |
733 | |
734 bool | |
15016 | 735 jit_call::infer (void) |
736 { | |
737 // FIXME: explain algorithm | |
738 for (size_t i = 0; i < argument_count (); ++i) | |
739 { | |
740 already_infered[i] = argument_type (i); | |
741 if (! already_infered[i]) | |
742 return false; | |
743 } | |
744 | |
745 jit_type *infered = moperation.result (already_infered); | |
746 if (! infered && use_count ()) | |
747 { | |
748 std::stringstream ss; | |
749 ss << "Missing overload in type inference for "; | |
750 print (ss, 0); | |
751 throw jit_fail_exception (ss.str ()); | |
752 } | |
753 | |
754 if (infered != type ()) | |
755 { | |
756 stash_type (infered); | |
757 return true; | |
758 } | |
759 | |
760 return false; | |
761 } | |
762 | |
15603 | 763 // -------------------- jit_error_check -------------------- |
764 std::string | |
765 jit_error_check::variable_to_string (variable v) | |
766 { | |
767 switch (v) | |
768 { | |
769 case var_error_state: | |
770 return "error_state"; | |
771 case var_interrupt: | |
772 return "interrupt"; | |
773 default: | |
774 panic_impossible (); | |
775 } | |
776 } | |
777 | |
778 std::ostream& | |
779 jit_error_check::print (std::ostream& os, size_t indent) const | |
780 { | |
781 print_indent (os, indent) << "error_check " << variable_to_string (mvariable) | |
782 << ", "; | |
783 | |
784 if (has_check_for ()) | |
785 os << "<for> " << *check_for () << ", "; | |
786 print_successor (os << "<normal> ", 1) << ", "; | |
787 return print_successor (os << "<error> ", 0); | |
788 } | |
789 | |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
790 // -------------------- 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
|
791 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
|
792 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
|
793 : 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
|
794 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
|
795 {} |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
796 |
15067 | 797 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
|
798 : contexts (full_context) |
15067 | 799 { |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
800 resize_arguments (contexts.size ()); |
15067 | 801 |
802 size_t i; | |
803 std::vector<context>::const_iterator iter; | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
804 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
|
805 stash_argument (i, iter->value); |
15067 | 806 } |
807 | |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
808 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
|
809 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
|
810 { |
15124
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
811 size_t idx; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
812 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
|
813 { |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
814 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
|
815 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
|
816 break; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
817 } |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
818 |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
819 if (idx >= contexts.size ()) |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
820 idx = 0; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
821 |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
822 context ret = contexts[idx]; |
0464e3ceb85b
Skip functions when resolving end context in JIT
Max Brister <max@2bass.com>
parents:
15102
diff
changeset
|
823 ret.value = argument (idx); |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
824 return ret; |
15056
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
825 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
826 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
827 bool |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
828 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
|
829 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
830 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
|
831 if (new_type != type ()) |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
832 { |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
833 stash_type (new_type); |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
834 return true; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
835 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
836 |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
837 return false; |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
838 } |
bc32288f4a42
Support the end keyword for one dimentional indexing in JIT.
Max Brister <max@2bass.com>
parents:
15016
diff
changeset
|
839 |
15102
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
840 std::ostream& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
841 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
|
842 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
843 context ctx = resolve_context (); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
844 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
|
845 return os << *ctx.index << ", " << *ctx.count << ")"; |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
846 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
847 |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
848 const jit_function& |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
849 jit_magic_end::overload () const |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
850 { |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
851 const context& ctx = resolve_context (); |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
852 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
|
853 } |
d29f2583cf7b
Support end in multi indexing in JIT
Max Brister <max@2bass.com>
parents:
15096
diff
changeset
|
854 |
20654 | 855 #endif /* ifdef HAVE_JIT */ |