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

Side by Side 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, 1 month 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
6 #define V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
7
8 #include "src/ast.h"
9 #include "src/data-flow.h"
10 #include "src/v8.h"
11 #include "src/zone-containers.h"
12
13 namespace v8 {
14 namespace internal {
15
16 class Variable;
17 class Scope;
18
19 namespace compiler {
20
21 // The result of analyzing loop assignments.
22 class LoopAssignmentAnalysis : public ZoneObject {
23 public:
24 BitVector* GetVariablesAssignedInLoop(IterationStatement* loop) {
25 for (size_t i = 0; i < list_.size(); i++) {
26 // TODO(turbofan): hashmap or binary search for loop assignments.
27 if (list_[i].first == loop) return list_[i].second;
28 }
29 UNREACHABLE(); // should never ask for loops that aren't here!
30 return NULL;
31 }
32
33 int GetAssignmentCountForTesting(Scope* scope, Variable* var);
34
35 private:
36 friend class AstLoopAssignmentAnalyzer;
37 explicit LoopAssignmentAnalysis(Zone* zone) : list_(zone) {}
38 ZoneVector<std::pair<IterationStatement*, BitVector*>> list_;
39 };
40
41
42 // The class that performs loop assignment analysis by walking the AST.
43 class AstLoopAssignmentAnalyzer : public AstVisitor {
44 public:
45 AstLoopAssignmentAnalyzer(Zone* zone, CompilationInfo* info);
46
47 LoopAssignmentAnalysis* Analyze();
48
49 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
50 AST_NODE_LIST(DECLARE_VISIT)
51 #undef DECLARE_VISIT
52
53 static int GetVariableIndex(Scope* scope, Variable* var);
54
55 private:
56 CompilationInfo* info_;
57 ZoneDeque<BitVector*> loop_stack_;
58 LoopAssignmentAnalysis* result_;
59
60 CompilationInfo* info() { return info_; }
61
62 void Enter(IterationStatement* loop);
63 void Exit(IterationStatement* loop);
64
65 void VisitIfNotNull(AstNode* node) {
66 if (node != NULL) Visit(node);
67 }
68
69 void AnalyzeAssignment(Variable* var);
70
71 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
72 DISALLOW_COPY_AND_ASSIGN(AstLoopAssignmentAnalyzer);
73 };
74 }
75 }
76 } // namespace v8::internal::compiler
77
78 #endif // V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
OLDNEW
« 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