Bug 1229338: Make OptimizationLevel an enum class; r=Waldo
authorBenjamin Bouvier <benj@benj.me>
Thu, 03 Dec 2015 21:03:14 +0100
changeset 277207 eb630918efd679213e76bf56bb77f53761305c9c
parent 277206 86a078b9824364ef033746bbf208ecde4f8aaea0
child 277208 3a5ae2ad1b3d112ae79c5909f4f17cfee47e1153
push id29819
push usercbook@mozilla.com
push dateTue, 22 Dec 2015 10:47:17 +0000
treeherdermozilla-central@ad16863d1d45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1229338
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1229338: Make OptimizationLevel an enum class; r=Waldo
js/src/asmjs/WasmIonCompile.cpp
js/src/jit/Ion.cpp
js/src/jit/IonAnalysis.cpp
js/src/jit/IonOptimizationLevels.cpp
js/src/jit/IonOptimizationLevels.h
--- a/js/src/asmjs/WasmIonCompile.cpp
+++ b/js/src/asmjs/WasmIonCompile.cpp
@@ -2941,17 +2941,17 @@ wasm::CompileFunction(CompileTask* task)
     FunctionCompileResults& results = task->results();
 
     JitContext jitContext(CompileRuntime::get(args.runtime), &results.alloc());
 
     const JitCompileOptions options;
     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
     {
         FunctionCompiler f(args, func, mir, results);
         if (!f.init())
             return false;
 
--- a/js/src/jit/Ion.cpp
+++ b/js/src/jit/Ion.cpp
@@ -2103,17 +2103,17 @@ IonCompile(JSContext* cx, JSScript* scri
            BaselineFrame* baselineFrame, jsbytecode* osrPc, bool constructing,
            bool recompile, OptimizationLevel optimizationLevel)
 {
     TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime());
     TraceLoggerEvent event(logger, TraceLogger_AnnotateScripts, 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.
     script->ensureNonLazyCanonicalFunction(cx);
 
     TrackPropertiesForSingletonScopes(cx, script, baselineFrame);
 
     LifoAlloc* alloc = cx->new_<LifoAlloc>(TempAllocator::PreferredLifoChunkSize);
@@ -2391,17 +2391,17 @@ Compile(JSContext* cx, HandleScript scri
     MethodStatus status = CheckScriptSize(cx, script);
     if (status != Method_Compiled) {
         JitSpew(JitSpew_IonAbort, "Aborted compilation of %s:%" PRIuSIZE, script->filename(), script->lineno());
         return status;
     }
 
     bool recompile = false;
     OptimizationLevel optimizationLevel = GetOptimizationLevel(script, osrPc);
-    if (optimizationLevel == Optimization_DontCompile)
+    if (optimizationLevel == OptimizationLevel::DontCompile)
         return Method_Skipped;
 
     if (script->hasIonScript()) {
         IonScript* scriptIon = script->ionScript();
         if (!scriptIon->method())
             return Method_CantCompile;
 
         // Don't recompile/overwrite higher optimized code,
--- a/js/src/jit/IonAnalysis.cpp
+++ b/js/src/jit/IonAnalysis.cpp
@@ -3678,17 +3678,17 @@ jit::AnalyzeNewScriptDefiniteProperties(
         return false;
 
     CompileInfo info(script, fun,
                      /* osrPc = */ nullptr, /* constructing = */ false,
                      Analysis_DefiniteProperties,
                      script->needsArgsObj(),
                      inlineScriptTree);
 
-    const OptimizationInfo* optimizationInfo = IonOptimizations.get(Optimization_Normal);
+    const OptimizationInfo* optimizationInfo = IonOptimizations.get(OptimizationLevel::Normal);
 
     CompilerConstraintList* constraints = NewCompilerConstraintList(temp);
     if (!constraints) {
         ReportOutOfMemory(cx);
         return false;
     }
 
     BaselineInspector inspector(script);
@@ -3899,17 +3899,17 @@ jit::AnalyzeArgumentsUsage(JSContext* cx
     }
 
     CompileInfo info(script, script->functionNonDelazifying(),
                      /* osrPc = */ nullptr, /* constructing = */ false,
                      Analysis_ArgumentsUsage,
                      /* needsArgsObj = */ true,
                      inlineScriptTree);
 
-    const OptimizationInfo* optimizationInfo = IonOptimizations.get(Optimization_Normal);
+    const OptimizationInfo* optimizationInfo = IonOptimizations.get(OptimizationLevel::Normal);
 
     CompilerConstraintList* constraints = NewCompilerConstraintList(temp);
     if (!constraints) {
         ReportOutOfMemory(cx);
         return false;
     }
 
     BaselineInspector inspector(script);
--- a/js/src/jit/IonOptimizationLevels.cpp
+++ b/js/src/jit/IonOptimizationLevels.cpp
@@ -16,17 +16,17 @@ using namespace js::jit;
 namespace js {
 namespace jit {
 
 OptimizationInfos IonOptimizations;
 
 void
 OptimizationInfo::initNormalOptimizationInfo()
 {
-    level_ = Optimization_Normal;
+    level_ = OptimizationLevel::Normal;
 
     eaa_ = true;
     edgeCaseAnalysis_ = true;
     eliminateRedundantChecks_ = true;
     inlineInterpreted_ = true;
     inlineNative_ = true;
     eagerSimdUnbox_ = true;
     gvn_ = true;
@@ -57,17 +57,17 @@ OptimizationInfo::initAsmjsOptimizationI
 {
     // The AsmJS optimization level
     // Disables some passes that don't work well with asmjs.
 
     // Take normal option values for not specified values.
     initNormalOptimizationInfo();
 
     ama_ = true;
-    level_ = Optimization_AsmJS;
+    level_ = OptimizationLevel::AsmJS;
     eagerSimdUnbox_ = false;           // AsmJS has no boxing / unboxing.
     edgeCaseAnalysis_ = false;
     eliminateRedundantChecks_ = false;
     autoTruncate_ = false;
     sincos_ = false;
     sink_ = false;
     registerAllocator_ = RegisterAllocator_Backtracking;
     scalarReplacement_ = false;        // AsmJS has no objects.
@@ -105,57 +105,59 @@ OptimizationInfo::compilerWarmUpThreshol
     // Note that the loop depth is always > 0 so we will prefer non-OSR over OSR.
     uint32_t loopDepth = LoopEntryDepthHint(pc);
     MOZ_ASSERT(loopDepth > 0);
     return warmUpThreshold + loopDepth * 100;
 }
 
 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
 }
 
 OptimizationLevel
 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);
         const OptimizationInfo* info = get(level);
         if (script->getWarmUpCount() < info->compilerWarmUpThreshold(script, pc))
             return prev;
 
         prev = level;
--- a/js/src/jit/IonOptimizationLevels.h
+++ b/js/src/jit/IonOptimizationLevels.h
@@ -2,47 +2,49 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef jit_IonOptimizationLevels_h
 #define jit_IonOptimizationLevels_h
 
+#include "mozilla/EnumeratedArray.h"
+
 #include "jsbytecode.h"
 #include "jstypes.h"
 
 #include "jit/JitOptions.h"
 #include "js/TypeDecls.h"
 
 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
 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
 
 class OptimizationInfo
 {
   public:
     OptimizationLevel level_;
 
@@ -261,26 +263,23 @@ class OptimizationInfo
     uint32_t inliningRecompileThreshold() const {
         return inliningWarmUpThreshold() * inliningRecompileThresholdFactor_;
     }
 };
 
 class OptimizationInfos
 {
   private:
-    OptimizationInfo infos_[Optimization_Count - 1];
+    mozilla::EnumeratedArray<OptimizationLevel, OptimizationLevel::Count, OptimizationInfo> 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;
     OptimizationLevel firstLevel() const;
     bool isLastLevel(OptimizationLevel level) const;
     OptimizationLevel levelForScript(JSScript* script, jsbytecode* pc = nullptr) const;
 };