v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
typing.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_TYPING_H_
29 #define V8_TYPING_H_
30 
31 #include "v8.h"
32 
33 #include "allocation.h"
34 #include "ast.h"
35 #include "compiler.h"
36 #include "type-info.h"
37 #include "types.h"
38 #include "effects.h"
39 #include "zone.h"
40 #include "scopes.h"
41 
42 namespace v8 {
43 namespace internal {
44 
45 
46 class AstTyper: public AstVisitor {
47  public:
48  static void Run(CompilationInfo* info);
49 
50  void* operator new(size_t size, Zone* zone) {
51  return zone->New(static_cast<int>(size));
52  }
53  void operator delete(void* pointer, Zone* zone) { }
54  void operator delete(void* pointer) { }
55 
57 
58  private:
59  explicit AstTyper(CompilationInfo* info);
60 
61  Effect ObservedOnStack(Object* value);
62  void ObserveTypesAtOsrEntry(IterationStatement* stmt);
63 
64  static const int kNoVar = INT_MIN;
67 
68  CompilationInfo* info_;
69  TypeFeedbackOracle oracle_;
70  Store store_;
71 
72  TypeFeedbackOracle* oracle() { return &oracle_; }
73 
74  void NarrowType(Expression* e, Bounds b) {
75  e->set_bounds(Bounds::Both(e->bounds(), b, zone()));
76  }
77  void NarrowLowerType(Expression* e, Type* t) {
78  e->set_bounds(Bounds::NarrowLower(e->bounds(), t, zone()));
79  }
80 
81  Effects EnterEffects() {
82  store_ = store_.Push();
83  return store_.Top();
84  }
85  void ExitEffects() { store_ = store_.Pop(); }
86 
87  int parameter_index(int index) { return -index - 2; }
88  int stack_local_index(int index) { return index; }
89 
90  int variable_index(Variable* var) {
91  // Stack locals have the range [0 .. l]
92  // Parameters have the range [-1 .. p]
93  // We map this to [-p-2 .. -1, 0 .. l]
94  return var->IsStackLocal() ? stack_local_index(var->index()) :
95  var->IsParameter() ? parameter_index(var->index()) : kNoVar;
96  }
97 
98  void VisitDeclarations(ZoneList<Declaration*>* declarations);
99  void VisitStatements(ZoneList<Statement*>* statements);
100 
101 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
103 #undef DECLARE_VISIT
104 
105  DISALLOW_COPY_AND_ASSIGN(AstTyper);
106 };
107 
108 } } // namespace v8::internal
109 
110 #endif // V8_TYPING_H_
BoundsImpl< ZoneTypeConfig > Bounds
Definition: types.h:644
TypeImpl< ZoneTypeConfig > Type
#define DECLARE_VISIT(type)
Definition: typing.h:101
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object size
Definition: flags.cc:211
NestedEffects Push()
Definition: effects.h:343
#define AST_NODE_LIST(V)
Definition: ast.h:121
NestedEffects Pop()
Definition: effects.h:349
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
Definition: flags.cc:317
Effects< Var, kNoVar > Top()
Definition: effects.h:266
static BoundsImpl Both(BoundsImpl b1, BoundsImpl b2, Region *region)
Definition: types.h:612
static BoundsImpl NarrowLower(BoundsImpl b, TypeHandle t, Region *region)
Definition: types.h:627
static void Run(CompilationInfo *info)
Definition: typing.cc:57