Line data Source code
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/JitAllocPolicy.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 :
25 : // If true, this is a JSOP_LOOPENTRY op inside a catch or finally block.
26 : bool loopEntryInCatchOrFinally : 1;
27 :
28 108979 : void init(unsigned depth) {
29 108979 : MOZ_ASSERT(depth <= MAX_STACK_DEPTH);
30 108979 : MOZ_ASSERT_IF(initialized, stackDepth == depth);
31 108979 : initialized = true;
32 108979 : stackDepth = depth;
33 108979 : }
34 : };
35 :
36 947 : class BytecodeAnalysis
37 : {
38 : JSScript* script_;
39 : Vector<BytecodeInfo, 0, JitAllocPolicy> infos_;
40 :
41 : bool usesEnvironmentChain_;
42 : bool hasTryFinally_;
43 : bool hasSetArg_;
44 :
45 : public:
46 : explicit BytecodeAnalysis(TempAllocator& alloc, JSScript* script);
47 :
48 : MOZ_MUST_USE bool init(TempAllocator& alloc, GSNCache& gsn);
49 :
50 1109 : BytecodeInfo& info(jsbytecode* pc) {
51 1109 : MOZ_ASSERT(infos_[script_->pcToOffset(pc)].initialized);
52 1109 : return infos_[script_->pcToOffset(pc)];
53 : }
54 :
55 81416 : BytecodeInfo* maybeInfo(jsbytecode* pc) {
56 81416 : if (infos_[script_->pcToOffset(pc)].initialized)
57 80699 : return &infos_[script_->pcToOffset(pc)];
58 717 : return nullptr;
59 : }
60 :
61 82 : bool usesEnvironmentChain() const {
62 82 : return usesEnvironmentChain_;
63 : }
64 :
65 10 : bool hasTryFinally() const {
66 10 : return hasTryFinally_;
67 : }
68 :
69 21 : bool hasSetArg() const {
70 21 : return hasSetArg_;
71 : }
72 : };
73 :
74 :
75 : } // namespace jit
76 : } // namespace js
77 :
78 : #endif /* jit_BytecodeAnalysis_h */
|