|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef jit_BytecodeAnalysis_h |
|
8 #define jit_BytecodeAnalysis_h |
|
9 |
|
10 #include "jsscript.h" |
|
11 #include "jit/IonAllocPolicy.h" |
|
12 #include "js/Vector.h" |
|
13 |
|
14 namespace js { |
|
15 namespace jit { |
|
16 |
|
17 // Basic information about bytecodes in the script. Used to help baseline compilation. |
|
18 struct BytecodeInfo |
|
19 { |
|
20 static const uint16_t MAX_STACK_DEPTH = 0xffffU; |
|
21 uint16_t stackDepth; |
|
22 bool initialized : 1; |
|
23 bool jumpTarget : 1; |
|
24 bool jumpFallthrough : 1; |
|
25 bool fallthrough : 1; |
|
26 |
|
27 // If true, this is a JSOP_LOOPENTRY op inside a catch or finally block. |
|
28 bool loopEntryInCatchOrFinally : 1; |
|
29 |
|
30 void init(unsigned depth) { |
|
31 JS_ASSERT(depth <= MAX_STACK_DEPTH); |
|
32 JS_ASSERT_IF(initialized, stackDepth == depth); |
|
33 initialized = true; |
|
34 stackDepth = depth; |
|
35 } |
|
36 }; |
|
37 |
|
38 class BytecodeAnalysis |
|
39 { |
|
40 JSScript *script_; |
|
41 Vector<BytecodeInfo, 0, IonAllocPolicy> infos_; |
|
42 |
|
43 bool usesScopeChain_; |
|
44 bool hasTryFinally_; |
|
45 bool hasSetArg_; |
|
46 |
|
47 public: |
|
48 explicit BytecodeAnalysis(TempAllocator &alloc, JSScript *script); |
|
49 |
|
50 bool init(TempAllocator &alloc, GSNCache &gsn); |
|
51 |
|
52 BytecodeInfo &info(jsbytecode *pc) { |
|
53 JS_ASSERT(infos_[script_->pcToOffset(pc)].initialized); |
|
54 return infos_[script_->pcToOffset(pc)]; |
|
55 } |
|
56 |
|
57 BytecodeInfo *maybeInfo(jsbytecode *pc) { |
|
58 if (infos_[script_->pcToOffset(pc)].initialized) |
|
59 return &infos_[script_->pcToOffset(pc)]; |
|
60 return nullptr; |
|
61 } |
|
62 |
|
63 bool usesScopeChain() const { |
|
64 return usesScopeChain_; |
|
65 } |
|
66 |
|
67 bool hasTryFinally() const { |
|
68 return hasTryFinally_; |
|
69 } |
|
70 |
|
71 bool hasSetArg() const { |
|
72 return hasSetArg_; |
|
73 } |
|
74 }; |
|
75 |
|
76 |
|
77 } // namespace jit |
|
78 } // namespace js |
|
79 |
|
80 #endif /* jit_BytecodeAnalysis_h */ |