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

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

Issue 9622002: Handle instance field and indexed increment operations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // successor of the loop condition. 87 // successor of the loop condition.
88 void TieLoop(const TestGraphVisitor& test_fragment, 88 void TieLoop(const TestGraphVisitor& test_fragment,
89 const EffectGraphVisitor& body_fragment); 89 const EffectGraphVisitor& body_fragment);
90 90
91 protected: 91 protected:
92 // Helpers for translating parts of the AST. 92 // Helpers for translating parts of the AST.
93 void TranslateArgumentList(const ArgumentListNode& node, 93 void TranslateArgumentList(const ArgumentListNode& node,
94 intptr_t next_temp_index, 94 intptr_t next_temp_index,
95 ZoneGrowableArray<Value*>* values); 95 ZoneGrowableArray<Value*>* values);
96 96
97 // Build the load part of a instance field increment. Translates the
98 // receiver and loads the value. The receiver will be named with
99 // start_index, the temporary index of the value is returned (always
100 // start_index+1).
101 int BuildIncrOpFieldLoad(IncrOpInstanceFieldNode* node, int start_index);
102
103 // Build the load part of an indexed increment. Translates the receiver
104 // and index and loads the value. The receiver will be named with
105 // start_index, the index with start_index+1, and the temporary index of
106 // the value is returned (always start_index+2).
107 int BuildIncrOpIndexedLoad(IncrOpIndexedNode* node, int start_index);
108
109 // Build the increment part of an increment operation (add or subtract 1).
110 // The original value is expected to be named with start_index-1, and the
111 // result will be named with start_index.
112 void BuildIncrOpIncrement(Token::Kind kind,
Kevin Millikin (Google) 2012/03/07 13:44:55 I suspect that there is a more general helper (for
113 intptr_t node_id,
114 intptr_t token_index,
115 int start_index);
116
97 void CloseFragment() { exit_ = NULL; } 117 void CloseFragment() { exit_ = NULL; }
98 intptr_t AllocateTempIndex() { return temp_index_++; } 118 intptr_t AllocateTempIndex() { return temp_index_++; }
99 119
100 private: 120 private:
101 // Specify a value as the final result. Does nothing in an effect context
102 // but is normally overridden by subclasses.
103 virtual void ReturnValue(Value* value) { }
104
105 // Specify a computation as the final result. Adds a Do instruction to 121 // Specify a computation as the final result. Adds a Do instruction to
106 // the graph, but normally overridden in subclasses. 122 // the graph, but normally overridden in subclasses.
107 virtual void ReturnComputation(Computation* computation) { 123 virtual void ReturnComputation(Computation* computation) {
108 AddInstruction(new DoInstr(computation)); 124 AddInstruction(new DoInstr(computation));
109 } 125 }
110 126
111 // Shared global state. 127 // Shared global state.
112 FlowGraphBuilder* owner_; 128 FlowGraphBuilder* owner_;
113 129
114 // Input parameters. 130 // Input parameters.
(...skipping 11 matching lines...) Expand all
126 // in the EffectGraphVisitor), a next temporary index, and an intermediate 142 // in the EffectGraphVisitor), a next temporary index, and an intermediate
127 // language Value. 143 // language Value.
128 class ValueGraphVisitor : public EffectGraphVisitor { 144 class ValueGraphVisitor : public EffectGraphVisitor {
129 public: 145 public:
130 ValueGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) 146 ValueGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index)
131 : EffectGraphVisitor(owner, temp_index), value_(NULL) { } 147 : EffectGraphVisitor(owner, temp_index), value_(NULL) { }
132 148
133 // Visit functions overridden by this class. 149 // Visit functions overridden by this class.
134 virtual void VisitLiteralNode(LiteralNode* node); 150 virtual void VisitLiteralNode(LiteralNode* node);
135 virtual void VisitLoadLocalNode(LoadLocalNode* node); 151 virtual void VisitLoadLocalNode(LoadLocalNode* node);
152 virtual void VisitIncrOpInstanceFieldNode(IncrOpInstanceFieldNode* node);
153 virtual void VisitIncrOpIndexedNode(IncrOpIndexedNode* node);
136 154
137 Value* value() const { return value_; } 155 Value* value() const { return value_; }
138 156
139 protected: 157 protected:
140 // Output parameters. 158 // Output parameters.
141 Value* value_; 159 Value* value_;
142 160
143 private: 161 private:
144 // Helper to set the output state to return a Value. 162 // Helper to set the output state to return a Value.
145 virtual void ReturnValue(Value* value) { value_ = value; } 163 virtual void ReturnValue(Value* value) { value_ = value; }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // TargetEntryInstr*. 195 // TargetEntryInstr*.
178 // 196 //
179 // To distinguish between the graphs with only nonlocal exits and graphs 197 // To distinguish between the graphs with only nonlocal exits and graphs
180 // with both true and false exits, there are a pair of TargetEntryInstr**: 198 // with both true and false exits, there are a pair of TargetEntryInstr**:
181 // 199 //
182 // - Both NULL: only non-local exits, truly closed 200 // - Both NULL: only non-local exits, truly closed
183 // - Neither NULL: true and false successors at the given addresses 201 // - Neither NULL: true and false successors at the given addresses
184 // 202 //
185 // We expect that AstNode in test contexts either have only nonlocal exits 203 // We expect that AstNode in test contexts either have only nonlocal exits
186 // or else control flow has both true and false successors. 204 // or else control flow has both true and false successors.
187 class TestGraphVisitor : public EffectGraphVisitor { 205 class TestGraphVisitor : public ValueGraphVisitor {
188 public: 206 public:
189 TestGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) 207 TestGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index)
190 : EffectGraphVisitor(owner, temp_index), 208 : ValueGraphVisitor(owner, temp_index),
191 true_successor_address_(NULL), 209 true_successor_address_(NULL),
192 false_successor_address_(NULL) { 210 false_successor_address_(NULL) {
193 } 211 }
194 212
195 // Visit functions overridden by this class. 213 // Visit functions overridden by this class.
196 virtual void VisitLiteralNode(LiteralNode* node); 214 virtual void VisitLiteralNode(LiteralNode* node);
197 virtual void VisitLoadLocalNode(LoadLocalNode* node); 215 virtual void VisitLoadLocalNode(LoadLocalNode* node);
198 216
199 bool can_be_true() const { 217 bool can_be_true() const {
200 // Either both successors are set or neither is set. 218 // Either both successors are set or neither is set.
(...skipping 13 matching lines...) Expand all
214 return true_successor_address_; 232 return true_successor_address_;
215 } 233 }
216 BlockEntryInstr** false_successor_address() const { 234 BlockEntryInstr** false_successor_address() const {
217 ASSERT(can_be_false()); 235 ASSERT(can_be_false());
218 return false_successor_address_; 236 return false_successor_address_;
219 } 237 }
220 238
221 private: 239 private:
222 // Construct and concatenate a Branch instruction to this graph fragment. 240 // Construct and concatenate a Branch instruction to this graph fragment.
223 // Closes the fragment and sets the output parameters. 241 // Closes the fragment and sets the output parameters.
224 void ReturnValue(Value* value); 242 virtual void ReturnValue(Value* value);
225 243
226 // Specify a computation as the final result. Adds a Bind instruction to 244 // Specify a computation as the final result. Adds a Bind instruction to
227 // the graph and branches on its value. 245 // the graph and branches on its value.
228 virtual void ReturnComputation(Computation* computation) { 246 virtual void ReturnComputation(Computation* computation) {
229 AddInstruction(new BindInstr(temp_index(), computation)); 247 AddInstruction(new BindInstr(temp_index(), computation));
230 ReturnValue(new TempVal(temp_index())); 248 ReturnValue(new TempVal(temp_index()));
231 } 249 }
232 250
233 // Output parameters. 251 // Output parameters.
234 BlockEntryInstr** true_successor_address_; 252 BlockEntryInstr** true_successor_address_;
235 BlockEntryInstr** false_successor_address_; 253 BlockEntryInstr** false_successor_address_;
236 }; 254 };
237 255
238 } // namespace dart 256 } // namespace dart
239 257
240 #endif // VM_FLOW_GRAPH_BUILDER_H_ 258 #endif // VM_FLOW_GRAPH_BUILDER_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698