• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_CRANKSHAFT_TYPING_H_
6 #define V8_CRANKSHAFT_TYPING_H_
7 
8 #include "src/allocation.h"
9 #include "src/ast/ast-type-bounds.h"
10 #include "src/ast/ast.h"
11 #include "src/ast/scopes.h"
12 #include "src/effects.h"
13 #include "src/type-info.h"
14 #include "src/types.h"
15 #include "src/zone.h"
16 
17 namespace v8 {
18 namespace internal {
19 
20 class AstTyper: public AstVisitor {
21  public:
22   AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
23            Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root,
24            AstTypeBounds* bounds);
25   void Run();
26 
27   DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
28 
29  private:
30   Effect ObservedOnStack(Object* value);
31   void ObserveTypesAtOsrEntry(IterationStatement* stmt);
32 
33   static const int kNoVar = INT_MIN;
34   typedef v8::internal::Effects<int, kNoVar> Effects;
35   typedef v8::internal::NestedEffects<int, kNoVar> Store;
36 
37   Isolate* isolate_;
38   Zone* zone_;
39   Handle<JSFunction> closure_;
40   Scope* scope_;
41   BailoutId osr_ast_id_;
42   FunctionLiteral* root_;
43   TypeFeedbackOracle oracle_;
44   Store store_;
45   AstTypeBounds* bounds_;
46 
zone()47   Zone* zone() const { return zone_; }
oracle()48   TypeFeedbackOracle* oracle() { return &oracle_; }
49 
NarrowType(Expression * e,Bounds b)50   void NarrowType(Expression* e, Bounds b) {
51     bounds_->set(e, Bounds::Both(bounds_->get(e), b, zone()));
52   }
NarrowLowerType(Expression * e,Type * t)53   void NarrowLowerType(Expression* e, Type* t) {
54     bounds_->set(e, Bounds::NarrowLower(bounds_->get(e), t, zone()));
55   }
56 
EnterEffects()57   Effects EnterEffects() {
58     store_ = store_.Push();
59     return store_.Top();
60   }
ExitEffects()61   void ExitEffects() { store_ = store_.Pop(); }
62 
parameter_index(int index)63   int parameter_index(int index) { return -index - 2; }
stack_local_index(int index)64   int stack_local_index(int index) { return index; }
65 
variable_index(Variable * var)66   int variable_index(Variable* var) {
67     // Stack locals have the range [0 .. l]
68     // Parameters have the range [-1 .. p]
69     // We map this to [-p-2 .. -1, 0 .. l]
70     return var->IsStackLocal() ? stack_local_index(var->index()) :
71            var->IsParameter() ? parameter_index(var->index()) : kNoVar;
72   }
73 
74   void VisitDeclarations(ZoneList<Declaration*>* declarations) override;
75   void VisitStatements(ZoneList<Statement*>* statements) override;
76 
77 #define DECLARE_VISIT(type) void Visit##type(type* node) override;
78   AST_NODE_LIST(DECLARE_VISIT)
79 #undef DECLARE_VISIT
80 
81   DISALLOW_COPY_AND_ASSIGN(AstTyper);
82 };
83 
84 }  // namespace internal
85 }  // namespace v8
86 
87 #endif  // V8_CRANKSHAFT_TYPING_H_
88