Bug 1885489 - Part 5: Add SnapshotIterator::readInt32(). r=iain
[gecko.git] / js / src / jit / BytecodeAnalysis.h
bloba3a9f65ddfd6fca118e557b13d996342df58837e
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"
14 namespace js {
15 namespace jit {
17 // Basic information about bytecodes in the script. Used to help baseline
18 // compilation.
19 struct BytecodeInfo {
20 static const uint16_t MAX_STACK_DEPTH = 0xffffU;
21 uint16_t stackDepth;
22 bool initialized : 1;
23 bool jumpTarget : 1;
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
29 // this works.
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);
38 initialized = true;
39 stackDepth = depth;
42 void setJumpTarget(bool normallyReachable) {
43 jumpTarget = true;
44 if (normallyReachable) {
45 jumpTargetNormallyReachable = true;
50 class BytecodeAnalysis {
51 JSScript* script_;
52 Vector<BytecodeInfo, 0, JitAllocPolicy> infos_;
54 public:
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];
70 return nullptr;
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);
80 } // namespace jit
81 } // namespace js
83 #endif /* jit_BytecodeAnalysis_h */