Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: runtime/vm/flow_graph_builder.h

Issue 71703002: Introduce a nesting stack to the flow graph builder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ 5 #ifndef VM_FLOW_GRAPH_BUILDER_H_
6 #define VM_FLOW_GRAPH_BUILDER_H_ 6 #define VM_FLOW_GRAPH_BUILDER_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 Definition* JoinReturns(BlockEntryInstr** exit_block, 100 Definition* JoinReturns(BlockEntryInstr** exit_block,
101 Instruction** last_instruction); 101 Instruction** last_instruction);
102 102
103 FlowGraph* caller_graph_; 103 FlowGraph* caller_graph_;
104 Definition* call_; 104 Definition* call_;
105 GrowableArray<Data> exits_; 105 GrowableArray<Data> exits_;
106 }; 106 };
107 107
108 108
109 class NestedStatement;
srdjan 2013/11/13 17:17:08 Typically all forward class declarations are done
Kevin Millikin (Google) 2013/11/13 17:47:22 I'll move it.
110
109 // Build a flow graph from a parsed function's AST. 111 // Build a flow graph from a parsed function's AST.
110 class FlowGraphBuilder: public ValueObject { 112 class FlowGraphBuilder: public ValueObject {
111 public: 113 public:
112 // The inlining context is NULL if not inlining. The osr_id is the deopt 114 // The inlining context is NULL if not inlining. The osr_id is the deopt
113 // id of the OSR entry or Isolate::kNoDeoptId if not compiling for OSR. 115 // id of the OSR entry or Isolate::kNoDeoptId if not compiling for OSR.
114 FlowGraphBuilder(ParsedFunction* parsed_function, 116 FlowGraphBuilder(ParsedFunction* parsed_function,
115 const Array& ic_data_array, 117 const Array& ic_data_array,
116 InlineExitCollector* exit_collector, 118 InlineExitCollector* exit_collector,
117 intptr_t osr_id); 119 intptr_t osr_id);
118 120
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 intptr_t temp_count() const { return temp_count_; } 165 intptr_t temp_count() const { return temp_count_; }
164 intptr_t AllocateTemp() { return temp_count_++; } 166 intptr_t AllocateTemp() { return temp_count_++; }
165 void DeallocateTemps(intptr_t count) { 167 void DeallocateTemps(intptr_t count) {
166 ASSERT(temp_count_ >= count); 168 ASSERT(temp_count_ >= count);
167 temp_count_ -= count; 169 temp_count_ -= count;
168 } 170 }
169 171
170 intptr_t args_pushed() const { return args_pushed_; } 172 intptr_t args_pushed() const { return args_pushed_; }
171 void add_args_pushed(intptr_t n) { args_pushed_ += n; } 173 void add_args_pushed(intptr_t n) { args_pushed_ += n; }
172 174
175 NestedStatement* nesting_stack() const { return nesting_stack_; }
176
173 // When compiling for OSR, remove blocks that are not reachable from the 177 // When compiling for OSR, remove blocks that are not reachable from the
174 // OSR entry point. 178 // OSR entry point.
175 void PruneUnreachable(); 179 void PruneUnreachable();
176 180
177 private: 181 private:
182 friend class NestedStatement; // Explicit access to nesting_stack_.
183
178 intptr_t parameter_count() const { 184 intptr_t parameter_count() const {
179 return num_copied_params_ + num_non_copied_params_; 185 return num_copied_params_ + num_non_copied_params_;
180 } 186 }
181 intptr_t variable_count() const { 187 intptr_t variable_count() const {
182 return parameter_count() + num_stack_locals_; 188 return parameter_count() + num_stack_locals_;
183 } 189 }
184 190
185 ParsedFunction* parsed_function_; 191 ParsedFunction* parsed_function_;
186 const Array& ic_data_array_; 192 const Array& ic_data_array_;
187 193
188 const intptr_t num_copied_params_; 194 const intptr_t num_copied_params_;
189 const intptr_t num_non_copied_params_; 195 const intptr_t num_non_copied_params_;
190 const intptr_t num_stack_locals_; // Does not include any parameters. 196 const intptr_t num_stack_locals_; // Does not include any parameters.
191 InlineExitCollector* const exit_collector_; 197 InlineExitCollector* const exit_collector_;
192 ZoneGrowableArray<const Field*>* guarded_fields_; 198 ZoneGrowableArray<const Field*>* guarded_fields_;
193 199
194 intptr_t last_used_block_id_; 200 intptr_t last_used_block_id_;
195 intptr_t context_level_; 201 intptr_t context_level_;
196 intptr_t try_index_; 202 intptr_t try_index_;
197 intptr_t catch_try_index_; 203 intptr_t catch_try_index_;
198 intptr_t loop_depth_; 204 intptr_t loop_depth_;
199 GraphEntryInstr* graph_entry_; 205 GraphEntryInstr* graph_entry_;
200 206
201 // The expression stack height. 207 // The expression stack height.
202 intptr_t temp_count_; 208 intptr_t temp_count_;
203 209
204 // Outgoing argument stack height. 210 // Outgoing argument stack height.
205 intptr_t args_pushed_; 211 intptr_t args_pushed_;
206 212
213 // A stack of enclosing nested statements.
214 NestedStatement* nesting_stack_;
215
207 // The deopt id of the OSR entry or Isolate::kNoDeoptId if not compiling 216 // The deopt id of the OSR entry or Isolate::kNoDeoptId if not compiling
208 // for OSR. 217 // for OSR.
209 const intptr_t osr_id_; 218 const intptr_t osr_id_;
210 219
211 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); 220 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder);
212 }; 221 };
213 222
214 223
224 // Base class for a stack of enclosing statements of interest (e.g.,
225 // blocks (breakable) and loops (continuable)).
226 class NestedStatement : public ValueObject {
Florian Schneider 2013/11/13 17:42:58 Do you actually need to declare NestedStatement he
Kevin Millikin (Google) 2013/11/13 17:47:22 It does look like a forward declaration is enough.
227 public:
228 NestedStatement(FlowGraphBuilder* owner, const SourceLabel* label)
229 : owner_(owner),
230 label_(label),
231 outer_(owner->nesting_stack_),
232 break_target_(NULL) {
233 // Push on the owner's nesting stack.
234 owner->nesting_stack_ = this;
235 }
236
237 virtual ~NestedStatement() {
238 // Pop from the owner's nesting stack.
239 ASSERT(owner_->nesting_stack_ == this);
240 owner_->nesting_stack_ = outer_;
241 }
242
243 FlowGraphBuilder* owner() const { return owner_; }
244 const SourceLabel* label() const { return label_; }
245 NestedStatement* outer() const { return outer_; }
246 JoinEntryInstr* break_target() const { return break_target_; }
247
248 virtual JoinEntryInstr* BreakTargetFor(SourceLabel* label);
249 virtual JoinEntryInstr* ContinueTargetFor(SourceLabel* label);
250
251 private:
252 FlowGraphBuilder* owner_;
253 const SourceLabel* label_;
254 NestedStatement* outer_;
255
256 JoinEntryInstr* break_target_;
257 };
258
259
215 class TestGraphVisitor; 260 class TestGraphVisitor;
216 261
217 // Translate an AstNode to a control-flow graph fragment for its effects 262 // Translate an AstNode to a control-flow graph fragment for its effects
218 // (e.g., a statement or an expression in an effect context). Implements a 263 // (e.g., a statement or an expression in an effect context). Implements a
219 // function from an AstNode and next temporary index to a graph fragment 264 // function from an AstNode and next temporary index to a graph fragment
220 // with a single entry and at most one exit. The fragment is represented by 265 // with a single entry and at most one exit. The fragment is represented by
221 // an (entry, exit) pair of Instruction pointers: 266 // an (entry, exit) pair of Instruction pointers:
222 // 267 //
223 // - (NULL, NULL): an empty and open graph fragment 268 // - (NULL, NULL): an empty and open graph fragment
224 // - (i0, NULL): a closed graph fragment which has only non-local exits 269 // - (i0, NULL): a closed graph fragment which has only non-local exits
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // Output parameters. 582 // Output parameters.
538 GrowableArray<TargetEntryInstr**> true_successor_addresses_; 583 GrowableArray<TargetEntryInstr**> true_successor_addresses_;
539 GrowableArray<TargetEntryInstr**> false_successor_addresses_; 584 GrowableArray<TargetEntryInstr**> false_successor_addresses_;
540 585
541 intptr_t condition_token_pos_; 586 intptr_t condition_token_pos_;
542 }; 587 };
543 588
544 } // namespace dart 589 } // namespace dart
545 590
546 #endif // VM_FLOW_GRAPH_BUILDER_H_ 591 #endif // VM_FLOW_GRAPH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698