From d6727ad6fbb02f2ba94f9d457ba64e4ffacccd8f Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 3 Dec 2015 21:03:14 +0100 Subject: [PATCH] Bug 1229338: Make OptimizationLevel an enum class; r=Waldo --HG-- extra : rebase_source : 2c4d48233965cbf0d65fccffd2d8497acc5f44cf extra : histedit_source : 323d28acc01c987b6495232fb8bc1d276f1233fe --- js/src/asmjs/WasmIonCompile.cpp | 2 +- js/src/jit/Ion.cpp | 4 ++-- js/src/jit/IonAnalysis.cpp | 4 ++-- js/src/jit/IonOptimizationLevels.cpp | 26 +++++++++++++------------ js/src/jit/IonOptimizationLevels.h | 29 ++++++++++++++-------------- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/js/src/asmjs/WasmIonCompile.cpp b/js/src/asmjs/WasmIonCompile.cpp index 25be1f4da6ee..daa239ad0bb0 100644 --- a/js/src/asmjs/WasmIonCompile.cpp +++ b/js/src/asmjs/WasmIonCompile.cpp @@ -2946,7 +2946,7 @@ wasm::CompileFunction(CompileTask* task) MIRGraph graph(&results.alloc()); CompileInfo compileInfo(func.numLocals()); MIRGenerator mir(nullptr, options, &results.alloc(), &graph, &compileInfo, - IonOptimizations.get(Optimization_AsmJS), + IonOptimizations.get(OptimizationLevel::AsmJS), args.usesSignalHandlersForOOB); // Build MIR graph diff --git a/js/src/jit/Ion.cpp b/js/src/jit/Ion.cpp index d42be8e7bfe5..7371c715c8e4 100644 --- a/js/src/jit/Ion.cpp +++ b/js/src/jit/Ion.cpp @@ -2108,7 +2108,7 @@ IonCompile(JSContext* cx, JSScript* script, AutoTraceLog logScript(logger, event); AutoTraceLog logCompile(logger, TraceLogger_IonCompilation); - MOZ_ASSERT(optimizationLevel > Optimization_DontCompile); + MOZ_ASSERT(optimizationLevel != OptimizationLevel::DontCompile); // Make sure the script's canonical function isn't lazy. We can't de-lazify // it in a helper thread. @@ -2396,7 +2396,7 @@ Compile(JSContext* cx, HandleScript script, BaselineFrame* osrFrame, jsbytecode* bool recompile = false; OptimizationLevel optimizationLevel = GetOptimizationLevel(script, osrPc); - if (optimizationLevel == Optimization_DontCompile) + if (optimizationLevel == OptimizationLevel::DontCompile) return Method_Skipped; if (script->hasIonScript()) { diff --git a/js/src/jit/IonAnalysis.cpp b/js/src/jit/IonAnalysis.cpp index eb709c6502aa..013f07c74696 100644 --- a/js/src/jit/IonAnalysis.cpp +++ b/js/src/jit/IonAnalysis.cpp @@ -3683,7 +3683,7 @@ jit::AnalyzeNewScriptDefiniteProperties(JSContext* cx, JSFunction* fun, script->needsArgsObj(), inlineScriptTree); - const OptimizationInfo* optimizationInfo = IonOptimizations.get(Optimization_Normal); + const OptimizationInfo* optimizationInfo = IonOptimizations.get(OptimizationLevel::Normal); CompilerConstraintList* constraints = NewCompilerConstraintList(temp); if (!constraints) { @@ -3904,7 +3904,7 @@ jit::AnalyzeArgumentsUsage(JSContext* cx, JSScript* scriptArg) /* needsArgsObj = */ true, inlineScriptTree); - const OptimizationInfo* optimizationInfo = IonOptimizations.get(Optimization_Normal); + const OptimizationInfo* optimizationInfo = IonOptimizations.get(OptimizationLevel::Normal); CompilerConstraintList* constraints = NewCompilerConstraintList(temp); if (!constraints) { diff --git a/js/src/jit/IonOptimizationLevels.cpp b/js/src/jit/IonOptimizationLevels.cpp index 5143c1411a51..bdb9b260832e 100644 --- a/js/src/jit/IonOptimizationLevels.cpp +++ b/js/src/jit/IonOptimizationLevels.cpp @@ -21,7 +21,7 @@ OptimizationInfos IonOptimizations; void OptimizationInfo::initNormalOptimizationInfo() { - level_ = Optimization_Normal; + level_ = OptimizationLevel::Normal; eaa_ = true; edgeCaseAnalysis_ = true; @@ -62,7 +62,7 @@ OptimizationInfo::initAsmjsOptimizationInfo() initNormalOptimizationInfo(); ama_ = true; - level_ = Optimization_AsmJS; + level_ = OptimizationLevel::AsmJS; eagerSimdUnbox_ = false; // AsmJS has no boxing / unboxing. edgeCaseAnalysis_ = false; eliminateRedundantChecks_ = false; @@ -110,14 +110,14 @@ OptimizationInfo::compilerWarmUpThreshold(JSScript* script, jsbytecode* pc) cons OptimizationInfos::OptimizationInfos() { - infos_[Optimization_Normal - 1].initNormalOptimizationInfo(); - infos_[Optimization_AsmJS - 1].initAsmjsOptimizationInfo(); + infos_[OptimizationLevel::Normal].initNormalOptimizationInfo(); + infos_[OptimizationLevel::AsmJS].initAsmjsOptimizationInfo(); #ifdef DEBUG OptimizationLevel level = firstLevel(); while (!isLastLevel(level)) { OptimizationLevel next = nextLevel(level); - MOZ_ASSERT(level < next); + MOZ_ASSERT_IF(level != OptimizationLevel::DontCompile, level < next); level = next; } #endif @@ -128,29 +128,31 @@ OptimizationInfos::nextLevel(OptimizationLevel level) const { MOZ_ASSERT(!isLastLevel(level)); switch (level) { - case Optimization_DontCompile: - return Optimization_Normal; - default: - MOZ_CRASH("Unknown optimization level."); + case OptimizationLevel::DontCompile: + return OptimizationLevel::Normal; + case OptimizationLevel::Normal: + case OptimizationLevel::AsmJS: + case OptimizationLevel::Count:; } + MOZ_CRASH("Unknown optimization level."); } OptimizationLevel OptimizationInfos::firstLevel() const { - return nextLevel(Optimization_DontCompile); + return nextLevel(OptimizationLevel::DontCompile); } bool OptimizationInfos::isLastLevel(OptimizationLevel level) const { - return level == Optimization_Normal; + return level == OptimizationLevel::Normal; } OptimizationLevel OptimizationInfos::levelForScript(JSScript* script, jsbytecode* pc) const { - OptimizationLevel prev = Optimization_DontCompile; + OptimizationLevel prev = OptimizationLevel::DontCompile; while (!isLastLevel(prev)) { OptimizationLevel level = nextLevel(prev); diff --git a/js/src/jit/IonOptimizationLevels.h b/js/src/jit/IonOptimizationLevels.h index 0ca81822a912..7a01cb724639 100644 --- a/js/src/jit/IonOptimizationLevels.h +++ b/js/src/jit/IonOptimizationLevels.h @@ -7,6 +7,8 @@ #ifndef jit_IonOptimizationLevels_h #define jit_IonOptimizationLevels_h +#include "mozilla/EnumeratedArray.h" + #include "jsbytecode.h" #include "jstypes.h" @@ -16,12 +18,12 @@ namespace js { namespace jit { -enum OptimizationLevel +enum class OptimizationLevel : uint8_t { - Optimization_DontCompile, - Optimization_Normal, - Optimization_AsmJS, - Optimization_Count + Normal, + AsmJS, + Count, + DontCompile }; #ifdef JS_JITSPEW @@ -29,15 +31,15 @@ inline const char* OptimizationLevelString(OptimizationLevel level) { switch (level) { - case Optimization_DontCompile: + case OptimizationLevel::DontCompile: return "Optimization_DontCompile"; - case Optimization_Normal: + case OptimizationLevel::Normal: return "Optimization_Normal"; - case Optimization_AsmJS: + case OptimizationLevel::AsmJS: return "Optimization_AsmJS"; - default: - MOZ_CRASH("Invalid OptimizationLevel"); + case OptimizationLevel::Count:; } + MOZ_CRASH("Invalid OptimizationLevel"); } #endif @@ -266,16 +268,13 @@ class OptimizationInfo class OptimizationInfos { private: - OptimizationInfo infos_[Optimization_Count - 1]; + mozilla::EnumeratedArray infos_; public: OptimizationInfos(); const OptimizationInfo* get(OptimizationLevel level) const { - MOZ_ASSERT(level < Optimization_Count); - MOZ_ASSERT(level != Optimization_DontCompile); - - return &infos_[level - 1]; + return &infos_[level]; } OptimizationLevel nextLevel(OptimizationLevel level) const;