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 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 { 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 info(jsbytecode * pc)50 BytecodeInfo& info(jsbytecode* pc) { 51 MOZ_ASSERT(infos_[script_->pcToOffset(pc)].initialized); 52 return infos_[script_->pcToOffset(pc)]; 53 } 54 maybeInfo(jsbytecode * pc)55 BytecodeInfo* maybeInfo(jsbytecode* pc) { 56 if (infos_[script_->pcToOffset(pc)].initialized) 57 return &infos_[script_->pcToOffset(pc)]; 58 return nullptr; 59 } 60 usesEnvironmentChain()61 bool usesEnvironmentChain() const { 62 return usesEnvironmentChain_; 63 } 64 hasTryFinally()65 bool hasTryFinally() const { 66 return hasTryFinally_; 67 } 68 hasSetArg()69 bool hasSetArg() const { 70 return hasSetArg_; 71 } 72 }; 73 74 75 } // namespace jit 76 } // namespace js 77 78 #endif /* jit_BytecodeAnalysis_h */ 79