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

Unified Diff: runtime/vm/flow_graph_optimizer.h

Issue 10949020: Reapply "Initial implementation of sparse conditional constant propagation." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase to HEAD. 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/flow_graph_optimizer.h
diff --git a/runtime/vm/flow_graph_optimizer.h b/runtime/vm/flow_graph_optimizer.h
index 4efbbf0b7ee26f0feb36a463a47edf57ab679db1..9e42123b9747227cc1fc18738010783267416960 100644
--- a/runtime/vm/flow_graph_optimizer.h
+++ b/runtime/vm/flow_graph_optimizer.h
@@ -156,6 +156,66 @@ class DominatorBasedCSE : public AllStatic {
};
+// Sparse conditional constant propagation and unreachable code elimination.
+// Assumes that use lists are computed and preserves them.
+class ConstantPropagator : public FlowGraphVisitor {
+ public:
+ ConstantPropagator(FlowGraph* graph,
+ const GrowableArray<BlockEntryInstr*>& ignored);
+
+ static void Optimize(FlowGraph* graph);
+
+ // Used to initialize the abstract value of definitions.
+ static RawObject* Unknown() { return Object::transition_sentinel(); }
+
+ private:
+ void Analyze();
+ void Transform();
+
+ void SetReachable(BlockEntryInstr* block);
+ void SetValue(Definition* definition, const Object& value);
+
+ // Assign the join (least upper bound) of a pair of abstract values to the
+ // first one.
+ void Join(Object* left, const Object& right);
+
+ bool IsUnknown(const Object& value) {
+ return value.raw() == unknown_.raw();
+ }
+ bool IsNonConstant(const Object& value) {
+ return value.raw() == non_constant_.raw();
+ }
+ bool IsConstant(const Object& value) {
+ return !IsNonConstant(value) && !IsUnknown(value);
+ }
+
+ virtual void VisitBlocks() { UNREACHABLE(); }
+
+#define DECLARE_VISIT(type) virtual void Visit##type(type##Instr* instr);
+ FOR_EACH_INSTRUCTION(DECLARE_VISIT)
+#undef DECLARE_VISIT
+
+ FlowGraph* graph_;
+
+ // Sentinels for unknown constant and non-constant values.
+ const Object& unknown_;
+ const Object& non_constant_;
+
+ // Analysis results. For each block, a reachability bit. Indexed by
+ // preorder number.
+ BitVector* reachable_;
+
+ // Definitions can move up the lattice twice, so we use a mark bit to
+ // indicate that they are already on the worklist in order to avoid adding
+ // them again. Indexed by SSA temp index.
+ BitVector* definition_marks_;
+
+ // Worklists of blocks and definitions.
+ GrowableArray<BlockEntryInstr*> block_worklist_;
+ GrowableArray<Definition*> definition_worklist_;
+};
+
+
} // namespace dart
#endif // VM_FLOW_GRAPH_OPTIMIZER_H_

Powered by Google App Engine
This is Rietveld 408576698