Commit ccf2e735 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[wasm][liftoff] Refactor CheckSupportedType for ref types

Switch from an array of supported types to a switch over
type kinds, in preparation for user-defined reference types.

Bug: v8:7748
Change-Id: I17a0a71184ee0937748f07f22c1fd545a057fb6e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2584950
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71733}
parent 43a5f208
...@@ -122,17 +122,6 @@ compiler::CallDescriptor* GetLoweredCallDescriptor( ...@@ -122,17 +122,6 @@ compiler::CallDescriptor* GetLoweredCallDescriptor(
: call_desc; : call_desc;
} }
constexpr ValueType kSupportedTypesArr[] = {
kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmS128, kWasmExternRef, kWasmFuncRef};
constexpr Vector<const ValueType> kSupportedTypes =
ArrayVector(kSupportedTypesArr);
constexpr ValueType kSupportedTypesWithoutRefsArr[] = {
kWasmI32, kWasmI64, kWasmF32, kWasmF64, kWasmS128};
constexpr Vector<const ValueType> kSupportedTypesWithoutRefs =
ArrayVector(kSupportedTypesWithoutRefsArr);
constexpr LiftoffCondition GetCompareCondition(WasmOpcode opcode) { constexpr LiftoffCondition GetCompareCondition(WasmOpcode opcode) {
switch (opcode) { switch (opcode) {
case kExprI32Eq: case kExprI32Eq:
...@@ -444,17 +433,27 @@ class LiftoffCompiler { ...@@ -444,17 +433,27 @@ class LiftoffCompiler {
} }
} }
bool CheckSupportedType(FullDecoder* decoder, bool CheckSupportedType(FullDecoder* decoder, ValueType type,
Vector<const ValueType> supported_types, const char* context) {
ValueType type, const char* context) { switch (type.kind()) {
// Special case for kWasm128 which requires specific hardware support. case ValueType::kI32:
if (type == kWasmS128 && (!CpuFeatures::SupportsWasmSimd128())) { case ValueType::kI64:
unsupported(decoder, kSimd, "simd"); case ValueType::kF32:
return false; case ValueType::kF64:
} return true;
// Check supported types. case ValueType::kS128:
for (ValueType supported : supported_types) { if (CpuFeatures::SupportsWasmSimd128()) return true;
if (type == supported) return true; break;
case ValueType::kRef:
case ValueType::kOptRef:
case ValueType::kRtt:
if (FLAG_experimental_liftoff_extern_ref) return true;
break;
case ValueType::kBottom:
case ValueType::kI8:
case ValueType::kI16:
case ValueType::kStmt:
UNREACHABLE();
} }
LiftoffBailoutReason bailout_reason = BailoutReasonForType(type); LiftoffBailoutReason bailout_reason = BailoutReasonForType(type);
EmbeddedVector<char, 128> buffer; EmbeddedVector<char, 128> buffer;
...@@ -587,12 +586,7 @@ class LiftoffCompiler { ...@@ -587,12 +586,7 @@ class LiftoffCompiler {
void StartFunctionBody(FullDecoder* decoder, Control* block) { void StartFunctionBody(FullDecoder* decoder, Control* block) {
for (uint32_t i = 0; i < __ num_locals(); ++i) { for (uint32_t i = 0; i < __ num_locals(); ++i) {
if (!CheckSupportedType(decoder, if (!CheckSupportedType(decoder, __ local_type(i), "param")) return;
FLAG_experimental_liftoff_extern_ref
? kSupportedTypes
: kSupportedTypesWithoutRefs,
__ local_type(i), "param"))
return;
} }
// Input 0 is the call target, the instance is at 1. // Input 0 is the call target, the instance is at 1.
...@@ -1880,11 +1874,7 @@ class LiftoffCompiler { ...@@ -1880,11 +1874,7 @@ class LiftoffCompiler {
void GlobalGet(FullDecoder* decoder, Value* result, void GlobalGet(FullDecoder* decoder, Value* result,
const GlobalIndexImmediate<validate>& imm) { const GlobalIndexImmediate<validate>& imm) {
const auto* global = &env_->module->globals[imm.index]; const auto* global = &env_->module->globals[imm.index];
if (!CheckSupportedType(decoder, if (!CheckSupportedType(decoder, global->type, "global")) {
FLAG_experimental_liftoff_extern_ref
? kSupportedTypes
: kSupportedTypesWithoutRefs,
global->type, "global")) {
return; return;
} }
...@@ -1919,11 +1909,7 @@ class LiftoffCompiler { ...@@ -1919,11 +1909,7 @@ class LiftoffCompiler {
void GlobalSet(FullDecoder* decoder, const Value& value, void GlobalSet(FullDecoder* decoder, const Value& value,
const GlobalIndexImmediate<validate>& imm) { const GlobalIndexImmediate<validate>& imm) {
auto* global = &env_->module->globals[imm.index]; auto* global = &env_->module->globals[imm.index];
if (!CheckSupportedType(decoder, if (!CheckSupportedType(decoder, global->type, "global")) {
FLAG_experimental_liftoff_extern_ref
? kSupportedTypes
: kSupportedTypesWithoutRefs,
global->type, "global")) {
return; return;
} }
...@@ -2397,8 +2383,7 @@ class LiftoffCompiler { ...@@ -2397,8 +2383,7 @@ class LiftoffCompiler {
const MemoryAccessImmediate<validate>& imm, const MemoryAccessImmediate<validate>& imm,
const Value& index_val, Value* result) { const Value& index_val, Value* result) {
ValueType value_type = type.value_type(); ValueType value_type = type.value_type();
if (!CheckSupportedType(decoder, kSupportedTypes, value_type, "load")) if (!CheckSupportedType(decoder, value_type, "load")) return;
return;
LiftoffRegList pinned; LiftoffRegList pinned;
Register index = pinned.set(__ PopToRegister()).gp(); Register index = pinned.set(__ PopToRegister()).gp();
if (BoundsCheckMem(decoder, type.size(), imm.offset, index, pinned, if (BoundsCheckMem(decoder, type.size(), imm.offset, index, pinned,
...@@ -2433,8 +2418,7 @@ class LiftoffCompiler { ...@@ -2433,8 +2418,7 @@ class LiftoffCompiler {
const Value& index_val, Value* result) { const Value& index_val, Value* result) {
// LoadTransform requires SIMD support, so check for it here. If // LoadTransform requires SIMD support, so check for it here. If
// unsupported, bailout and let TurboFan lower the code. // unsupported, bailout and let TurboFan lower the code.
if (!CheckSupportedType(decoder, kSupportedTypes, kWasmS128, if (!CheckSupportedType(decoder, kWasmS128, "LoadTransform")) {
"LoadTransform")) {
return; return;
} }
...@@ -2487,8 +2471,7 @@ class LiftoffCompiler { ...@@ -2487,8 +2471,7 @@ class LiftoffCompiler {
const MemoryAccessImmediate<validate>& imm, const MemoryAccessImmediate<validate>& imm,
const Value& index_val, const Value& value_val) { const Value& index_val, const Value& value_val) {
ValueType value_type = type.value_type(); ValueType value_type = type.value_type();
if (!CheckSupportedType(decoder, kSupportedTypes, value_type, "store")) if (!CheckSupportedType(decoder, value_type, "store")) return;
return;
LiftoffRegList pinned; LiftoffRegList pinned;
LiftoffRegister value = pinned.set(__ PopToRegister()); LiftoffRegister value = pinned.set(__ PopToRegister());
Register index = pinned.set(__ PopToRegister(pinned)).gp(); Register index = pinned.set(__ PopToRegister(pinned)).gp();
...@@ -3956,16 +3939,7 @@ class LiftoffCompiler { ...@@ -3956,16 +3939,7 @@ class LiftoffCompiler {
const CallFunctionImmediate<validate>& imm, const CallFunctionImmediate<validate>& imm,
const Value args[], Value returns[], CallKind call_kind) { const Value args[], Value returns[], CallKind call_kind) {
for (ValueType ret : imm.sig->returns()) { for (ValueType ret : imm.sig->returns()) {
if (!CheckSupportedType(decoder, if (!CheckSupportedType(decoder, ret, "return")) return;
FLAG_experimental_liftoff_extern_ref
? kSupportedTypes
: kSupportedTypesWithoutRefs,
ret, "return")) {
// TODO(7581): Remove this once reference-types are full supported.
if (!ret.is_reference_type()) {
return;
}
}
} }
auto call_descriptor = auto call_descriptor =
...@@ -4038,13 +4012,7 @@ class LiftoffCompiler { ...@@ -4038,13 +4012,7 @@ class LiftoffCompiler {
return unsupported(decoder, kRefTypes, "table index != 0"); return unsupported(decoder, kRefTypes, "table index != 0");
} }
for (ValueType ret : imm.sig->returns()) { for (ValueType ret : imm.sig->returns()) {
if (!CheckSupportedType(decoder, if (!CheckSupportedType(decoder, ret, "return")) return;
FLAG_experimental_liftoff_extern_ref
? kSupportedTypes
: kSupportedTypesWithoutRefs,
ret, "return")) {
return;
}
} }
// Pop the index. // Pop the index.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment