From 15bd606c5a2e7b97b81820f2559fcf3891d04f39 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 3 Feb 2016 18:43:38 +0100 Subject: [PATCH] Bug 1242342: Set return type accordingly to the compilation mode; r=luke --- js/src/asmjs/WasmBinary.h | 8 ++++++-- js/src/asmjs/WasmGenerator.cpp | 3 ++- js/src/asmjs/WasmIonCompile.cpp | 16 ++++++++++++---- js/src/asmjs/WasmModule.h | 8 -------- js/src/asmjs/WasmTypes.h | 8 ++++++++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/js/src/asmjs/WasmBinary.h b/js/src/asmjs/WasmBinary.h index 3e520d28d68..97ab6805dfe 100644 --- a/js/src/asmjs/WasmBinary.h +++ b/js/src/asmjs/WasmBinary.h @@ -724,6 +724,7 @@ typedef Vector Uint32Vector; class FuncBytecode { // Function metadata + ModuleKind kind_; const DeclaredSig& sig_; ValTypeVector locals_; uint32_t lineOrBytecode_; @@ -742,8 +743,10 @@ class FuncBytecode ValTypeVector&& locals, uint32_t lineOrBytecode, Uint32Vector&& callSiteLineNums, - unsigned generateTime) - : sig_(sig), + unsigned generateTime, + ModuleKind kind) + : kind_(kind), + sig_(sig), locals_(Move(locals)), lineOrBytecode_(lineOrBytecode), callSiteLineNums_(Move(callSiteLineNums)), @@ -764,6 +767,7 @@ class FuncBytecode ValType localType(size_t i) const { return locals_[i]; } unsigned generateTime() const { return generateTime_; } + bool isAsmJS() const { return kind_ == ModuleKind::AsmJS; } }; typedef UniquePtr UniqueFuncBytecode; diff --git a/js/src/asmjs/WasmGenerator.cpp b/js/src/asmjs/WasmGenerator.cpp index 1c9e623cec1..9f2a24cfdb8 100644 --- a/js/src/asmjs/WasmGenerator.cpp +++ b/js/src/asmjs/WasmGenerator.cpp @@ -488,7 +488,8 @@ ModuleGenerator::finishFuncDef(uint32_t funcIndex, unsigned generateTime, Functi Move(fg->locals_), fg->lineOrBytecode_, Move(fg->callSiteLineNums_), - generateTime); + generateTime, + module_->kind); if (!func) return false; diff --git a/js/src/asmjs/WasmIonCompile.cpp b/js/src/asmjs/WasmIonCompile.cpp index b7ef6dbc0de..142ea7b0aee 100644 --- a/js/src/asmjs/WasmIonCompile.cpp +++ b/js/src/asmjs/WasmIonCompile.cpp @@ -2579,7 +2579,7 @@ EmitRet(FunctionCompiler& f) return true; } - MDefinition *def = nullptr; + MDefinition* def; if (!EmitExpr(f, ret, &def)) return false; f.returnExpr(def); @@ -2992,12 +2992,20 @@ wasm::IonCompileFunction(IonCompileTask* task) return false; MDefinition* last = nullptr; - while (!f.done()) { - if (!EmitExprStmt(f, &last)) + if (func.isAsmJS()) { + while (!f.done()) { + if (!EmitExprStmt(f, &last)) + return false; + } + } else { + if (!EmitExpr(f, f.sig().ret(), &last)) return false; + MOZ_ASSERT(f.done()); } - if (IsVoid(f.sig().ret()) || !last) + MOZ_ASSERT(IsVoid(f.sig().ret()) || f.inDeadCode() || last); + + if (IsVoid(f.sig().ret())) f.returnVoid(); else f.returnExpr(last); diff --git a/js/src/asmjs/WasmModule.h b/js/src/asmjs/WasmModule.h index 9352ab66f8f..e0b94c449eb 100644 --- a/js/src/asmjs/WasmModule.h +++ b/js/src/asmjs/WasmModule.h @@ -348,14 +348,6 @@ UsesHeap(HeapUsage heapUsage) return bool(heapUsage); } -// A Module can either be asm.js or wasm. - -enum ModuleKind -{ - Wasm, - AsmJS -}; - // ModuleCacheablePod holds the trivially-memcpy()able serializable portion of // ModuleData. diff --git a/js/src/asmjs/WasmTypes.h b/js/src/asmjs/WasmTypes.h index eb7ab61c1f9..02da9bca576 100644 --- a/js/src/asmjs/WasmTypes.h +++ b/js/src/asmjs/WasmTypes.h @@ -41,6 +41,14 @@ using mozilla::Move; using mozilla::DebugOnly; using mozilla::MallocSizeOf; +// A Module can either be asm.js or wasm. + +enum ModuleKind +{ + Wasm, + AsmJS +}; + // The ValType enum represents the WebAssembly "value type", which are used to // specify the type of locals and parameters.