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 "jit/JitAllocPolicy.h" 11 #include "js/Vector.h" 12 #include "vm/JSScript.h" 13 14 namespace js { 15 namespace jit { 16 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; 24 25 // If true, this is a JSOP_LOOPENTRY op inside a catch or finally block. 26 bool loopEntryInCatchOrFinally : 1; 27 initBytecodeInfo28 void init(unsigned depth) { 29 MOZ_ASSERT(depth <= MAX_STACK_DEPTH); 30 MOZ_ASSERT_IF(initialized, stackDepth == depth); 31 initialized = true; 32 stackDepth = depth; 33 } 34 }; 35 36 class BytecodeAnalysis { 37 JSScript* script_; 38 Vector<BytecodeInfo, 0, JitAllocPolicy> infos_; 39 40 bool usesEnvironmentChain_; 41 bool hasTryFinally_; 42 43 public: 44 explicit BytecodeAnalysis(TempAllocator& alloc, JSScript* script); 45 46 MOZ_MUST_USE bool init(TempAllocator& alloc, GSNCache& gsn); 47 info(jsbytecode * pc)48 BytecodeInfo& info(jsbytecode* pc) { 49 MOZ_ASSERT(infos_[script_->pcToOffset(pc)].initialized); 50 return infos_[script_->pcToOffset(pc)]; 51 } 52 maybeInfo(jsbytecode * pc)53 BytecodeInfo* maybeInfo(jsbytecode* pc) { 54 if (infos_[script_->pcToOffset(pc)].initialized) 55 return &infos_[script_->pcToOffset(pc)]; 56 return nullptr; 57 } 58 usesEnvironmentChain()59 bool usesEnvironmentChain() const { return usesEnvironmentChain_; } 60 hasTryFinally()61 bool hasTryFinally() const { return hasTryFinally_; } 62 }; 63 64 } // namespace jit 65 } // namespace js 66 67 #endif /* jit_BytecodeAnalysis_h */ 68