annotate src/share/vm/c1/c1_ValueStack.hpp @ 1824:ad0638ff8ea4

6988303: 6986046 breaks build with recent gcc Summary: fixes build break Reviewed-by: never, kvn
author roland
date Wed, 29 Sep 2010 18:53:28 +0200
parents 1375bc8922e4
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 class ValueStack: public CompilationResourceObj {
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
26 public:
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
27 enum Kind {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
28 Parsing, // During abstract interpretation in GraphBuilder
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
29 CallerState, // Caller state when inlining
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
30 StateBefore, // Before before execution of instruction
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
31 StateAfter, // After execution of instruction
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
32 ExceptionState, // Exception handling of instruction
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
33 EmptyExceptionState, // Exception handling of instructions not covered by an xhandler
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
34 BlockBeginState // State of BlockBegin instruction with phi functions of this block
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
35 };
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
36
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 IRScope* _scope; // the enclosing scope
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
39 ValueStack* _caller_state;
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
40 int _bci;
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
41 Kind _kind;
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
42
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 Values _locals; // the locals
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Values _stack; // the expression stack
a61af66fc99e Initial load
duke
parents:
diff changeset
45 Values _locks; // the monitor stack (holding the locked values)
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 Value check(ValueTag tag, Value t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Value check(ValueTag tag, Value t, Value h) {
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
53 assert(h == NULL, "hi-word of doubleword value must be NULL");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54 return check(tag, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // helper routine
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
58 static void apply(Values list, ValueVisitor* f);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
60 // for simplified copying
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
61 ValueStack(ValueStack* copy_from, Kind kind, int bci);
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
62
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // creation
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
65 ValueStack(IRScope* scope, ValueStack* caller_state);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
66
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
67 ValueStack* copy() { return new ValueStack(this, _kind, _bci); }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
68 ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci); }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
69 ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99); }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
70
1822
1375bc8922e4 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 1819
diff changeset
71 void set_caller_state(ValueStack* s) {
1375bc8922e4 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 1819
diff changeset
72 assert(kind() == EmptyExceptionState ||
1375bc8922e4 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 1819
diff changeset
73 (Compilation::current()->env()->jvmti_can_access_local_variables() && kind() == ExceptionState),
1375bc8922e4 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 1819
diff changeset
74 "only EmptyExceptionStates can be modified");
1375bc8922e4 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 1819
diff changeset
75 _caller_state = s;
1375bc8922e4 6987763: assert(kind() == EmptyExceptionState) failed: only EmptyExceptionStates can be modified
never
parents: 1819
diff changeset
76 }
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
77
0
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals)
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
81 IRScope* scope() const { return _scope; }
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
82 ValueStack* caller_state() const { return _caller_state; }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
83 int bci() const { return _bci; }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
84 Kind kind() const { return _kind; }
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
85
0
a61af66fc99e Initial load
duke
parents:
diff changeset
86 int locals_size() const { return _locals.length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int stack_size() const { return _stack.length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int locks_size() const { return _locks.length(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 bool stack_is_empty() const { return _stack.is_empty(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 bool no_active_locks() const { return _locks.is_empty(); }
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
91 int total_locks_size() const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // locals access
a61af66fc99e Initial load
duke
parents:
diff changeset
94 void clear_locals(); // sets all locals to NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 void invalidate_local(int i) {
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
97 assert(_locals.at(i)->type()->is_single_word() ||
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
98 _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
99 _locals.at_put(i, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
102 Value local_at(int i) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 Value x = _locals.at(i);
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
104 assert(x == NULL || x->type()->is_single_word() ||
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
105 _locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return x;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void store_local(int i, Value x) {
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
110 // When overwriting local i, check if i - 1 was the start of a
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
111 // double word local and kill it.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (i > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 Value prev = _locals.at(i - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (prev != NULL && prev->type()->is_double_word()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _locals.at_put(i - 1, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
118
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
119 _locals.at_put(i, x);
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
120 if (x->type()->is_double_word()) {
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
121 // hi-word of doubleword value is always NULL
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
122 _locals.at_put(i + 1, NULL);
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
123 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // stack access
a61af66fc99e Initial load
duke
parents:
diff changeset
127 Value stack_at(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 Value x = _stack.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(x->type()->is_single_word() ||
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
130 _stack.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return x;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 Value stack_at_inc(int& i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 Value x = stack_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 i += x->type()->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return x;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // pinning support
a61af66fc99e Initial load
duke
parents:
diff changeset
141 void pin_stack_for_linear_scan();
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // iteration
1584
b812ff5abc73 6958292: C1: Enable parallel compilation
iveresov
parents: 1552
diff changeset
144 void values_do(ValueVisitor* f);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // untyped manipulation (for dup_x1, etc.)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 void truncate_stack(int size) { _stack.trunc_to(size); }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 void raw_push(Value t) { _stack.push(t); }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 Value raw_pop() { return _stack.pop(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // typed manipulation
a61af66fc99e Initial load
duke
parents:
diff changeset
152 void ipush(Value t) { _stack.push(check(intTag , t)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 void fpush(Value t) { _stack.push(check(floatTag , t)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void apush(Value t) { _stack.push(check(objectTag , t)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void rpush(Value t) { _stack.push(check(addressTag, t)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(NULL); }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(NULL); }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void push(ValueType* type, Value t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 switch (type->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 case intTag : ipush(t); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 case longTag : lpush(t); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 case floatTag : fpush(t); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 case doubleTag : dpush(t); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 case objectTag : apush(t); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 case addressTag: rpush(t); return;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Value ipop() { return check(intTag , _stack.pop()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 Value fpop() { return check(floatTag , _stack.pop()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 Value apop() { return check(objectTag , _stack.pop()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 Value rpop() { return check(addressTag, _stack.pop()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 Value lpop() { Value h = _stack.pop(); return check(longTag , _stack.pop(), h); }
a61af66fc99e Initial load
duke
parents:
diff changeset
176 Value dpop() { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 Value pop(ValueType* type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 switch (type->tag()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
180 case intTag : return ipop();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 case longTag : return lpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 case floatTag : return fpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 case doubleTag : return dpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
184 case objectTag : return apop();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 case addressTag: return rpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 Values* pop_arguments(int argument_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // locks access
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
194 int lock (Value obj);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int unlock();
a61af66fc99e Initial load
duke
parents:
diff changeset
196 Value lock_at(int i) const { return _locks.at(i); }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // SSA form IR support
a61af66fc99e Initial load
duke
parents:
diff changeset
199 void setup_phi_for_stack(BlockBegin* b, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 void setup_phi_for_local(BlockBegin* b, int index);
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
203 void print() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 void verify() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 };
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // Macro definitions for simple iteration of stack and local values of a ValueStack
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // The macros can be used like a for-loop. All variables (state, index and value)
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // must be defined before the loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // When states are nested because of inlining, the stack of the innermost state
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // cumulates also the stack of the nested states. In contrast, the locals of all
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // states must be iterated each.
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Use the following code pattern to iterate all stack values and all nested local values:
a61af66fc99e Initial load
duke
parents:
diff changeset
216 //
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // ValueStack* state = ... // state that is iterated
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // int index; // current loop index (overwritten in loop)
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // Value value; // value at current loop index (overwritten in loop)
a61af66fc99e Initial load
duke
parents:
diff changeset
220 //
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // for_each_stack_value(state, index, value {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // do something with value and index
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 //
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // for_each_state(state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // for_each_local_value(state, index, value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // do something with value and index
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // as an invariant, state is NULL now
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 // construct a unique variable name with the line number where the macro is used
a61af66fc99e Initial load
duke
parents:
diff changeset
234 #define temp_var3(x) temp__ ## x
a61af66fc99e Initial load
duke
parents:
diff changeset
235 #define temp_var2(x) temp_var3(x)
a61af66fc99e Initial load
duke
parents:
diff changeset
236 #define temp_var temp_var2(__LINE__)
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 #define for_each_state(state) \
a61af66fc99e Initial load
duke
parents:
diff changeset
239 for (; state != NULL; state = state->caller_state())
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 #define for_each_local_value(state, index, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
242 int temp_var = state->locals_size(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
243 for (index = 0; \
a61af66fc99e Initial load
duke
parents:
diff changeset
244 index < temp_var && (value = state->local_at(index), true); \
a61af66fc99e Initial load
duke
parents:
diff changeset
245 index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size())) \
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (value != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 #define for_each_stack_value(state, index, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
250 int temp_var = state->stack_size(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
251 for (index = 0; \
a61af66fc99e Initial load
duke
parents:
diff changeset
252 index < temp_var && (value = state->stack_at(index), true); \
a61af66fc99e Initial load
duke
parents:
diff changeset
253 index += value->type()->size())
a61af66fc99e Initial load
duke
parents:
diff changeset
254
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 #define for_each_lock_value(state, index, value) \
a61af66fc99e Initial load
duke
parents:
diff changeset
257 int temp_var = state->locks_size(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
258 for (index = 0; \
a61af66fc99e Initial load
duke
parents:
diff changeset
259 index < temp_var && (value = state->lock_at(index), true); \
a61af66fc99e Initial load
duke
parents:
diff changeset
260 index++) \
a61af66fc99e Initial load
duke
parents:
diff changeset
261 if (value != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // Macro definition for simple iteration of all state values of a ValueStack
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // Because the code cannot be executed in a single loop, the code must be passed
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // as a macro parameter.
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Use the following code pattern to iterate all stack values and all nested local values:
a61af66fc99e Initial load
duke
parents:
diff changeset
268 //
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // ValueStack* state = ... // state that is iterated
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // for_each_state_value(state, value,
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // do something with value (note that this is a macro parameter)
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // );
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 #define for_each_state_value(v_state, v_value, v_code) \
a61af66fc99e Initial load
duke
parents:
diff changeset
275 { \
a61af66fc99e Initial load
duke
parents:
diff changeset
276 int cur_index; \
a61af66fc99e Initial load
duke
parents:
diff changeset
277 ValueStack* cur_state = v_state; \
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
278 Value v_value; \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
279 for_each_state(cur_state) { \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
280 { \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
281 for_each_local_value(cur_state, cur_index, v_value) { \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
282 v_code; \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
283 } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
284 } \
1819
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
285 { \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
286 for_each_stack_value(cur_state, cur_index, v_value) { \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
287 v_code; \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
288 } \
f02a8bbe6ed4 6986046: C1 valuestack cleanup
roland
parents: 1584
diff changeset
289 } \
0
a61af66fc99e Initial load
duke
parents:
diff changeset
290 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // Macro definition for simple iteration of all phif functions of a block, i.e all
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // phi functions of the ValueStack where the block matches.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // Use the following code pattern to iterate all phi functions of a block:
a61af66fc99e Initial load
duke
parents:
diff changeset
297 //
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // BlockBegin* block = ... // block that is iterated
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // for_each_phi_function(block, phi,
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // do something with the phi function phi (note that this is a macro parameter)
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // );
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 #define for_each_phi_fun(v_block, v_phi, v_code) \
a61af66fc99e Initial load
duke
parents:
diff changeset
304 { \
a61af66fc99e Initial load
duke
parents:
diff changeset
305 int cur_index; \
a61af66fc99e Initial load
duke
parents:
diff changeset
306 ValueStack* cur_state = v_block->state(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
307 Value value; \
a61af66fc99e Initial load
duke
parents:
diff changeset
308 { \
a61af66fc99e Initial load
duke
parents:
diff changeset
309 for_each_stack_value(cur_state, cur_index, value) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
310 Phi* v_phi = value->as_Phi(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (v_phi != NULL && v_phi->block() == v_block) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
312 v_code; \
a61af66fc99e Initial load
duke
parents:
diff changeset
313 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
314 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
315 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
316 { \
a61af66fc99e Initial load
duke
parents:
diff changeset
317 for_each_local_value(cur_state, cur_index, value) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
318 Phi* v_phi = value->as_Phi(); \
a61af66fc99e Initial load
duke
parents:
diff changeset
319 if (v_phi != NULL && v_phi->block() == v_block) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
320 v_code; \
a61af66fc99e Initial load
duke
parents:
diff changeset
321 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
322 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
323 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }