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

Unified Diff: src/data-flow.h

Issue 876001: Initialize reaching definitions state for all flow graph nodes. (Closed)
Patch Set: Incorporated review comments. Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler.cc ('k') | src/data-flow.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/data-flow.h
diff --git a/src/data-flow.h b/src/data-flow.h
index 1c0d1104baa44954f6e4306d687cf10e5ec2c737..ea603ecb6191ce83c85fe7eeda3a46138004aa9f 100644
--- a/src/data-flow.h
+++ b/src/data-flow.h
@@ -100,6 +100,13 @@ class BitVector: public ZoneObject {
}
}
+ void Subtract(const BitVector& other) {
+ ASSERT(other.length() == length());
+ for (int i = 0; i < data_length_; i++) {
+ data_[i] &= ~other.data_[i];
+ }
+ }
+
void Clear() {
for (int i = 0; i < data_length_; i++) {
data_[i] = 0;
@@ -122,6 +129,27 @@ class BitVector: public ZoneObject {
};
+class ReachingDefinitionsData BASE_EMBEDDED {
+ public:
+ ReachingDefinitionsData() : rd_in_(NULL), kill_(NULL), gen_(NULL) {}
+
+ void Initialize(int definition_count) {
+ rd_in_ = new BitVector(definition_count);
+ kill_ = new BitVector(definition_count);
+ gen_ = new BitVector(definition_count);
+ }
+
+ BitVector* rd_in() { return rd_in_; }
+ BitVector* kill() { return kill_; }
+ BitVector* gen() { return gen_; }
+
+ private:
+ BitVector* rd_in_;
+ BitVector* kill_;
+ BitVector* gen_;
+};
+
+
// Flow-graph nodes.
class Node: public ZoneObject {
public:
@@ -149,11 +177,19 @@ class Node: public ZoneObject {
int number() { return number_; }
void set_number(int number) { number_ = number; }
+ // Functions used by data-flow analyses.
+ virtual void InitializeReachingDefinitions(int definition_count,
+ List<BitVector*>* variables);
+
#ifdef DEBUG
- virtual void AssignNumbers();
+ void AssignNodeNumber();
+ void PrintReachingDefinitions();
virtual void PrintText() = 0;
#endif
+ protected:
+ ReachingDefinitionsData rd_;
+
private:
int number_;
bool mark_;
@@ -224,8 +260,10 @@ class BlockNode: public Node {
ZoneList<Node*>* preorder,
ZoneList<Node*>* postorder);
+ void InitializeReachingDefinitions(int definition_count,
+ List<BitVector*>* variables);
+
#ifdef DEBUG
- void AssignNumbers();
void PrintText();
#endif
@@ -384,8 +422,8 @@ class FlowGraphBuilder: public AstVisitor {
void Build(FunctionLiteral* lit);
FlowGraph* graph() { return &graph_; }
-
ZoneList<Node*>* postorder() { return &postorder_; }
+ ZoneList<Expression*>* definitions() { return &definitions_; }
private:
ExitNode* global_exit() { return global_exit_; }
@@ -402,8 +440,9 @@ class FlowGraphBuilder: public AstVisitor {
// The flow graph builder collects a list of definitions (assignments and
// count operations) to stack-allocated variables to use for reaching
- // definitions analysis.
- ZoneList<AstNode*> definitions_;
+ // definitions analysis. AST node numbers in the AST are used to refer
+ // into this list.
+ ZoneList<Expression*> definitions_;
DISALLOW_COPY_AND_ASSIGN(FlowGraphBuilder);
};
@@ -521,6 +560,39 @@ class AssignedVariablesAnalyzer : public AstVisitor {
DISALLOW_COPY_AND_ASSIGN(AssignedVariablesAnalyzer);
};
+
+class ReachingDefinitions BASE_EMBEDDED {
+ public:
+ ReachingDefinitions(ZoneList<Node*>* postorder,
+ ZoneList<Expression*>* definitions,
+ int variable_count)
+ : postorder_(postorder),
+ definitions_(definitions),
+ variables_(variable_count) {
+ int definition_count = definitions->length();
+ for (int i = 0; i < variable_count; i++) {
+ variables_.Add(new BitVector(definition_count));
+ }
+ }
+
+ static int IndexFor(Variable* var, int variable_count);
+
+ void Compute();
+
+ private:
+ // A (postorder) list of flow-graph nodes in the body.
+ ZoneList<Node*>* postorder_;
+
+ // A list of all the definitions in the body.
+ ZoneList<Expression*>* definitions_;
+
+ // For each variable, the set of all its definitions.
+ List<BitVector*> variables_;
+
+ DISALLOW_COPY_AND_ASSIGN(ReachingDefinitions);
+};
+
+
} } // namespace v8::internal
« no previous file with comments | « src/compiler.cc ('k') | src/data-flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698