Skip to content

Commit

Permalink
Bug 1618595: Disable Cranelift on aarch64 when reftypes are enabled; …
Browse files Browse the repository at this point in the history
…r=lth,perftest-reviewers,sparky

This requires adding a new JSOptions field (for internal use within the shell),
as well as a new browser pref (to support possible Cranelift benchmarking on
aarch64).

Differential Revision: https://phabricator.services.mozilla.com/D72907
  • Loading branch information
bnjbvr committed Apr 30, 2020
1 parent f0e5de2 commit 5bd280d
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions dom/workers/RuntimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ void LoadContextOptions(const char* aPrefName, void* /* aClosure */) {
.setWasmBaseline(
GetWorkerPref<bool>(NS_LITERAL_CSTRING("wasm_baselinejit")))
.setWasmIon(GetWorkerPref<bool>(NS_LITERAL_CSTRING("wasm_ionjit")))
.setWasmReftypes(GetWorkerPref<bool>(NS_LITERAL_CSTRING("wasm_reftypes")))
#ifdef ENABLE_WASM_CRANELIFT
.setWasmCranelift(
GetWorkerPref<bool>(NS_LITERAL_CSTRING("wasm_cranelift")))
Expand Down
8 changes: 8 additions & 0 deletions js/public/ContextOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class JS_PUBLIC_API ContextOptions {
wasmBaseline_(true),
wasmIon_(true),
wasmCranelift_(false),
wasmReftypes_(true),
wasmGc_(false),
wasmMultiValue_(false),
testWasmAwaitTier2_(false),
Expand Down Expand Up @@ -107,6 +108,12 @@ class JS_PUBLIC_API ContextOptions {
}
#endif

bool wasmReftypes() const { return wasmReftypes_; }
ContextOptions& setWasmReftypes(bool flag) {
wasmReftypes_ = flag;
return *this;
}

bool wasmGc() const { return wasmGc_; }
// Defined out-of-line because it depends on a compile-time option
ContextOptions& setWasmGc(bool flag);
Expand Down Expand Up @@ -213,6 +220,7 @@ class JS_PUBLIC_API ContextOptions {
bool wasmBaseline_ : 1;
bool wasmIon_ : 1;
bool wasmCranelift_ : 1;
bool wasmReftypes_ : 1;
bool wasmGc_ : 1;
bool wasmMultiValue_ : 1;
bool testWasmAwaitTier2_ : 1;
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/TypedObject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled() || wasmCompileMode() != 'baseline'
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline'

// We can read the object fields from JS, and write them if they are mutable.

Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/anyref-boxing-struct.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled() || wasmCompileMode() != 'baseline'
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline'

// Moving a JS value through a wasm anyref is a pair of boxing/unboxing
// conversions that leaves the value unchanged. There are many cases,
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/anyref-refeq.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled()
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled()
//
// ref.eq is part of the gc feature, not the reftypes feature.

Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/disabled.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: wasmReftypesEnabled()
// |jit-test| skip-if: wasmReftypesEnabled() || wasmGcEnabled()

const { CompileError, validate } = WebAssembly;

Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/ion-and-baseline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled()
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled()

// Attempt to test intercalls from ion to baseline and back.
//
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/ref-global.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled() || wasmCompileMode() != 'baseline'
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline'

// Basic private-to-module functionality. At the moment all we have is null
// pointers, not very exciting.
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/ref-restrict.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled()
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled()

// For the time being, we do not want to expose struct types outside of the
// module where they are defined, and so there are restrictions on how functions
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/ref-struct.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled() || wasmCompileMode() != 'baseline'
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline'

// We'll be running some binary-format tests shortly.

Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/ref.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled()
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled()

// Parsing and resolving.

Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/regress-outline-repr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled() || wasmCompileMode() != 'baseline'
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline'

// White-box test for bug 1617908. The significance of this test is that the
// type $S is too large to fit in an inline TypedObject, and the write barrier
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit-test/tests/wasm/gc/structs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// |jit-test| skip-if: !wasmGcEnabled() || wasmCompileMode() != 'baseline'
// |jit-test| skip-if: !wasmReftypesEnabled() || !wasmGcEnabled() || wasmCompileMode() != 'baseline'

var conf = getBuildConfiguration();

Expand Down
5 changes: 5 additions & 0 deletions js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ bool shell::enableSharedMemory = SHARED_MEMORY_DEFAULT;
bool shell::enableWasmBaseline = false;
bool shell::enableWasmIon = false;
bool shell::enableWasmCranelift = false;
bool shell::enableWasmReftypes = true;
#ifdef ENABLE_WASM_GC
bool shell::enableWasmGc = false;
#endif
Expand Down Expand Up @@ -10492,6 +10493,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
}
}

enableWasmReftypes = !op.getBoolOption("no-wasm-reftypes");
#ifdef ENABLE_WASM_GC
enableWasmGc = op.getBoolOption("wasm-gc");
#endif
Expand Down Expand Up @@ -10520,6 +10522,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
.setWasmForTrustedPrinciples(enableWasm)
.setWasmBaseline(enableWasmBaseline)
.setWasmIon(enableWasmIon)
.setWasmReftypes(enableWasmReftypes)
#ifdef ENABLE_WASM_CRANELIFT
.setWasmCranelift(enableWasmCranelift)
#endif
Expand Down Expand Up @@ -11328,6 +11331,8 @@ int main(int argc, char** argv, char** envp) {
!op.addBoolOption('\0', "test-wasm-await-tier2",
"Forcibly activate tiering and block "
"instantiation on completion of tier2") ||
!op.addBoolOption('\0', "no-wasm-reftypes",
"Disable wasm reference types features") ||
#ifdef ENABLE_WASM_GC
!op.addBoolOption('\0', "wasm-gc",
"Enable experimental wasm GC features") ||
Expand Down
1 change: 1 addition & 0 deletions js/src/shell/jsshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extern bool enableSharedMemory;
extern bool enableWasmBaseline;
extern bool enableWasmIon;
extern bool enableWasmCranelift;
extern bool enableWasmReftypes;
#ifdef ENABLE_WASM_GC
extern bool enableWasmGc;
#endif
Expand Down
4 changes: 3 additions & 1 deletion js/src/wasm/WasmCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ SharedCompileArgs CompileArgs::build(JSContext* cx,
target->sharedMemoryEnabled =
cx->realm()->creationOptions().getSharedMemoryAndAtomicsEnabled();
target->forceTiering = forceTiering;
target->reftypesEnabled = wasm::ReftypesAvailable(cx);
target->gcEnabled = wasm::GcTypesAvailable(cx);
target->hugeMemory = wasm::IsHugeMemoryEnabled();
target->bigIntEnabled = wasm::I64BigIntConversionAvailable(cx);
Expand Down Expand Up @@ -452,6 +453,7 @@ void CompilerEnvironment::computeParameters(Decoder& d) {
return;
}

bool reftypesEnabled = args_->reftypesEnabled;
bool gcEnabled = args_->gcEnabled;
bool baselineEnabled = args_->baselineEnabled;
bool ionEnabled = args_->ionEnabled;
Expand Down Expand Up @@ -490,8 +492,8 @@ void CompilerEnvironment::computeParameters(Decoder& d) {
craneliftEnabled ? OptimizedBackend::Cranelift : OptimizedBackend::Ion;

debug_ = debugEnabled ? DebugEnabled::True : DebugEnabled::False;
refTypes_ = reftypesEnabled;
gcTypes_ = gcEnabled;
refTypes_ = true;
multiValues_ = multiValuesEnabled;
hugeMemory_ = hugeMemory;
bigInt_ = bigIntEnabled;
Expand Down
2 changes: 2 additions & 0 deletions js/src/wasm/WasmCompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct CompileArgs : ShareableBase<CompileArgs> {
bool debugEnabled;
bool sharedMemoryEnabled;
bool forceTiering;
bool reftypesEnabled;
bool gcEnabled;
bool hugeMemory;
bool bigIntEnabled;
Expand All @@ -81,6 +82,7 @@ struct CompileArgs : ShareableBase<CompileArgs> {
debugEnabled(false),
sharedMemoryEnabled(false),
forceTiering(false),
reftypesEnabled(false),
gcEnabled(false),
hugeMemory(false),
bigIntEnabled(false),
Expand Down
18 changes: 14 additions & 4 deletions js/src/wasm/WasmJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,19 @@ bool wasm::CraneliftAvailable(JSContext* cx) {
bool wasm::CraneliftDisabledByFeatures(JSContext* cx, bool* isDisabled,
JSStringBuilder* reason) {
// Cranelift has no debugging support, no gc support, no multi-value support,
// no threads.
// no threads, and on ARM64, no reference types.
bool debug = cx->realm() && cx->realm()->debuggerObservesAsmJS();
bool gc = cx->options().wasmGc();
bool multiValue = WasmMultiValueFlag(cx);
bool threads =
cx->realm() &&
cx->realm()->creationOptions().getSharedMemoryAndAtomicsEnabled();
#if defined(JS_CODEGEN_ARM64)
bool reftypesOnArm64 = cx->options().wasmReftypes();
#else
// On other platforms, assume reftypes has been implemented.
bool reftypesOnArm64 = false;
#endif
if (reason) {
char sep = 0;
if (debug && !Append(reason, "debug", &sep)) {
Expand All @@ -167,8 +173,11 @@ bool wasm::CraneliftDisabledByFeatures(JSContext* cx, bool* isDisabled,
if (threads && !Append(reason, "threads", &sep)) {
return false;
}
if (reftypesOnArm64 && !Append(reason, "reftypes", &sep)) {
return false;
}
}
*isDisabled = debug || gc || multiValue || threads;
*isDisabled = debug || gc || multiValue || threads || reftypesOnArm64;
return true;
}

Expand All @@ -181,9 +190,10 @@ bool wasm::CraneliftDisabledByFeatures(JSContext* cx, bool* isDisabled,
// ensure that only compilers that actually support the feature are used.

bool wasm::ReftypesAvailable(JSContext* cx) {
// All compilers support reference types.
// All compilers support reference types, except Cranelift on ARM64.
#ifdef ENABLE_WASM_REFTYPES
return true;
return cx->options().wasmReftypes() &&
(BaselineAvailable(cx) || IonAvailable(cx) || CraneliftAvailable(cx));
#else
return false;
#endif
Expand Down
3 changes: 3 additions & 0 deletions js/xpconnect/src/XPCJSContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
bool useWasmCranelift =
Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_cranelift");
#endif
bool useWasmReftypes =
Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_reftypes");
#ifdef ENABLE_WASM_GC
bool useWasmGc = Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_gc");
#endif
Expand Down Expand Up @@ -965,6 +967,7 @@ static void ReloadPrefsCallback(const char* pref, void* aXpccx) {
.setWasmForTrustedPrinciples(useWasmTrustedPrincipals)
.setWasmIon(useWasmIon)
.setWasmBaseline(useWasmBaseline)
.setWasmReftypes(useWasmReftypes)
#ifdef ENABLE_WASM_CRANELIFT
.setWasmCranelift(useWasmCranelift)
#endif
Expand Down
1 change: 1 addition & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ pref("javascript.options.wasm_trustedprincipals", true);
pref("javascript.options.wasm_verbose", false);
pref("javascript.options.wasm_ionjit", true);
pref("javascript.options.wasm_baselinejit", true);
pref("javascript.options.wasm_reftypes", true);
#ifdef ENABLE_WASM_CRANELIFT
pref("javascript.options.wasm_cranelift", false);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ preferences = {"javascript.options.wasm_baselinejit": false,
"javascript.options.wasm_ionjit": false,
"javascript.options.shared_memory": false,
"javascript.options.wasm_multi_value": false,
"javascript.options.wasm_reftypes": false,
"javascript.options.wasm_cranelift": true}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ preferences = {"javascript.options.wasm_baselinejit": false,
"javascript.options.wasm_ionjit": false,
"javascript.options.shared_memory": false,
"javascript.options.wasm_multi_value": false,
"javascript.options.wasm_reftypes": false,
"javascript.options.wasm_cranelift": true}

0 comments on commit 5bd280d

Please sign in to comment.