1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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/. */
7 #ifndef jit_BytecodeAnalysis_h
8 #define jit_BytecodeAnalysis_h
10 #include "jit/JitAllocPolicy.h"
11 #include "js/Vector.h"
12 #include "vm/JSScript.h"
17 // Basic information about bytecodes in the script. Used to help baseline
20 static const uint16_t MAX_STACK_DEPTH
= 0xffffU
;
25 // If true, this is a JSOp::LoopHead where we can OSR into Ion/Warp code.
26 bool loopHeadCanOsr
: 1;
28 // See the comment above normallyReachable in BytecodeAnalysis.cpp for how
30 bool jumpTargetNormallyReachable
: 1;
32 // True if the script has a resume offset for this bytecode op.
33 bool hasResumeOffset
: 1;
35 void init(unsigned depth
) {
36 MOZ_ASSERT(depth
<= MAX_STACK_DEPTH
);
37 MOZ_ASSERT_IF(initialized
, stackDepth
== depth
);
42 void setJumpTarget(bool normallyReachable
) {
44 if (normallyReachable
) {
45 jumpTargetNormallyReachable
= true;
50 class BytecodeAnalysis
{
52 Vector
<BytecodeInfo
, 0, JitAllocPolicy
> infos_
;
55 explicit BytecodeAnalysis(TempAllocator
& alloc
, JSScript
* script
);
57 [[nodiscard
]] bool init(TempAllocator
& alloc
);
59 BytecodeInfo
& info(jsbytecode
* pc
) {
60 uint32_t pcOffset
= script_
->pcToOffset(pc
);
61 MOZ_ASSERT(infos_
[pcOffset
].initialized
);
62 return infos_
[pcOffset
];
65 BytecodeInfo
* maybeInfo(jsbytecode
* pc
) {
66 uint32_t pcOffset
= script_
->pcToOffset(pc
);
67 if (infos_
[pcOffset
].initialized
) {
68 return &infos_
[pcOffset
];
73 void checkWarpSupport(JSOp op
);
76 // Whether this script uses the frame's environment chain. The result is cached
77 // in JitScript and used by WarpBuilder.
78 bool ScriptUsesEnvironmentChain(JSScript
* script
);
83 #endif /* jit_BytecodeAnalysis_h */