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

Unified Diff: src/compiler/ast-loop-assignment-analyzer.h

Issue 656123005: Implement loop variable assignment analysis. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added unit tests. Created 6 years, 2 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/ast-graph-builder.cc ('k') | src/compiler/ast-loop-assignment-analyzer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/ast-loop-assignment-analyzer.h
diff --git a/src/compiler/ast-loop-assignment-analyzer.h b/src/compiler/ast-loop-assignment-analyzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..daa94f9dfb434edcae3577304b39e51bfb12b636
--- /dev/null
+++ b/src/compiler/ast-loop-assignment-analyzer.h
@@ -0,0 +1,78 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
+#define V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
+
+#include "src/ast.h"
+#include "src/data-flow.h"
+#include "src/v8.h"
+#include "src/zone-containers.h"
+
+namespace v8 {
+namespace internal {
+
+class Variable;
+class Scope;
+
+namespace compiler {
+
+// The result of analyzing loop assignments.
+class LoopAssignmentAnalysis : public ZoneObject {
+ public:
+ BitVector* GetVariablesAssignedInLoop(IterationStatement* loop) {
+ for (size_t i = 0; i < list_.size(); i++) {
+ // TODO(turbofan): hashmap or binary search for loop assignments.
+ if (list_[i].first == loop) return list_[i].second;
+ }
+ UNREACHABLE(); // should never ask for loops that aren't here!
+ return NULL;
+ }
+
+ int GetAssignmentCountForTesting(Scope* scope, Variable* var);
+
+ private:
+ friend class AstLoopAssignmentAnalyzer;
+ explicit LoopAssignmentAnalysis(Zone* zone) : list_(zone) {}
+ ZoneVector<std::pair<IterationStatement*, BitVector*>> list_;
+};
+
+
+// The class that performs loop assignment analysis by walking the AST.
+class AstLoopAssignmentAnalyzer : public AstVisitor {
+ public:
+ AstLoopAssignmentAnalyzer(Zone* zone, CompilationInfo* info);
+
+ LoopAssignmentAnalysis* Analyze();
+
+#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
+ AST_NODE_LIST(DECLARE_VISIT)
+#undef DECLARE_VISIT
+
+ static int GetVariableIndex(Scope* scope, Variable* var);
+
+ private:
+ CompilationInfo* info_;
+ ZoneDeque<BitVector*> loop_stack_;
+ LoopAssignmentAnalysis* result_;
+
+ CompilationInfo* info() { return info_; }
+
+ void Enter(IterationStatement* loop);
+ void Exit(IterationStatement* loop);
+
+ void VisitIfNotNull(AstNode* node) {
+ if (node != NULL) Visit(node);
+ }
+
+ void AnalyzeAssignment(Variable* var);
+
+ DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
+ DISALLOW_COPY_AND_ASSIGN(AstLoopAssignmentAnalyzer);
+};
+}
+}
+} // namespace v8::internal::compiler
+
+#endif // V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
« no previous file with comments | « src/compiler/ast-graph-builder.cc ('k') | src/compiler/ast-loop-assignment-analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698