Skip to content

Commit b83c5a0

Browse files
backesCommit Bot
authored andcommitted
[wasm] Refactor WasmFeatures
Make WasmFeatures a proper class which uses an EnumSet under the hood. This way, it inherits all behaviour of EnumSet like comparison, merge, etc. Accesses change from being simple field access into the struct to actually bit tests in the EnumSet. R=mstarzinger@chromium.org Bug: v8:10019 Change-Id: I768f92b90ac0294156f4482defba5ce00bc70165 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1934334 Commit-Queue: Clemens Backes <clemensb@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#65184}
1 parent dcb828b commit b83c5a0

45 files changed

Lines changed: 284 additions & 277 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api/api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7247,7 +7247,7 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::Compile(Isolate* isolate,
72477247
i::MaybeHandle<i::JSObject> maybe_compiled;
72487248
{
72497249
i::wasm::ErrorThrower thrower(i_isolate, "WasmModuleObject::Compile()");
7250-
auto enabled_features = i::wasm::WasmFeaturesFromIsolate(i_isolate);
7250+
auto enabled_features = i::wasm::WasmFeatures::FromIsolate(i_isolate);
72517251
maybe_compiled = i_isolate->wasm_engine()->SyncCompile(
72527252
i_isolate, enabled_features, &thrower,
72537253
i::wasm::ModuleWireBytes(start, start + length));

src/base/enum-set.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ class EnumSet {
2121
public:
2222
constexpr EnumSet() = default;
2323

24-
EnumSet(std::initializer_list<E> init) {
25-
for (E e : init) Add(e);
24+
explicit constexpr EnumSet(std::initializer_list<E> init) {
25+
T bits = 0;
26+
for (E e : init) bits |= Mask(e);
27+
bits_ = bits;
2628
}
2729

2830
bool empty() const { return bits_ == 0; }

src/compiler/wasm-compiler.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,7 +5485,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
54855485
case wasm::kWasmS128:
54865486
UNREACHABLE();
54875487
case wasm::kWasmI64: {
5488-
DCHECK(enabled_features_.bigint);
5488+
DCHECK(enabled_features_.has_bigint());
54895489
return BuildChangeInt64ToBigInt(node);
54905490
}
54915491
case wasm::kWasmF32:
@@ -5590,7 +5590,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
55905590
break;
55915591
}
55925592
case wasm::kWasmI64: {
5593-
DCHECK(enabled_features_.bigint);
5593+
DCHECK(enabled_features_.has_bigint());
55945594
num = BuildChangeBigIntToInt64(node, js_context);
55955595
break;
55965596
}
@@ -6600,7 +6600,7 @@ wasm::WasmCompilationResult CompileWasmMathIntrinsic(
66006600
wasm::CompilationEnv env(
66016601
nullptr, wasm::UseTrapHandler::kNoTrapHandler,
66026602
wasm::RuntimeExceptionSupport::kNoRuntimeExceptionSupport,
6603-
wasm::kAllWasmFeatures, wasm::LowerSimd::kNoLowerSimd);
6603+
wasm::WasmFeatures::All(), wasm::LowerSimd::kNoLowerSimd);
66046604

66056605
WasmGraphBuilder builder(&env, mcgraph->zone(), mcgraph, sig,
66066606
source_positions);
@@ -6816,7 +6816,7 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate,
68166816

68176817
WasmWrapperGraphBuilder builder(zone.get(), &mcgraph, sig, nullptr,
68186818
StubCallMode::kCallBuiltinPointer,
6819-
wasm::WasmFeaturesFromIsolate(isolate));
6819+
wasm::WasmFeatures::FromIsolate(isolate));
68206820
builder.set_control_ptr(&control);
68216821
builder.set_effect_ptr(&effect);
68226822
builder.BuildJSToJSWrapper(isolate);
@@ -6863,7 +6863,7 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
68636863

68646864
WasmWrapperGraphBuilder builder(zone.get(), &mcgraph, sig, nullptr,
68656865
StubCallMode::kCallBuiltinPointer,
6866-
wasm::WasmFeaturesFromIsolate(isolate));
6866+
wasm::WasmFeatures::FromIsolate(isolate));
68676867
builder.set_control_ptr(&control);
68686868
builder.set_effect_ptr(&effect);
68696869
builder.BuildCWasmEntry();

src/compiler/wasm-compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct DecodeStruct;
4343
using TFNode = compiler::Node;
4444
using TFGraph = compiler::MachineGraph;
4545
class WasmCode;
46-
struct WasmFeatures;
46+
class WasmFeatures;
4747
enum class LoadTransformationKind : uint8_t;
4848
} // namespace wasm
4949

