Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 GrowableArray<Data> exits_; | 96 GrowableArray<Data> exits_; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 | 99 |
| 100 // Build a flow graph from a parsed function's AST. | 100 // Build a flow graph from a parsed function's AST. |
| 101 class FlowGraphBuilder: public ValueObject { | 101 class FlowGraphBuilder: public ValueObject { |
| 102 public: | 102 public: |
| 103 // The inlining context is NULL if not inlining. | 103 // The inlining context is NULL if not inlining. |
| 104 FlowGraphBuilder(ParsedFunction* parsed_function, | 104 FlowGraphBuilder(ParsedFunction* parsed_function, |
| 105 const Array& ic_data_array, | 105 const Array& ic_data_array, |
| 106 InlineExitCollector* exit_collector); | 106 InlineExitCollector* exit_collector, |
| 107 intptr_t osr_id); | |
| 107 | 108 |
| 108 FlowGraph* BuildGraph(); | 109 FlowGraph* BuildGraph(); |
| 109 | 110 |
| 110 ParsedFunction* parsed_function() const { return parsed_function_; } | 111 ParsedFunction* parsed_function() const { return parsed_function_; } |
| 111 const Array& ic_data_array() const { return ic_data_array_; } | 112 const Array& ic_data_array() const { return ic_data_array_; } |
| 112 | 113 |
| 113 void Bailout(const char* reason); | 114 void Bailout(const char* reason); |
| 114 | 115 |
| 115 intptr_t AllocateBlockId() { return ++last_used_block_id_; } | 116 intptr_t AllocateBlockId() { return ++last_used_block_id_; } |
| 116 void SetInitialBlockId(intptr_t id) { last_used_block_id_ = id; } | 117 void SetInitialBlockId(intptr_t id) { last_used_block_id_ = id; } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 136 intptr_t num_stack_locals() const { | 137 intptr_t num_stack_locals() const { |
| 137 return num_stack_locals_; | 138 return num_stack_locals_; |
| 138 } | 139 } |
| 139 | 140 |
| 140 bool IsInlining() const { return (exit_collector_ != NULL); } | 141 bool IsInlining() const { return (exit_collector_ != NULL); } |
| 141 InlineExitCollector* exit_collector() const { return exit_collector_; } | 142 InlineExitCollector* exit_collector() const { return exit_collector_; } |
| 142 | 143 |
| 143 intptr_t args_pushed() const { return args_pushed_; } | 144 intptr_t args_pushed() const { return args_pushed_; } |
| 144 void add_args_pushed(intptr_t n) { args_pushed_ += n; } | 145 void add_args_pushed(intptr_t n) { args_pushed_ += n; } |
| 145 | 146 |
| 147 // When compiling for OSR, remove blocks that are not reachable from the | |
| 148 // OSR entry point. | |
| 149 void PruneUnreachable(); | |
| 150 | |
| 146 private: | 151 private: |
| 147 intptr_t parameter_count() const { | 152 intptr_t parameter_count() const { |
| 148 return num_copied_params_ + num_non_copied_params_; | 153 return num_copied_params_ + num_non_copied_params_; |
| 149 } | 154 } |
| 150 intptr_t variable_count() const { | 155 intptr_t variable_count() const { |
| 151 return parameter_count() + num_stack_locals_; | 156 return parameter_count() + num_stack_locals_; |
| 152 } | 157 } |
| 153 | 158 |
| 154 ParsedFunction* parsed_function_; | 159 ParsedFunction* parsed_function_; |
| 155 const Array& ic_data_array_; | 160 const Array& ic_data_array_; |
| 156 | 161 |
| 157 const intptr_t num_copied_params_; | 162 const intptr_t num_copied_params_; |
| 158 const intptr_t num_non_copied_params_; | 163 const intptr_t num_non_copied_params_; |
| 159 const intptr_t num_stack_locals_; // Does not include any parameters. | 164 const intptr_t num_stack_locals_; // Does not include any parameters. |
| 160 InlineExitCollector* const exit_collector_; | 165 InlineExitCollector* const exit_collector_; |
| 161 | 166 |
| 162 intptr_t last_used_block_id_; | 167 intptr_t last_used_block_id_; |
| 163 intptr_t context_level_; | 168 intptr_t context_level_; |
| 164 intptr_t last_used_try_index_; | 169 intptr_t last_used_try_index_; |
| 165 intptr_t try_index_; | 170 intptr_t try_index_; |
| 166 GraphEntryInstr* graph_entry_; | 171 GraphEntryInstr* graph_entry_; |
| 167 | 172 |
| 168 // Outgoing argument stack height. | 173 // Outgoing argument stack height. |
| 169 intptr_t args_pushed_; | 174 intptr_t args_pushed_; |
| 170 | 175 |
| 176 // The deopt id of the OSR entry or Isolate::kNoDeoptId if not compiling | |
|
srdjan
2013/06/11 17:12:02
Add this comment also to the constructor.
Kevin Millikin (Google)
2013/06/14 10:10:42
Done.
| |
| 177 // for OSR. | |
| 178 intptr_t osr_id_; | |
|
srdjan
2013/06/11 17:12:02
const?
Kevin Millikin (Google)
2013/06/14 10:10:42
Done.
| |
| 179 | |
| 171 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); | 180 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); |
| 172 }; | 181 }; |
| 173 | 182 |
| 174 | 183 |
| 175 class TestGraphVisitor; | 184 class TestGraphVisitor; |
| 176 | 185 |
| 177 // Translate an AstNode to a control-flow graph fragment for its effects | 186 // Translate an AstNode to a control-flow graph fragment for its effects |
| 178 // (e.g., a statement or an expression in an effect context). Implements a | 187 // (e.g., a statement or an expression in an effect context). Implements a |
| 179 // function from an AstNode and next temporary index to a graph fragment | 188 // function from an AstNode and next temporary index to a graph fragment |
| 180 // with a single entry and at most one exit. The fragment is represented by | 189 // with a single entry and at most one exit. The fragment is represented by |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 | 231 |
| 223 // Append a 'diamond' branch and join to this graph, depending on which | 232 // Append a 'diamond' branch and join to this graph, depending on which |
| 224 // parts are reachable. Assumes this graph is open. | 233 // parts are reachable. Assumes this graph is open. |
| 225 void Join(const TestGraphVisitor& test_fragment, | 234 void Join(const TestGraphVisitor& test_fragment, |
| 226 const EffectGraphVisitor& true_fragment, | 235 const EffectGraphVisitor& true_fragment, |
| 227 const EffectGraphVisitor& false_fragment); | 236 const EffectGraphVisitor& false_fragment); |
| 228 | 237 |
| 229 // Append a 'while loop' test and back edge to this graph, depending on | 238 // Append a 'while loop' test and back edge to this graph, depending on |
| 230 // which parts are reachable. Afterward, the graph exit is the false | 239 // which parts are reachable. Afterward, the graph exit is the false |
| 231 // successor of the loop condition. | 240 // successor of the loop condition. |
| 232 void TieLoop(const TestGraphVisitor& test_fragment, | 241 void TieLoop(intptr_t token_pos, |
| 242 const TestGraphVisitor& test_fragment, | |
| 233 const EffectGraphVisitor& body_fragment); | 243 const EffectGraphVisitor& body_fragment); |
| 234 | 244 |
| 235 // Wraps a value in a push-argument instruction and adds the result to the | 245 // Wraps a value in a push-argument instruction and adds the result to the |
| 236 // graph. | 246 // graph. |
| 237 PushArgumentInstr* PushArgument(Value* value); | 247 PushArgumentInstr* PushArgument(Value* value); |
| 238 | 248 |
| 239 // This implementation shares state among visitors by using the builder. | 249 // This implementation shares state among visitors by using the builder. |
| 240 // The implementation is incorrect if a visitor that hits a return is not | 250 // The implementation is incorrect if a visitor that hits a return is not |
| 241 // actually added to the graph. | 251 // actually added to the graph. |
| 242 void AddReturnExit(intptr_t token_pos, Value* value); | 252 void AddReturnExit(intptr_t token_pos, Value* value); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 // Output parameters. | 511 // Output parameters. |
| 502 GrowableArray<TargetEntryInstr**> true_successor_addresses_; | 512 GrowableArray<TargetEntryInstr**> true_successor_addresses_; |
| 503 GrowableArray<TargetEntryInstr**> false_successor_addresses_; | 513 GrowableArray<TargetEntryInstr**> false_successor_addresses_; |
| 504 | 514 |
| 505 intptr_t condition_token_pos_; | 515 intptr_t condition_token_pos_; |
| 506 }; | 516 }; |
| 507 | 517 |
| 508 } // namespace dart | 518 } // namespace dart |
| 509 | 519 |
| 510 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 520 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
| OLD | NEW |