Line data Source code
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-types.h"
11 : #include "src/ast/ast.h"
12 : #include "src/ast/variables.h"
13 : #include "src/effects.h"
14 : #include "src/type-info.h"
15 : #include "src/zone/zone.h"
16 :
17 : namespace v8 {
18 : namespace internal {
19 :
20 : class DeclarationScope;
21 : class Isolate;
22 : class FunctionLiteral;
23 :
24 : class AstTyper final : public AstVisitor<AstTyper> {
25 : public:
26 : AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure,
27 : DeclarationScope* scope, BailoutId osr_ast_id, FunctionLiteral* root,
28 : AstTypeBounds* bounds);
29 : void Run();
30 :
31 53457832 : DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
32 :
33 : private:
34 : Effect ObservedOnStack(Object* value);
35 : void ObserveTypesAtOsrEntry(IterationStatement* stmt);
36 :
37 : static const int kNoVar = INT_MIN;
38 : typedef v8::internal::Effects<int, kNoVar> Effects;
39 : typedef v8::internal::NestedEffects<int, kNoVar> Store;
40 :
41 : Isolate* isolate_;
42 : Zone* zone_;
43 : Handle<JSFunction> closure_;
44 : DeclarationScope* scope_;
45 : BailoutId osr_ast_id_;
46 : FunctionLiteral* root_;
47 : TypeFeedbackOracle oracle_;
48 : Store store_;
49 : AstTypeBounds* bounds_;
50 :
51 : Zone* zone() const { return zone_; }
52 : TypeFeedbackOracle* oracle() { return &oracle_; }
53 :
54 7527408 : void NarrowType(Expression* e, AstBounds b) {
55 7527408 : bounds_->set(e, AstBounds::Both(bounds_->get(e), b, zone()));
56 7527408 : }
57 2605727 : void NarrowLowerType(Expression* e, AstType* t) {
58 2605727 : bounds_->set(e, AstBounds::NarrowLower(bounds_->get(e), t, zone()));
59 2605727 : }
60 :
61 : Effects EnterEffects() {
62 1127579 : store_ = store_.Push();
63 : return store_.Top();
64 : }
65 1127579 : void ExitEffects() { store_ = store_.Pop(); }
66 :
67 1289548 : int parameter_index(int index) { return -index - 2; }
68 : int stack_local_index(int index) { return index; }
69 :
70 : int variable_index(Variable* var);
71 :
72 : void VisitDeclarations(Declaration::List* declarations);
73 : void VisitStatements(ZoneList<Statement*>* statements);
74 :
75 : #define DECLARE_VISIT(type) void Visit##type(type* node);
76 : AST_NODE_LIST(DECLARE_VISIT)
77 : #undef DECLARE_VISIT
78 :
79 : DISALLOW_COPY_AND_ASSIGN(AstTyper);
80 : };
81 :
82 : } // namespace internal
83 : } // namespace v8
84 :
85 : #endif // V8_CRANKSHAFT_TYPING_H_
|