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

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

Issue 14215006: Re-apply r20377. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/intermediate_language.h" 9 #include "vm/intermediate_language.h"
10 #include "vm/parser.h" 10 #include "vm/parser.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 class FlowGraphBuilder; 14 class FlowGraphBuilder;
15 class ValueInliningContext; 15 class ValueInliningContext;
16 class VariableLivenessAnalysis;
16 17
17 class BlockIterator : public ValueObject { 18 class BlockIterator : public ValueObject {
18 public: 19 public:
19 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order) 20 explicit BlockIterator(const GrowableArray<BlockEntryInstr*>& block_order)
20 : block_order_(block_order), current_(0) { } 21 : block_order_(block_order), current_(0) { }
21 22
22 BlockIterator(const BlockIterator& other) 23 BlockIterator(const BlockIterator& other)
23 : ValueObject(), 24 : ValueObject(),
24 block_order_(other.block_order_), 25 block_order_(other.block_order_),
25 current_(other.current_) { } 26 current_(other.current_) { }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // SSA transformation methods and fields. 152 // SSA transformation methods and fields.
152 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier); 153 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier);
153 154
154 void CompressPath( 155 void CompressPath(
155 intptr_t start_index, 156 intptr_t start_index,
156 intptr_t current_index, 157 intptr_t current_index,
157 GrowableArray<intptr_t>* parent, 158 GrowableArray<intptr_t>* parent,
158 GrowableArray<intptr_t>* label); 159 GrowableArray<intptr_t>* label);
159 160
160 void Rename(GrowableArray<PhiInstr*>* live_phis, 161 void Rename(GrowableArray<PhiInstr*>* live_phis,
162 VariableLivenessAnalysis* variable_liveness,
161 GrowableArray<Definition*>* inlining_parameters); 163 GrowableArray<Definition*>* inlining_parameters);
164
162 void RenameRecursive( 165 void RenameRecursive(
163 BlockEntryInstr* block_entry, 166 BlockEntryInstr* block_entry,
164 GrowableArray<Definition*>* env, 167 GrowableArray<Definition*>* env,
165 GrowableArray<PhiInstr*>* live_phis); 168 GrowableArray<PhiInstr*>* live_phis,
169 VariableLivenessAnalysis* variable_liveness);
166 170
167 void AttachEnvironment(Instruction* instr, GrowableArray<Definition*>* env); 171 void AttachEnvironment(Instruction* instr, GrowableArray<Definition*>* env);
168 172
169 void InsertPhis( 173 void InsertPhis(
170 const GrowableArray<BlockEntryInstr*>& preorder, 174 const GrowableArray<BlockEntryInstr*>& preorder,
171 const GrowableArray<BitVector*>& assigned_vars, 175 const GrowableArray<BitVector*>& assigned_vars,
172 const GrowableArray<BitVector*>& dom_frontier); 176 const GrowableArray<BitVector*>& dom_frontier);
173 177
174 void RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis); 178 void RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis);
175 179
(...skipping 14 matching lines...) Expand all
190 const intptr_t num_non_copied_params_; 194 const intptr_t num_non_copied_params_;
191 const intptr_t num_stack_locals_; 195 const intptr_t num_stack_locals_;
192 GraphEntryInstr* graph_entry_; 196 GraphEntryInstr* graph_entry_;
193 GrowableArray<BlockEntryInstr*> preorder_; 197 GrowableArray<BlockEntryInstr*> preorder_;
194 GrowableArray<BlockEntryInstr*> postorder_; 198 GrowableArray<BlockEntryInstr*> postorder_;
195 GrowableArray<BlockEntryInstr*> reverse_postorder_; 199 GrowableArray<BlockEntryInstr*> reverse_postorder_;
196 bool invalid_dominator_tree_; 200 bool invalid_dominator_tree_;
197 ConstantInstr* constant_null_; 201 ConstantInstr* constant_null_;
198 }; 202 };
199 203
204
205 class LivenessAnalysis : public ValueObject {
206 public:
207 LivenessAnalysis(intptr_t variable_count,
208 const GrowableArray<BlockEntryInstr*>& postorder);
209
210 void Analyze();
211
212 virtual ~LivenessAnalysis() { }
213
214 BitVector* GetLiveInSetAt(intptr_t postorder_number) const {
215 return live_in_[postorder_number];
216 }
217
218 BitVector* GetLiveOutSetAt(intptr_t postorder_number) const {
219 return live_out_[postorder_number];
220 }
221
222 BitVector* GetLiveInSet(BlockEntryInstr* block) const {
223 return GetLiveInSetAt(block->postorder_number());
224 }
225
226 BitVector* GetKillSet(BlockEntryInstr* block) const {
227 return kill_[block->postorder_number()];
228 }
229
230 BitVector* GetLiveOutSet(BlockEntryInstr* block) const {
231 return GetLiveOutSetAt(block->postorder_number());
232 }
233
234 // Print results of liveness analysis.
235 void Dump();
236
237 protected:
238 // Compute initial values for live-out, kill and live-in sets.
239 virtual void ComputeInitialSets() = 0;
240
241 // Update live-out set for the given block: live-out should contain
242 // all values that are live-in for block's successors.
243 // Returns true if live-out set was changed.
244 bool UpdateLiveOut(const BlockEntryInstr& instr);
245
246 // Update live-in set for the given block: live-in should contain
247 // all values that are live-out from the block and are not defined
248 // by this block.
249 // Returns true if live-in set was changed.
250 bool UpdateLiveIn(const BlockEntryInstr& instr);
251
252 // Perform fix-point iteration updating live-out and live-in sets
253 // for blocks until they stop changing.
254 void ComputeLiveInAndLiveOutSets();
255
256 const intptr_t variable_count_;
257
258 const GrowableArray<BlockEntryInstr*>& postorder_;
259
260 // Live-out sets for each block. They contain indices of variables
261 // that are live out from this block: that is values that were either
262 // defined in this block or live into it and that are used in some
263 // successor block.
264 GrowableArray<BitVector*> live_out_;
265
266 // Kill sets for each block. They contain indices of variables that
267 // are defined by this block.
268 GrowableArray<BitVector*> kill_;
269
270 // Live-in sets for each block. They contain indices of variables
271 // that are used by this block or its successors.
272 GrowableArray<BitVector*> live_in_;
273 };
274
200 } // namespace dart 275 } // namespace dart
201 276
202 #endif // VM_FLOW_GRAPH_H_ 277 #endif // VM_FLOW_GRAPH_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698