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

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

Issue 10857016: Refactored FlowGraphBuilder into a separate FlowGraph representation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added flow_graph.{h,cc} Created 8 years, 4 months 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 "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/flow_graph.h"
10 #include "vm/growable_array.h" 11 #include "vm/growable_array.h"
11 #include "vm/intermediate_language.h" 12 #include "vm/intermediate_language.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 class Instruction; 16 class Instruction;
16 class ParsedFunction; 17 class ParsedFunction;
17 18
18 // Build a flow graph from a parsed function's AST. 19 // Build a flow graph from a parsed function's AST.
19 class FlowGraphBuilder: public ValueObject { 20 class FlowGraphBuilder: public ValueObject {
20 public: 21 public:
21 explicit FlowGraphBuilder(const ParsedFunction& parsed_function); 22 explicit FlowGraphBuilder(const FlowGraph& flow_graph);
22 23
23 void BuildGraph(bool for_optimized, bool use_ssa); 24 GraphEntryInstr* BuildGraph();
24 25
25 const ParsedFunction& parsed_function() const { return parsed_function_; } 26 const ParsedFunction& parsed_function() const { return parsed_function_; }
26 27
27 const GrowableArray<BlockEntryInstr*>& postorder_block_entries() const {
28 return postorder_block_entries_;
29 }
30
31 void Bailout(const char* reason); 28 void Bailout(const char* reason);
32 29
33 void set_context_level(intptr_t value) { context_level_ = value; } 30 void set_context_level(intptr_t value) { context_level_ = value; }
34 intptr_t context_level() const { return context_level_; } 31 intptr_t context_level() const { return context_level_; }
35 32
36 // Each try in this function gets its own try index. 33 // Each try in this function gets its own try index.
37 intptr_t AllocateTryIndex() { return ++last_used_try_index_; } 34 intptr_t AllocateTryIndex() { return ++last_used_try_index_; }
38 35
39 // Manage the currently active try index. 36 // Manage the currently active try index.
40 void set_try_index(intptr_t value) { try_index_ = value; } 37 void set_try_index(intptr_t value) { try_index_ = value; }
41 intptr_t try_index() const { return try_index_; } 38 intptr_t try_index() const { return try_index_; }
42 39
43 void AddCatchEntry(TargetEntryInstr* entry); 40 void AddCatchEntry(TargetEntryInstr* entry);
44 41
45 intptr_t current_ssa_temp_index() const {
46 return current_ssa_temp_index_;
47 }
48
49 intptr_t alloc_ssa_temp_index() {
50 return current_ssa_temp_index_++;
51 }
52
53 intptr_t copied_parameter_count() const { return copied_parameter_count_; } 42 intptr_t copied_parameter_count() const { return copied_parameter_count_; }
54 43
55 private: 44 private:
56 intptr_t parameter_count() const { 45 intptr_t parameter_count() const {
57 return copied_parameter_count_ + non_copied_parameter_count_; 46 return copied_parameter_count_ + non_copied_parameter_count_;
58 } 47 }
59 intptr_t variable_count() const { 48 intptr_t variable_count() const {
60 return parameter_count() + stack_local_count_; 49 return parameter_count() + stack_local_count_;
61 } 50 }
62 51
63 void ComputeDominators(GrowableArray<BlockEntryInstr*>* preorder,
64 GrowableArray<intptr_t>* parent,
65 GrowableArray<BitVector*>* dominance_frontier);
66
67 void CompressPath(intptr_t start_index,
68 intptr_t current_index,
69 GrowableArray<intptr_t>* parent,
70 GrowableArray<intptr_t>* label);
71
72 void Rename(GrowableArray<PhiInstr*>* live_phis);
73 void RenameRecursive(BlockEntryInstr* block_entry,
74 GrowableArray<Value*>* env,
75 GrowableArray<PhiInstr*>* live_phis);
76
77 void InsertPhis(const GrowableArray<BlockEntryInstr*>& preorder,
78 const GrowableArray<BitVector*>& assigned_vars,
79 const GrowableArray<BitVector*>& dom_frontier);
80
81 void MarkLivePhis(GrowableArray<PhiInstr*>* live_phis);
82
83 const ParsedFunction& parsed_function_; 52 const ParsedFunction& parsed_function_;
84 53
85 const intptr_t copied_parameter_count_; 54 const intptr_t copied_parameter_count_;
86 const intptr_t non_copied_parameter_count_; 55 const intptr_t non_copied_parameter_count_;
87 const intptr_t stack_local_count_; // Does not include any parameters. 56 const intptr_t stack_local_count_; // Does not include any parameters.
88 57
89 GrowableArray<BlockEntryInstr*> preorder_block_entries_;
90 GrowableArray<BlockEntryInstr*> postorder_block_entries_;
91 intptr_t context_level_; 58 intptr_t context_level_;
92 intptr_t last_used_try_index_; 59 intptr_t last_used_try_index_;
93 intptr_t try_index_; 60 intptr_t try_index_;
94 GraphEntryInstr* graph_entry_; 61 GraphEntryInstr* graph_entry_;
95 intptr_t current_ssa_temp_index_;
96 62
97 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder); 63 DISALLOW_IMPLICIT_CONSTRUCTORS(FlowGraphBuilder);
98 }; 64 };
99 65
100 66
101 class TestGraphVisitor; 67 class TestGraphVisitor;
102 68
103 // Translate an AstNode to a control-flow graph fragment for its effects 69 // Translate an AstNode to a control-flow graph fragment for its effects
104 // (e.g., a statement or an expression in an effect context). Implements a 70 // (e.g., a statement or an expression in an effect context). Implements a
105 // function from an AstNode and next temporary index to a graph fragment 71 // function from an AstNode and next temporary index to a graph fragment
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // Output parameters. 342 // Output parameters.
377 TargetEntryInstr** true_successor_address_; 343 TargetEntryInstr** true_successor_address_;
378 TargetEntryInstr** false_successor_address_; 344 TargetEntryInstr** false_successor_address_;
379 345
380 intptr_t condition_token_pos_; 346 intptr_t condition_token_pos_;
381 }; 347 };
382 348
383 } // namespace dart 349 } // namespace dart
384 350
385 #endif // VM_FLOW_GRAPH_BUILDER_H_ 351 #endif // VM_FLOW_GRAPH_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698