JitOptions.h (6197B)
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/. */ 6 7 #ifndef jit_JitOptions_h 8 #define jit_JitOptions_h 9 10 #include "mozilla/Maybe.h" 11 12 #include "jit/IonTypes.h" 13 #include "js/TypeDecls.h" 14 15 namespace js { 16 namespace jit { 17 18 // Possible register allocators which may be used. 19 enum IonRegisterAllocator { 20 RegisterAllocator_Backtracking, 21 RegisterAllocator_Simple, 22 }; 23 24 // Which register to use as base register to access stack slots: frame pointer, 25 // stack pointer, or whichever is the default for this platform. See comment 26 // for baseRegForLocals in JitOptions.cpp for more information. 27 enum class BaseRegForAddress { Default, FP, SP }; 28 29 enum class UseMonomorphicInlining : uint8_t { 30 Default, 31 Always, 32 Never, 33 }; 34 35 static inline mozilla::Maybe<IonRegisterAllocator> LookupRegisterAllocator( 36 const char* name) { 37 if (!strcmp(name, "backtracking")) { 38 return mozilla::Some(RegisterAllocator_Backtracking); 39 } 40 if (!strcmp(name, "simple")) { 41 return mozilla::Some(RegisterAllocator_Simple); 42 } 43 return mozilla::Nothing(); 44 } 45 46 struct DefaultJitOptions { 47 bool checkGraphConsistency; 48 #ifdef CHECK_OSIPOINT_REGISTERS 49 bool checkOsiPointRegisters; 50 #endif 51 bool checkRangeAnalysis; 52 bool runExtraChecks; 53 bool disableJitBackend; 54 bool disableJitHints; 55 bool disableAma; 56 bool disableEaa; 57 bool disableEdgeCaseAnalysis; 58 bool disableGvn; 59 bool disableInlining; 60 bool disableLicm; 61 bool disablePruning; 62 bool disableInstructionReordering; 63 bool disableIteratorIndices; 64 bool disableMarkLoadsUsedAsPropertyKeys; 65 bool disableRangeAnalysis; 66 bool disableRecoverIns; 67 bool disableScalarReplacement; 68 bool disableCacheIR; 69 bool disableStubFolding; 70 bool disableStubFoldingLoadsAndStores; 71 bool disableSink; 72 bool disableRedundantShapeGuards; 73 bool disableRedundantGCBarriers; 74 bool disableBailoutLoopCheck; 75 bool disableObjectKeysScalarReplacement; 76 #ifdef ENABLE_PORTABLE_BASELINE_INTERP 77 bool portableBaselineInterpreter; 78 #endif 79 bool baselineInterpreter; 80 bool baselineJit; 81 bool baselineBatching; 82 bool ion; 83 bool jitForTrustedPrincipals; 84 bool nativeRegExp; 85 bool forceInlineCaches; 86 bool forceMegamorphicICs; 87 bool fullDebugChecks; 88 bool limitScriptSize; 89 bool osr; 90 bool wasmFoldOffsets; 91 bool wasmDelayTier2; 92 bool lessDebugCode; 93 bool onlyInlineSelfHosted; 94 bool enableICFramePointers; 95 bool enableWasmJitExit; 96 bool enableWasmJitEntry; 97 bool enableWasmIonFastCalls; 98 #ifdef WASM_CODEGEN_DEBUG 99 bool enableWasmImportCallSpew; 100 bool enableWasmFuncCallSpew; 101 #endif 102 bool emitInterpreterEntryTrampoline; 103 uint32_t baselineInterpreterWarmUpThreshold; 104 uint32_t baselineJitWarmUpThreshold; 105 uint32_t baselineQueueCapacity; 106 uint32_t trialInliningWarmUpThreshold; 107 uint32_t trialInliningInitialWarmUpCount; 108 UseMonomorphicInlining monomorphicInlining = UseMonomorphicInlining::Default; 109 uint32_t normalIonWarmUpThreshold; 110 uint32_t regexpWarmUpThreshold; 111 #ifdef ENABLE_PORTABLE_BASELINE_INTERP 112 uint32_t portableBaselineInterpreterWarmUpThreshold; 113 #endif 114 uint32_t exceptionBailoutThreshold; 115 uint32_t frequentBailoutThreshold; 116 uint32_t maxStackArgs; 117 uint32_t osrPcMismatchesBeforeRecompile; 118 uint32_t smallFunctionMaxBytecodeLength; 119 uint32_t inliningEntryThreshold; 120 uint32_t jumpThreshold; 121 uint32_t branchPruningHitCountFactor; 122 uint32_t branchPruningInstFactor; 123 uint32_t branchPruningBlockSpanFactor; 124 uint32_t branchPruningEffectfulInstFactor; 125 uint32_t branchPruningThreshold; 126 uint32_t ionMaxScriptSize; 127 uint32_t ionMaxScriptSizeMainThread; 128 uint32_t ionMaxLocalsAndArgs; 129 uint32_t ionMaxLocalsAndArgsMainThread; 130 uint32_t wasmBatchBaselineThreshold; 131 uint32_t wasmBatchIonThreshold; 132 #ifdef ENABLE_JS_AOT_ICS 133 bool enableAOTICs; 134 bool enableAOTICEnforce; 135 #endif 136 137 // Spectre mitigation flags. Each mitigation has its own flag in order to 138 // measure the effectiveness of each mitigation with various proof of 139 // concept. 140 bool spectreIndexMasking; 141 bool spectreObjectMitigations; 142 bool spectreStringMitigations; 143 bool spectreValueMasking; 144 bool spectreJitToCxxCalls; 145 146 bool writeProtectCode; 147 148 bool supportsUnalignedAccesses; 149 BaseRegForAddress baseRegForLocals; 150 151 // Irregexp shim flags 152 bool correctness_fuzzer_suppressions; 153 bool enable_regexp_unaligned_accesses; 154 bool js_regexp_modifiers; 155 bool js_regexp_duplicate_named_groups; 156 bool regexp_possessive_quantifier; 157 bool regexp_optimization; 158 bool regexp_peephole_optimization; 159 bool regexp_tier_up; 160 bool trace_regexp_assembler; 161 bool trace_regexp_bytecodes; 162 bool trace_regexp_parser; 163 bool trace_regexp_peephole_optimization; 164 165 DefaultJitOptions(); 166 bool isSmallFunction(JSScript* script) const; 167 #ifdef ENABLE_PORTABLE_BASELINE_INTERP 168 void setEagerPortableBaselineInterpreter(); 169 #endif 170 void setEagerBaselineCompilation(); 171 void setEagerIonCompilation(); 172 void setNormalIonWarmUpThreshold(uint32_t warmUpThreshold); 173 void resetNormalIonWarmUpThreshold(); 174 void enableGvn(bool val); 175 void setFastWarmUp(); 176 177 void maybeSetWriteProtectCode(bool val); 178 179 bool eagerIonCompilation() const { return normalIonWarmUpThreshold == 0; } 180 }; 181 182 extern DefaultJitOptions JitOptions; 183 184 inline bool HasJitBackend() { 185 #if defined(JS_CODEGEN_NONE) 186 return false; 187 #else 188 return !JitOptions.disableJitBackend; 189 #endif 190 } 191 192 inline bool IsBaselineInterpreterEnabled() { 193 return HasJitBackend() && JitOptions.baselineInterpreter; 194 } 195 196 #ifdef ENABLE_PORTABLE_BASELINE_INTERP 197 inline bool IsPortableBaselineInterpreterEnabled() { 198 return JitOptions.portableBaselineInterpreter; 199 } 200 #else 201 inline bool IsPortableBaselineInterpreterEnabled() { return false; } 202 #endif 203 204 inline bool TooManyActualArguments(size_t nargs) { 205 return nargs > JitOptions.maxStackArgs; 206 } 207 208 } // namespace jit 209 210 extern mozilla::Atomic<bool> fuzzingSafe; 211 212 static inline bool IsFuzzing() { 213 #ifdef FUZZING 214 return true; 215 #else 216 return fuzzingSafe; 217 #endif 218 } 219 220 } // namespace js 221 222 #endif /* jit_JitOptions_h */