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"
10 #include "src/zone-containers.h"
20 // The result of analyzing loop assignments.
21 class LoopAssignmentAnalysis : public ZoneObject {
23 BitVector* GetVariablesAssignedInLoop(IterationStatement* loop) {
24 for (size_t i = 0; i < list_.size(); i++) {
25 // TODO(turbofan): hashmap or binary search for loop assignments.
26 if (list_[i].first == loop) return list_[i].second;
28 UNREACHABLE(); // should never ask for loops that aren't here!
32 int GetAssignmentCountForTesting(Scope* scope, Variable* var);
35 friend class AstLoopAssignmentAnalyzer;
36 explicit LoopAssignmentAnalysis(Zone* zone) : list_(zone) {}
37 ZoneVector<std::pair<IterationStatement*, BitVector*>> list_;
41 // The class that performs loop assignment analysis by walking the AST.
42 class AstLoopAssignmentAnalyzer : public AstVisitor {
44 AstLoopAssignmentAnalyzer(Zone* zone, CompilationInfo* info);
46 LoopAssignmentAnalysis* Analyze();
48 #define DECLARE_VISIT(type) void Visit##type(type* node) override;
49 AST_NODE_LIST(DECLARE_VISIT)
52 static int GetVariableIndex(Scope* scope, Variable* var);
55 CompilationInfo* info_;
56 ZoneDeque<BitVector*> loop_stack_;
57 LoopAssignmentAnalysis* result_;
59 CompilationInfo* info() { return info_; }
61 void Enter(IterationStatement* loop);
62 void Exit(IterationStatement* loop);
64 void VisitIfNotNull(AstNode* node) {
65 if (node != NULL) Visit(node);
68 void AnalyzeAssignment(Variable* var);
70 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
71 DISALLOW_COPY_AND_ASSIGN(AstLoopAssignmentAnalyzer);
73 } // namespace compiler
74 } // namespace internal
77 #endif // V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_