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

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

Issue 10909094: Implement loop invariant code motion for check instructions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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_H_ 5 #ifndef VM_FLOW_GRAPH_H_
6 #define VM_FLOW_GRAPH_H_ 6 #define VM_FLOW_GRAPH_H_
7 7
8 #include "vm/growable_array.h" 8 #include "vm/growable_array.h"
9 #include "vm/parser.h" 9 #include "vm/parser.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 class BlockEntryInstr; 13 class BlockEntryInstr;
14 class Definition; 14 class Definition;
15 class FlowGraphBuilder; 15 class FlowGraphBuilder;
16 class GraphEntryInstr; 16 class GraphEntryInstr;
17 class PhiInstr; 17 class PhiInstr;
18 class ReturnInstr; 18 class ReturnInstr;
19 class StaticCallInstr; 19 class StaticCallInstr;
20 20
21
22 class BlockIterator : public ValueObject {
23 public:
24 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order)
25 : block_order_(block_order), current_(0) { }
26
27 void Advance() {
28 ASSERT(!Done());
29 current_++;
30 }
31
32 bool Done() const { return current_ >= block_order_.length(); }
33
34 BlockEntryInstr* Current() const { return block_order_[current_]; }
35
36 private:
37 const GrowableArray<BlockEntryInstr*>& block_order_;
38 intptr_t current_;
39 };
40
41
21 // Class to incapsulate the construction and manipulation of the flow graph. 42 // Class to incapsulate the construction and manipulation of the flow graph.
22 class FlowGraph: public ZoneAllocated { 43 class FlowGraph: public ZoneAllocated {
23 public: 44 public:
24 FlowGraph(const FlowGraphBuilder& builder, GraphEntryInstr* graph_entry); 45 FlowGraph(const FlowGraphBuilder& builder, GraphEntryInstr* graph_entry);
25 46
26 // Function properties. 47 // Function properties.
27 const ParsedFunction& parsed_function() const { 48 const ParsedFunction& parsed_function() const {
28 return parsed_function_; 49 return parsed_function_;
29 } 50 }
30 intptr_t parameter_count() const { 51 intptr_t parameter_count() const {
(...skipping 16 matching lines...) Expand all
47 const GrowableArray<BlockEntryInstr*>& preorder() const { 68 const GrowableArray<BlockEntryInstr*>& preorder() const {
48 return preorder_; 69 return preorder_;
49 } 70 }
50 const GrowableArray<BlockEntryInstr*>& postorder() const { 71 const GrowableArray<BlockEntryInstr*>& postorder() const {
51 return postorder_; 72 return postorder_;
52 } 73 }
53 const GrowableArray<BlockEntryInstr*>& reverse_postorder() const { 74 const GrowableArray<BlockEntryInstr*>& reverse_postorder() const {
54 return reverse_postorder_; 75 return reverse_postorder_;
55 } 76 }
56 77
78 // Iterators.
79 BlockIterator reverse_postorder_iterator() const {
80 return BlockIterator(reverse_postorder());
81 }
82 BlockIterator postorder_iterator() const {
83 return BlockIterator(postorder());
84 }
85
57 intptr_t max_virtual_register_number() const { 86 intptr_t max_virtual_register_number() const {
58 return current_ssa_temp_index(); 87 return current_ssa_temp_index();
59 } 88 }
60 89
61 GraphEntryInstr* graph_entry() const { 90 GraphEntryInstr* graph_entry() const {
62 return graph_entry_; 91 return graph_entry_;
63 } 92 }
64 93
65 ZoneGrowableArray<ReturnInstr*>* exits() const { return exits_; } 94 ZoneGrowableArray<ReturnInstr*>* exits() const { return exits_; }
66 void set_exits(ZoneGrowableArray<ReturnInstr*>* exits) { exits_ = exits; } 95 void set_exits(ZoneGrowableArray<ReturnInstr*>* exits) { exits_ = exits; }
67 96
68 intptr_t alloc_ssa_temp_index() { return current_ssa_temp_index_++; } 97 intptr_t alloc_ssa_temp_index() { return current_ssa_temp_index_++; }
69 98
70 // Operations on the flow graph. 99 // Operations on the flow graph.
71 void ComputeSSA(intptr_t next_virtual_register_number = 0); 100 void ComputeSSA(intptr_t next_virtual_register_number = 0);
72 void ComputeUseLists(); 101 void ComputeUseLists();
73 102
103 // Finds natural loops in the flow graph and attaches a list of loop
104 // body blocks for each loop header.
105 void ComputeLoops(GrowableArray<BlockEntryInstr*>* loop_headers);
106
74 void InlineCall(StaticCallInstr* call, FlowGraph* callee_graph); 107 void InlineCall(StaticCallInstr* call, FlowGraph* callee_graph);
75 108
76 // TODO(zerny): Once the SSA is feature complete this should be removed. 109 // TODO(zerny): Once the SSA is feature complete this should be removed.
77 void Bailout(const char* reason) const; 110 void Bailout(const char* reason) const;
78 111
79 #ifdef DEBUG 112 #ifdef DEBUG
80 // Validation methods for debugging. 113 // Validation methods for debugging.
81 bool ResetUseLists(); 114 bool ResetUseLists();
82 bool ValidateUseLists(); 115 bool ValidateUseLists();
83 #endif // DEBUG 116 #endif // DEBUG
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 GraphEntryInstr* graph_entry_; 160 GraphEntryInstr* graph_entry_;
128 GrowableArray<BlockEntryInstr*> preorder_; 161 GrowableArray<BlockEntryInstr*> preorder_;
129 GrowableArray<BlockEntryInstr*> postorder_; 162 GrowableArray<BlockEntryInstr*> postorder_;
130 GrowableArray<BlockEntryInstr*> reverse_postorder_; 163 GrowableArray<BlockEntryInstr*> reverse_postorder_;
131 ZoneGrowableArray<ReturnInstr*>* exits_; 164 ZoneGrowableArray<ReturnInstr*>* exits_;
132 }; 165 };
133 166
134 } // namespace dart 167 } // namespace dart
135 168
136 #endif // VM_FLOW_GRAPH_H_ 169 #endif // VM_FLOW_GRAPH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698