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.
5 #ifndef V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
6 #define V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
9 #include "src/bit-vector.h"
11 #include "src/zone-containers.h"
21 // The result of analyzing loop assignments.
22 class LoopAssignmentAnalysis : public ZoneObject {
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;
29 UNREACHABLE(); // should never ask for loops that aren't here!
33 int GetAssignmentCountForTesting(Scope* scope, Variable* var);
36 friend class AstLoopAssignmentAnalyzer;
37 explicit LoopAssignmentAnalysis(Zone* zone) : list_(zone) {}
38 ZoneVector<std::pair<IterationStatement*, BitVector*>> list_;
42 // The class that performs loop assignment analysis by walking the AST.
43 class AstLoopAssignmentAnalyzer : public AstVisitor {
45 AstLoopAssignmentAnalyzer(Zone* zone, CompilationInfo* info);
47 LoopAssignmentAnalysis* Analyze();
49 #define DECLARE_VISIT(type) void Visit##type(type* node) OVERRIDE;
50 AST_NODE_LIST(DECLARE_VISIT)
53 static int GetVariableIndex(Scope* scope, Variable* var);
56 CompilationInfo* info_;
57 ZoneDeque<BitVector*> loop_stack_;
58 LoopAssignmentAnalysis* result_;
60 CompilationInfo* info() { return info_; }
62 void Enter(IterationStatement* loop);
63 void Exit(IterationStatement* loop);
65 void VisitIfNotNull(AstNode* node) {
66 if (node != NULL) Visit(node);
69 void AnalyzeAssignment(Variable* var);
71 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
72 DISALLOW_COPY_AND_ASSIGN(AstLoopAssignmentAnalyzer);
76 } // namespace v8::internal::compiler
78 #endif // V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_