Bug 1186424: Take ModuleCompiler out of CheckFunction(); r=luke
☠☠ backed out by f8dd6bbde6ce ☠ ☠
authorBenjamin Bouvier <benj@benj.me>
Wed, 29 Jul 2015 14:33:17 +0200
changeset 292255 bdeb7135e5414be2b76b81bbc0c97b5a6231a3b8
parent 292254 e41895c02c0bd19b62add8b3e58a97ecaa17e028
child 292256 94c7d36f29ba70f22776a4cdeb71b770ce30e854
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1186424
milestone43.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 1186424: Take ModuleCompiler out of CheckFunction(); r=luke
js/src/asmjs/AsmJSValidate.cpp
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -10359,18 +10359,18 @@ EmitMIR(ModuleCompiler& m, const AsmFunc
 
     jit::SpewBeginFunction(mir, nullptr);
 
     f.checkPostconditions();
     return mir;
 }
 
 static bool
-CheckFunction(ModuleValidator& m, ModuleCompiler& mc, LifoAlloc& lifo,
-              MIRGenerator** mir, ModuleGlobals::Func** funcOut)
+CheckFunction(ModuleValidator& m, LifoAlloc& lifo, AsmFunction** asmFunc,
+              ModuleGlobals::Func** funcOut)
 {
     int64_t before = PRMJ_Now();
 
     // asm.js modules can be quite large when represented as parse trees so pop
     // the backing LifoAlloc after parsing/compiling each function.
     AsmJSParser::Mark mark = m.parser().mark();
 
     ParseNode* fn = nullptr;  // initialize to silence GCC warning
@@ -10380,23 +10380,23 @@ CheckFunction(ModuleValidator& m, Module
     if (!CheckFunctionHead(m, fn))
         return false;
 
     if (m.tryOnceToValidateChangeHeap()) {
         bool validated;
         if (!CheckChangeHeap(m, fn, &validated))
             return false;
         if (validated) {
-            *mir = nullptr;
+            *asmFunc = nullptr;
             return true;
         }
     }
 
-    AsmFunction function(m.cx());
-    FunctionBuilder f(m, function, fn);
+    *asmFunc = lifo.new_<AsmFunction>(m.cx());
+    FunctionBuilder f(m, **asmFunc, fn);
     if (!f.init())
         return false;
 
     ParseNode* stmtIter = ListHead(FunctionStatementList(fn));
 
     if (!CheckProcessingDirectives(m, &stmtIter))
         return false;
 
@@ -10426,23 +10426,32 @@ CheckFunction(ModuleValidator& m, Module
     if (func->defined())
         return m.failName(fn, "function '%s' already defined", FunctionName(fn));
 
     func->define(fn);
     func->accumulateCompileTime((PRMJ_Now() - before) / PRMJ_USEC_PER_MSEC);
 
     m.parser().release(mark);
 
-    function.setNumLocals(f.numLocals());
-
-    *mir = EmitMIR(mc, function, lifo, func->sig().args());
+    (*asmFunc)->setNumLocals(f.numLocals());
+    *funcOut = func;
+    return true;
+}
+
+static bool
+GenerateMIR(ModuleCompiler& mc, LifoAlloc& lifo, AsmFunction& bytecode, ModuleGlobals::Func* func,
+            MIRGenerator** mir)
+{
+    int64_t before = PRMJ_Now();
+
+    *mir = EmitMIR(mc, bytecode, lifo, func->sig().args());
     if (!*mir)
         return false;
 
-    *funcOut = func;
+    func->accumulateCompileTime((PRMJ_Now() - before) / PRMJ_USEC_PER_MSEC);
     return true;
 }
 
 static bool
 GenerateCode(ModuleCompiler& m, ModuleGlobals::Func& func, MIRGenerator& mir, LIRGraph& lir)
 {
     int64_t before = PRMJ_Now();
 
@@ -10496,25 +10505,29 @@ CheckFunctionsSequential(ModuleValidator
         TokenKind tk;
         if (!PeekToken(m.parser(), &tk))
             return false;
         if (tk != TOK_FUNCTION)
             break;
 
         LifoAllocScope scope(&lifo);
 
-        MIRGenerator* mir;
+        AsmFunction* asmFunc;
         ModuleGlobals::Func* func;
-        if (!CheckFunction(m, mc, lifo, &mir, &func))
-            return false;
-
-        // In the case of the change-heap function, no MIR is produced.
-        if (!mir)
+        if (!CheckFunction(m, lifo, &asmFunc, &func))
+            return false;
+
+        // In the case of the change-heap function, no bytecode is produced.
+        if (!asmFunc)
             continue;
 
+        MIRGenerator* mir;
+        if (!GenerateMIR(mc, lifo, *asmFunc, func, &mir))
+            return false;
+
         int64_t before = PRMJ_Now();
 
         JitContext jcx(m.cx(), &mir->alloc());
         jit::AutoSpewEndFunction spewEndFunction(mir);
 
         if (!OptimizeMIR(mir))
             return m.failOffset(func->srcBegin(), "internal compiler failure (probably out of memory)");
 
@@ -10662,25 +10675,29 @@ CheckFunctionsParallel(ModuleValidator& 
         if (!PeekToken(m.parser(), &tk))
             return false;
         if (tk != TOK_FUNCTION)
             break;
 
         if (!task && !GetUnusedTask(group, i, &task) && !GetUsedTask(mc, group, &task))
             return false;
 
+        AsmFunction* asmFunc;
+        ModuleGlobals::Func* func;
+        if (!CheckFunction(m, task->lifo, &asmFunc, &func))
+            return false;
+
+        // In the case of the change-heap function, no bytecode is produced.
+        if (!asmFunc)
+            continue;
+
         // Generate MIR into the LifoAlloc on the main thread.
         MIRGenerator* mir;
-        ModuleGlobals::Func* func;
-        if (!CheckFunction(m, mc, task->lifo, &mir, &func))
-            return false;
-
-        // In the case of the change-heap function, no MIR is produced.
-        if (!mir)
-            continue;
+        if (!GenerateMIR(mc, task->lifo, *asmFunc, func, &mir))
+            return false;
 
         // Perform optimizations and LIR generation on a helper thread.
         task->init(m.cx()->compartment()->runtimeFromAnyThread(), func, mir);
         if (!StartOffThreadAsmJSCompile(m.cx(), task))
             return false;
 
         group.outstandingJobs++;
         task = nullptr;
@@ -12104,17 +12121,17 @@ CheckModule(ExclusiveContext* cx, AsmJSP
     if (!CheckModuleProcessingDirectives(mv))
         return false;
 
     if (!CheckModuleGlobals(mv))
         return false;
 
 #if !defined(ENABLE_SHARED_ARRAY_BUFFER)
     if (mv.module().hasArrayView() && mv.module().isSharedView())
-        return mc.fail(nullptr, "shared views not supported by this build");
+        return mv.fail(nullptr, "shared views not supported by this build");
 #endif
 
     ModuleCompiler mc(cx, parser, mv.modulePtr(), mg);
     if (!mc.init())
         return false;
 
     mc.startFunctionBodies();