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

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

Issue 12638040: Compute local variable liveness before translation to SSA. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // SSA transformation methods and fields. 156 // SSA transformation methods and fields.
156 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier); 157 void ComputeDominators(GrowableArray<BitVector*>* dominance_frontier);
157 158
158 void CompressPath( 159 void CompressPath(
159 intptr_t start_index, 160 intptr_t start_index,
160 intptr_t current_index, 161 intptr_t current_index,
161 GrowableArray<intptr_t>* parent, 162 GrowableArray<intptr_t>* parent,
162 GrowableArray<intptr_t>* label); 163 GrowableArray<intptr_t>* label);
163 164
164 void Rename(GrowableArray<PhiInstr*>* live_phis, 165 void Rename(GrowableArray<PhiInstr*>* live_phis,
166 VariableLivenessAnalysis* variable_liveness,
165 GrowableArray<Definition*>* inlining_parameters); 167 GrowableArray<Definition*>* inlining_parameters);
168
166 void RenameRecursive( 169 void RenameRecursive(
167 BlockEntryInstr* block_entry, 170 BlockEntryInstr* block_entry,
168 GrowableArray<Definition*>* env, 171 GrowableArray<Definition*>* env,
169 GrowableArray<PhiInstr*>* live_phis); 172 GrowableArray<PhiInstr*>* live_phis,
173 VariableLivenessAnalysis* variable_liveness);
170 174
171 void InsertPhis( 175 void InsertPhis(
172 const GrowableArray<BlockEntryInstr*>& preorder, 176 const GrowableArray<BlockEntryInstr*>& preorder,
173 const GrowableArray<BitVector*>& assigned_vars, 177 const GrowableArray<BitVector*>& assigned_vars,
174 const GrowableArray<BitVector*>& dom_frontier); 178 const GrowableArray<BitVector*>& dom_frontier);
175 179
176 void RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis); 180 void RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis);
177 181
178 void ReplacePredecessor(BlockEntryInstr* old_block, 182 void ReplacePredecessor(BlockEntryInstr* old_block,
179 BlockEntryInstr* new_block); 183 BlockEntryInstr* new_block);
(...skipping 12 matching lines...) Expand all
192 const intptr_t num_non_copied_params_; 196 const intptr_t num_non_copied_params_;
193 const intptr_t num_stack_locals_; 197 const intptr_t num_stack_locals_;
194 GraphEntryInstr* graph_entry_; 198 GraphEntryInstr* graph_entry_;
195 GrowableArray<BlockEntryInstr*> preorder_; 199 GrowableArray<BlockEntryInstr*> preorder_;
196 GrowableArray<BlockEntryInstr*> postorder_; 200 GrowableArray<BlockEntryInstr*> postorder_;
197 GrowableArray<BlockEntryInstr*> reverse_postorder_; 201 GrowableArray<BlockEntryInstr*> reverse_postorder_;
198 bool invalid_dominator_tree_; 202 bool invalid_dominator_tree_;
199 ConstantInstr* constant_null_; 203 ConstantInstr* constant_null_;
200 }; 204 };
201 205
206
207 class LivenessAnalysis : public ValueObject {
208 public:
209 LivenessAnalysis(intptr_t variable_count,
210 const GrowableArray<BlockEntryInstr*>& postorder);
211
212 void Analyze();
213
214 virtual ~LivenessAnalysis() { }
215
216 BitVector* GetLiveInSetAt(intptr_t postorder_number) const {
217 return live_in_[postorder_number];
218 }
219
220 BitVector* GetLiveOutSetAt(intptr_t postorder_number) const {
221 return live_out_[postorder_number];
222 }
223
224 BitVector* GetLiveInSet(BlockEntryInstr* block) const {
225 return GetLiveInSetAt(block->postorder_number());
226 }
227
228 BitVector* GetKillSet(BlockEntryInstr* block) const {
229 return kill_[block->postorder_number()];
230 }
231
232 BitVector* GetLiveOutSet(BlockEntryInstr* block) const {
233 return GetLiveOutSetAt(block->postorder_number());
234 }
235
236 // Print results of liveness analysis.
237 void Dump();
238
239 protected:
240 // Compute initial values for live-out, kill and live-in sets.
241 virtual void ComputeInitialSets() = 0;
242
243 // Update live-out set for the given block: live-out should contain
244 // all values that are live-in for block's successors.
245 // Returns true if live-out set was changed.
246 bool UpdateLiveOut(const BlockEntryInstr& instr);
247
248 // Update live-in set for the given block: live-in should contain
249 // all values that are live-out from the block and are not defined
250 // by this block.
251 // Returns true if live-in set was changed.
252 bool UpdateLiveIn(const BlockEntryInstr& instr);
253
254 // Perform fix-point iteration updating live-out and live-in sets
255 // for blocks until they stop changing.
256 void ComputeLiveInAndLiveOutSets();
257
258 const intptr_t variable_count_;
259
260 const GrowableArray<BlockEntryInstr*>& postorder_;
261
262 // Live-out sets for each block. They contain indices of SSA values
Kevin Millikin (Google) 2013/03/22 11:57:52 This comment and the ones below should not mention
Vyacheslav Egorov (Google) 2013/03/22 12:16:15 Done.
263 // that are live out from this block: that is values that were either
264 // defined in this block or live into it and that are used in some
265 // successor block.
266 GrowableArray<BitVector*> live_out_;
267
268 // Kill sets for each block. They contain indices of SSA values that
269 // are defined by this block.
270 GrowableArray<BitVector*> kill_;
271
272 // Live-in sets for each block. They contain indices of SSA values
273 // that are used by this block or its successors.
274 GrowableArray<BitVector*> live_in_;
275 };
276
202 } // namespace dart 277 } // namespace dart
203 278
204 #endif // VM_FLOW_GRAPH_H_ 279 #endif // VM_FLOW_GRAPH_H_
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/flow_graph.cc » ('j') | runtime/vm/flow_graph.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698