src/objects/value-serializer.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,17 @@ Maybe<bool> ValueSerializer::WriteJSReceiver(Handle<JSReceiver> receiver) {
567567
case JS_ERROR_TYPE:
568568
return WriteJSError(Handle<JSObject>::cast(receiver));
569569
case WASM_MODULE_OBJECT_TYPE: {
570-
auto enabled_features = wasm::WasmFeaturesFromIsolate(isolate_);
571-
if (!FLAG_wasm_disable_structured_cloning || enabled_features.threads) {
570+
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
571+
if (!FLAG_wasm_disable_structured_cloning ||
572+
enabled_features.has_threads()) {
572573
// Only write WebAssembly modules if not disabled by a flag.
573574
return WriteWasmModule(Handle<WasmModuleObject>::cast(receiver));
574575
}
575576
break;
576577
}
577578
case WASM_MEMORY_OBJECT_TYPE: {
578-
auto enabled_features = wasm::WasmFeaturesFromIsolate(isolate_);
579-
if (enabled_features.threads) {
579+
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
580+
if (enabled_features.has_threads()) {
580581
return WriteWasmMemory(Handle<WasmMemoryObject>::cast(receiver));
581582
}
582583
break;
@@ -1939,8 +1940,9 @@ MaybeHandle<Object> ValueDeserializer::ReadJSError() {
19391940
}
19401941

19411942
MaybeHandle<JSObject> ValueDeserializer::ReadWasmModuleTransfer() {
1942-
auto enabled_features = wasm::WasmFeaturesFromIsolate(isolate_);
1943-
if ((FLAG_wasm_disable_structured_cloning && !enabled_features.threads) ||
1943+
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
1944+
if ((FLAG_wasm_disable_structured_cloning &&
1945+
!enabled_features.has_threads()) ||
19441946
expect_inline_wasm()) {
19451947
return MaybeHandle<JSObject>();
19461948
}
@@ -1963,8 +1965,9 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModuleTransfer() {
19631965
}
19641966

19651967
MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() {
1966-
auto enabled_features = wasm::WasmFeaturesFromIsolate(isolate_);
1967-
if ((FLAG_wasm_disable_structured_cloning && !enabled_features.threads) ||
1968+
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
1969+
if ((FLAG_wasm_disable_structured_cloning &&
1970+
!enabled_features.has_threads()) ||
19681971
!expect_inline_wasm()) {
19691972
return MaybeHandle<JSObject>();
19701973
}
@@ -1999,7 +2002,7 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() {
19992002
if (result.is_null()) {
20002003
wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule");
20012004
// TODO(titzer): are the current features appropriate for deserializing?
2002-
auto enabled_features = wasm::WasmFeaturesFromIsolate(isolate_);
2005+
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
20032006
result = isolate_->wasm_engine()->SyncCompile(
20042007
isolate_, enabled_features, &thrower,
20052008
wasm::ModuleWireBytes(wire_bytes));
@@ -2014,8 +2017,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() {
20142017
MaybeHandle<WasmMemoryObject> ValueDeserializer::ReadWasmMemory() {
20152018
uint32_t id = next_id_++;
20162019

2017-
auto enabled_features = wasm::WasmFeaturesFromIsolate(isolate_);
2018-
if (!enabled_features.threads) {
2020+
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
2021+
if (!enabled_features.has_threads()) {
20192022
return MaybeHandle<WasmMemoryObject>();
20202023
}
20212024

src/wasm/baseline/liftoff-compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace wasm {
1717

1818
struct CompilationEnv;
1919
struct FunctionBody;
20-
struct WasmFeatures;
20+
class WasmFeatures;
2121

2222
// Note: If this list changes, also the histogram "V8.LiftoffBailoutReasons"
2323
// on the chromium side needs to be updated.

src/wasm/c-api.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ auto Module::validate(Store* store_abs, const vec<byte_t>& binary) -> bool {
970970
i::wasm::ModuleWireBytes bytes(
971971
{reinterpret_cast<const uint8_t*>(binary.get()), binary.size()});
972972
i::Isolate* isolate = impl(store_abs)->i_isolate();
973-
i::wasm::WasmFeatures features = i::wasm::WasmFeaturesFromIsolate(isolate);
973+
i::wasm::WasmFeatures features = i::wasm::WasmFeatures::FromIsolate(isolate);
974974
return isolate->wasm_engine()->SyncValidate(isolate, features, bytes);
975975
}
976976

@@ -980,7 +980,7 @@ auto Module::make(Store* store_abs, const vec<byte_t>& binary) -> own<Module> {
980980
i::HandleScope scope(isolate);
981981
i::wasm::ModuleWireBytes bytes(
982982
{reinterpret_cast<const uint8_t*>(binary.get()), binary.size()});
983-
i::wasm::WasmFeatures features = i::wasm::WasmFeaturesFromIsolate(isolate);
983+
i::wasm::WasmFeatures features = i::wasm::WasmFeatures::FromIsolate(isolate);
984984
i::wasm::ErrorThrower thrower(isolate, "ignored");
985985
i::Handle<i::WasmModuleObject> module;
986986
if (!isolate->wasm_engine()
@@ -1763,7 +1763,8 @@ auto Table::make(Store* store_abs, const TableType* type, const Ref* ref)
17631763
i_type = i::wasm::kWasmFuncRef;
17641764
break;
17651765
case ANYREF:
1766-
DCHECK(i::wasm::WasmFeaturesFromFlags().anyref); // See Engine::make().
1766+
// See Engine::make().
1767+
DCHECK(i::wasm::WasmFeatures::FromFlags().has_anyref());
17671768
i_type = i::wasm::kWasmAnyRef;
17681769
break;
17691770
default:

src/wasm/function-body-decoder-impl.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ struct WasmException;
4343

4444
#define RET_ON_PROTOTYPE_OPCODE(feat) \
4545
DCHECK(!this->module_ || this->module_->origin == kWasmOrigin); \
46-
if (!this->enabled_.feat) { \
46+
if (!this->enabled_.has_##feat()) { \
4747
this->error("Invalid opcode (enable with --experimental-wasm-" #feat ")"); \
4848
} else { \
49-
this->detected_->feat = true; \
49+
this->detected_->Add(kFeature_##feat); \
5050
}
5151

5252
#define CHECK_PROTOTYPE_OPCODE(feat) \
5353
DCHECK(!this->module_ || this->module_->origin == kWasmOrigin); \
54-
if (!this->enabled_.feat) { \
54+
if (!this->enabled_.has_##feat()) { \
5555
this->error("Invalid opcode (enable with --experimental-wasm-" #feat ")"); \
5656
break; \
5757
} else { \
58-
this->detected_->feat = true; \
58+
this->detected_->Add(kFeature_##feat); \
5959
}
6060

6161
#define OPCODE_ERROR(opcode, message) \
@@ -281,7 +281,7 @@ struct BlockTypeImmediate {
281281
uint8_t val = decoder->read_u8<validate>(pc + 1, "block type");
282282
if (!function_body_decoder::decode_local_type(val, &type)) {
283283
// Handle multi-value blocks.
284-
if (!VALIDATE(enabled.mv)) {
284+
if (!VALIDATE(enabled.has_mv())) {
285285
decoder->error(pc + 1, "invalid block type");
286286
return;
287287
}
@@ -381,7 +381,8 @@ struct CallIndirectImmediate {
381381
uint32_t len = 0;
382382
sig_index = decoder->read_u32v<validate>(pc + 1, &len, "signature index");
383383
TableIndexImmediate<validate> table(decoder, pc + len);
384-
if (!VALIDATE((table.index == 0 && table.length == 1) || enabled.anyref)) {
384+
if (!VALIDATE((table.index == 0 && table.length == 1) ||
385+
enabled.has_anyref())) {
385386
decoder->errorf(pc + 1 + len, "expected table index 0, found %u",
386387
table.index);
387388
}
@@ -840,7 +841,7 @@ class WasmDecoder : public Decoder {
840841
type = kWasmF64;
841842
break;
842843
case kLocalAnyRef:
843-
if (enabled.anyref) {
844+
if (enabled.has_anyref()) {
844845
type = kWasmAnyRef;
845846
break;
846847
}
@@ -849,7 +850,7 @@ class WasmDecoder : public Decoder {
849850
"--experimental-wasm-anyref");
850851
return false;
851852
case kLocalFuncRef:
852-
if (enabled.anyref) {
853+
if (enabled.has_anyref()) {
853854
type = kWasmFuncRef;
854855
break;
855856
}
@@ -858,7 +859,7 @@ class WasmDecoder : public Decoder {
858859
"--experimental-wasm-anyref");
859860
return false;
860861
case kLocalExnRef:
861-
if (enabled.eh) {
862+
if (enabled.has_eh()) {
862863
type = kWasmExnRef;
863864
break;
864865
}
@@ -867,7 +868,7 @@ class WasmDecoder : public Decoder {
867868
"--experimental-wasm-eh");
868869
return false;
869870
case kLocalS128:
870-
if (enabled.simd) {
871+
if (enabled.has_simd()) {
871872
type = kWasmS128;
872873
break;
873874
}
@@ -1231,15 +1232,15 @@ class WasmDecoder : public Decoder {
12311232
}
12321233
case kExprCallIndirect:
12331234
case kExprReturnCallIndirect: {
1234-
CallIndirectImmediate<validate> imm(kAllWasmFeatures, decoder, pc);
1235+
CallIndirectImmediate<validate> imm(WasmFeatures::All(), decoder, pc);
12351236
return 1 + imm.length;
12361237
}
12371238

12381239
case kExprTry:
12391240
case kExprIf: // fall through
12401241
case kExprLoop:
12411242
case kExprBlock: {
1242-
BlockTypeImmediate<validate> imm(kAllWasmFeatures, decoder, pc);
1243+
BlockTypeImmediate<validate> imm(WasmFeatures::All(), decoder, pc);
12431244
return 1 + imm.length;
12441245
}
12451246

@@ -2569,7 +2570,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
25692570
}
25702571

25712572
for (int i = 0; i < br_arity; ++i) {
2572-
if (this->enabled_.anyref) {
2573+
if (this->enabled_.has_anyref()) {
25732574
// The expected type is the biggest common sub type of all targets.
25742575
(*result_types)[i] =
25752576
ValueTypes::CommonSubType((*result_types)[i], (*merge)[i].type);

src/wasm/function-body-decoder.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ BytecodeIterator::BytecodeIterator(const byte* start, const byte* end,
3535
BodyLocalDecls* decls)
3636
: Decoder(start, end) {
3737
if (decls != nullptr) {
38-
if (DecodeLocalDecls(kAllWasmFeatures, decls, start, end)) {
38+
if (DecodeLocalDecls(WasmFeatures::All(), decls, start, end)) {
3939
pc_ += decls->encoded_size;
4040
if (pc_ > end_) pc_ = end_;
4141
}
@@ -61,9 +61,9 @@ unsigned OpcodeLength(const byte* pc, const byte* end) {
6161
std::pair<uint32_t, uint32_t> StackEffect(const WasmModule* module,
6262
FunctionSig* sig, const byte* pc,
6363
const byte* end) {
64-
WasmFeatures unused_detected_features;
64+
WasmFeatures unused_detected_features = WasmFeatures::None();
6565
WasmDecoder<Decoder::kNoValidate> decoder(
66-
module, kAllWasmFeatures, &unused_detected_features, sig, pc, end);
66+
module, WasmFeatures::All(), &unused_detected_features, sig, pc, end);
6767
return decoder.StackEffect(pc);
6868
}
6969

@@ -98,8 +98,8 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
9898
const WasmModule* module, PrintLocals print_locals,
9999
std::ostream& os, std::vector<int>* line_numbers) {
100100
Zone zone(allocator, ZONE_NAME);
101-
WasmFeatures unused_detected_features;
102-
WasmDecoder<Decoder::kNoValidate> decoder(module, kAllWasmFeatures,
101+
WasmFeatures unused_detected_features = WasmFeatures::None();
102+
WasmDecoder<Decoder::kNoValidate> decoder(module, WasmFeatures::All(),
103103
&unused_detected_features, body.sig,
104104
body.start, body.end);
105105
int line_nr = 0;
@@ -208,7 +208,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
208208
case kExprIf:
209209
case kExprBlock:
210210
case kExprTry: {
211-
BlockTypeImmediate<Decoder::kNoValidate> imm(kAllWasmFeatures, &i,
211+
BlockTypeImmediate<Decoder::kNoValidate> imm(WasmFeatures::All(), &i,
212212
i.pc());
213213
os << " // @" << i.pc_offset();
214214
if (decoder.Complete(imm)) {
@@ -239,7 +239,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
239239
break;
240240
}
241241
case kExprCallIndirect: {
242-
CallIndirectImmediate<Decoder::kNoValidate> imm(kAllWasmFeatures, &i,
242+
CallIndirectImmediate<Decoder::kNoValidate> imm(WasmFeatures::All(), &i,
243243
i.pc());
244244
os << " // sig #" << imm.sig_index;
245245
if (decoder.Complete(i.pc(), imm)) {

src/wasm/function-body-decoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class BitVector; // forward declaration
1919

2020
namespace wasm {
2121

22+
class WasmFeatures;
2223
struct WasmModule; // forward declaration of module interface.
23-
struct WasmFeatures;
2424

2525
// A wrapper around the signature and bytes of a function.
2626
struct FunctionBody {

0 commit comments

Comments
 (0)