v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-features.h
Go to the documentation of this file.
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_WASM_WASM_FEATURES_H_
6#define V8_WASM_WASM_FEATURES_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include <iosfwd>
13#include <string>
14
16#include "src/common/globals.h"
17// The feature flags are declared in their own header.
19
20// Features that are always enabled and do not have a flag.
21#define FOREACH_WASM_NON_FLAG_FEATURE(V) \
22 V(shared_memory) \
23 V(reftypes) \
24 V(simd) \
25 V(threads) \
26 V(return_call) \
27 V(extended_const) \
28 V(relaxed_simd) \
29 V(gc) \
30 V(typed_funcref) \
31 V(multi_memory) \
32 V(memory64)
33
34// All features, including features that do not have flags.
35#define FOREACH_WASM_FEATURE(V) \
36 FOREACH_WASM_FEATURE_FLAG(V) \
37 FOREACH_WASM_NON_FLAG_FEATURE(V)
38
39namespace v8::internal::wasm {
40
42#define DECL_FEATURE_ENUM(feat, ...) feat,
44#undef DECL_FEATURE_ENUM
45};
46
48#define DECL_FEATURE_ENUM(feat, ...) feat,
50#undef DECL_FEATURE_ENUM
51};
52
53// Set of enabled features. This only includes features that have a flag.
54class WasmEnabledFeatures : public base::EnumSet<WasmEnabledFeature> {
55 public:
56 constexpr WasmEnabledFeatures() = default;
57 explicit constexpr WasmEnabledFeatures(
58 std::initializer_list<WasmEnabledFeature> features)
59 : EnumSet(features) {}
60
61 // Simplified getters. Use {has_foo()} instead of
62 // {contains(WasmEnabledFeature::foo)}.
63#define DECL_FEATURE_GETTER(feat, ...) \
64 constexpr bool has_##feat() const { \
65 return contains(WasmEnabledFeature::feat); \
66 }
68#undef DECL_FEATURE_GETTER
69
70 static inline constexpr WasmEnabledFeatures All() {
71#define LIST_FEATURE(feat, ...) WasmEnabledFeature::feat,
73#undef LIST_FEATURE
74 }
75 static inline constexpr WasmEnabledFeatures None() { return {}; }
76 static inline constexpr WasmEnabledFeatures ForAsmjs() { return {}; }
77 // Retuns optional features that are enabled by flags, plus features that are
78 // not enabled by a flag and are always on.
83};
84
85// Set of detected features. This includes features that have a flag plus
86// features in FOREACH_WASM_NON_FLAG_FEATURE.
87class WasmDetectedFeatures : public base::EnumSet<WasmDetectedFeature> {
88 public:
89 constexpr WasmDetectedFeatures() = default;
90 // Construct from an enum set.
91 // NOLINTNEXTLINE(runtime/explicit)
94
95 // Simplified getters and setters. Use {add_foo()} and {has_foo()} instead of
96 // {Add(WasmDetectedFeature::foo)} or {contains(WasmDetectedFeature::foo)}.
97#define DECL_FEATURE_GETTER(feat, ...) \
98 constexpr void add_##feat() { Add(WasmDetectedFeature::feat); } \
99 constexpr bool has_##feat() const { \
100 return contains(WasmDetectedFeature::feat); \
101 }
103#undef DECL_FEATURE_GETTER
104};
105
106inline constexpr const char* name(WasmEnabledFeature feature) {
107 switch (feature) {
108#define NAME(feat, ...) \
109 case WasmEnabledFeature::feat: \
110 return #feat;
112 }
113#undef NAME
114}
115
116inline std::ostream& operator<<(std::ostream& os, WasmEnabledFeature feature) {
117 return os << name(feature);
118}
119
120inline constexpr const char* name(WasmDetectedFeature feature) {
121 switch (feature) {
122#define NAME(feat, ...) \
123 case WasmDetectedFeature::feat: \
124 return #feat;
126 }
127#undef NAME
128}
129
130inline std::ostream& operator<<(std::ostream& os, WasmDetectedFeature feature) {
131 return os << name(feature);
132}
133
135 kJsString,
139 // Not really an import, but needs the same handling as compile-time imports.
141};
142
143inline std::ostream& operator<<(std::ostream& os, CompileTimeImport imp) {
144 return os << static_cast<int>(imp);
145}
146
148
150 public:
152
155 V8_NOEXCEPT = default;
157 *this = std::move(other);
158 }
160 bits_ = other.bits_;
161 constants_module_ = std::move(other.constants_module_);
162 return *this;
163 }
173
174 bool empty() const { return bits_.empty(); }
177 constants_module_.size() == name.size() &&
178 std::equal(name.begin(), name.end(), constants_module_.begin());
179 }
180 bool contains(CompileTimeImport imp) const { return bits_.contains(imp); }
181
182 int compare(const CompileTimeImports& other) const {
183 if (bits_.ToIntegral() < other.bits_.ToIntegral()) return -1;
184 if (bits_.ToIntegral() > other.bits_.ToIntegral()) return 1;
185 return constants_module_.compare(other.constants_module_);
186 }
187
188 void Add(CompileTimeImport imp) { bits_.Add(imp); }
189
190 std::string& constants_module() { return constants_module_; }
191 const std::string& constants_module() const { return constants_module_; }
192
194
195 private:
197 std::string constants_module_;
198};
199
200} // namespace v8::internal::wasm
201
202#endif // V8_WASM_WASM_FEATURES_H_
constexpr void Add(E element)
Definition enum-set.h:50
static constexpr EnumSet FromIntegral(int bits)
Definition enum-set.h:91
constexpr bool empty() const
Definition enum-set.h:34
constexpr T ToIntegral() const
Definition enum-set.h:56
constexpr bool contains(E element) const
Definition enum-set.h:35
bool has_string_constants(base::Vector< const uint8_t > name) const
CompileTimeImportFlags flags() const
CompileTimeImports & operator=(const CompileTimeImports &other) V8_NOEXCEPT=default
const std::string & constants_module() const
CompileTimeImports & operator=(CompileTimeImports &&other) V8_NOEXCEPT
static CompileTimeImports FromSerialized(CompileTimeImportFlags::StorageType flags, base::Vector< const char > constants_module)
bool contains(CompileTimeImport imp) const
int compare(const CompileTimeImports &other) const
CompileTimeImports(const CompileTimeImports &other) V8_NOEXCEPT=default
CompileTimeImports(CompileTimeImports &&other) V8_NOEXCEPT
void Add(CompileTimeImport imp)
constexpr WasmDetectedFeatures(base::EnumSet< WasmDetectedFeature > features)
constexpr WasmEnabledFeatures(std::initializer_list< WasmEnabledFeature > features)
static V8_EXPORT_PRIVATE WasmEnabledFeatures FromContext(Isolate *, DirectHandle< NativeContext >)
static V8_EXPORT_PRIVATE WasmEnabledFeatures FromIsolate(Isolate *)
static constexpr WasmEnabledFeatures All()
static V8_EXPORT_PRIVATE WasmEnabledFeatures FromFlags()
static constexpr WasmEnabledFeatures ForAsmjs()
static constexpr WasmEnabledFeatures None()
ZoneVector< RpoNumber > & result
#define LIST_FEATURE(name,...)
std::ostream & operator<<(std::ostream &os, LiftoffVarState slot)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
Definition flags.cc:2086
#define V8_NOEXCEPT
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define FOREACH_WASM_FEATURE_FLAG(V)
#define NAME(feat,...)
#define DECL_FEATURE_GETTER(feat,...)
#define FOREACH_WASM_FEATURE(V)