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