Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ BinaryenFeatures BinaryenFeatureBulkMemoryOpt(void) {
BinaryenFeatures BinaryenFeatureCallIndirectOverlong(void) {
return static_cast<BinaryenFeatures>(FeatureSet::CallIndirectOverlong);
}
BinaryenFeatures BinaryenFeatureRelaxedAtomics(void) {
return static_cast<BinaryenFeatures>(FeatureSet::RelaxedAtomics);
}
BinaryenFeatures BinaryenFeatureAll(void) {
return static_cast<BinaryenFeatures>(FeatureSet::All);
}
Expand Down
1 change: 1 addition & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureSharedEverything(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureFP16(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureBulkMemoryOpt(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureCallIndirectOverlong(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedAtomics(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void);

// Modules
Expand Down
1 change: 1 addition & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function initializeConstants() {
'FP16',
'BulkMemoryOpt',
'CallIndirectOverlong',
'RelaxedAtomics',
'All'
].forEach(name => {
Module['Features'][name] = Module['_BinaryenFeature' + name]();
Expand Down
12 changes: 9 additions & 3 deletions src/passes/SafeHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,15 @@ struct SafeHeap : public Pass {
if (align > bytes) {
continue;
}
for (auto memoryOrder : {MemoryOrder::Unordered,
MemoryOrder::AcqRel,
MemoryOrder::SeqCst}) {

std::vector<MemoryOrder> memoryOrders(
features.hasRelaxedAtomics()
? std::initializer_list<MemoryOrder>{MemoryOrder::Unordered,
MemoryOrder::AcqRel,
MemoryOrder::SeqCst}
: std::initializer_list<MemoryOrder>{MemoryOrder::Unordered,
MemoryOrder::SeqCst});
for (MemoryOrder memoryOrder : memoryOrders) {
load.order = memoryOrder;
if (load.isAtomic() &&
!isPossibleAtomicOperation(
Expand Down
2 changes: 2 additions & 0 deletions src/tools/tool-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ struct ToolOptions : public Options {
.addFeature(FeatureSet::FP16, "float 16 operations")
.addFeature(FeatureSet::CustomDescriptors,
"custom descriptors (RTTs) and exact references")
.addFeature(FeatureSet::RelaxedAtomics,
"acquire/release atomic memory operations")
.add("--enable-typed-function-references",
"",
"Deprecated compatibility flag",
Expand Down
1 change: 1 addition & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ extern const char* FP16Feature;
extern const char* BulkMemoryOptFeature;
extern const char* CallIndirectOverlongFeature;
extern const char* CustomDescriptorsFeature;
extern const char* RelaxedAtomicsFeature;

enum Subsection {
NameModule = 0,
Expand Down
7 changes: 6 additions & 1 deletion src/wasm-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ struct FeatureSet {
// it does nothing. Binaryen always accepts LEB call-indirect encodings.
CallIndirectOverlong = 1 << 20,
CustomDescriptors = 1 << 21,
RelaxedAtomics = 1 << 22,
MVP = None,
// Keep in sync with llvm default features:
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
Default = SignExt | MutableGlobals,
All = (1 << 22) - 1,
All = (1 << 23) - 1,
};

static std::string toString(Feature f) {
Expand Down Expand Up @@ -108,6 +109,8 @@ struct FeatureSet {
return "call-indirect-overlong";
case CustomDescriptors:
return "custom-descriptors";
case RelaxedAtomics:
return "relaxed-atomics";
case MVP:
case Default:
case All:
Expand Down Expand Up @@ -168,6 +171,7 @@ struct FeatureSet {
bool hasCustomDescriptors() const {
return (features & CustomDescriptors) != 0;
}
bool hasRelaxedAtomics() const { return (features & RelaxedAtomics) != 0; }
bool hasAll() const { return (features & All) != 0; }

void set(FeatureSet f, bool v = true) {
Expand All @@ -194,6 +198,7 @@ struct FeatureSet {
void setFP16(bool v = true) { set(FP16, v); }
void setBulkMemoryOpt(bool v = true) { set(BulkMemoryOpt, v); }
void setCustomDescriptors(bool v = true) { set(CustomDescriptors, v); }
void setRelaxedAtomics(bool v = true) { set(RelaxedAtomics, v); }
void setMVP() { features = MVP; }
void setAll() { features = All; }

Expand Down
4 changes: 4 additions & 0 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,8 @@ void WasmBinaryWriter::writeFeaturesSection() {
return BinaryConsts::CustomSections::CallIndirectOverlongFeature;
case FeatureSet::CustomDescriptors:
return BinaryConsts::CustomSections::CustomDescriptorsFeature;
case FeatureSet::RelaxedAtomics:
return BinaryConsts::CustomSections::RelaxedAtomicsFeature;
case FeatureSet::None:
case FeatureSet::Default:
case FeatureSet::All:
Expand Down Expand Up @@ -5296,6 +5298,8 @@ void WasmBinaryReader::readFeatures(size_t sectionPos, size_t payloadLen) {
feature = FeatureSet::FP16;
} else if (name == BinaryConsts::CustomSections::CustomDescriptorsFeature) {
feature = FeatureSet::CustomDescriptors;
} else if (name == BinaryConsts::CustomSections::RelaxedAtomicsFeature) {
feature = FeatureSet::RelaxedAtomics;
} else {
// Silently ignore unknown features (this may be and old binaryen running
// on a new wasm).
Expand Down
6 changes: 6 additions & 0 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,12 @@ void FunctionValidator::visitLoad(Load* curr) {
curr,
"Atomic load should be i32 or i64");
}
if (curr->order == MemoryOrder::AcqRel) {
shouldBeTrue(getModule()->features.hasRelaxedAtomics(),
curr,
"Acquire/release operations require relaxed atomics "
"[--enable-relaxed-atomics]");
}
if (curr->type == Type::v128) {
shouldBeTrue(getModule()->features.hasSIMD(),
curr,
Expand Down
1 change: 1 addition & 0 deletions src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const char* FP16Feature = "fp16";
const char* BulkMemoryOptFeature = "bulk-memory-opt";
const char* CallIndirectOverlongFeature = "call-indirect-overlong";
const char* CustomDescriptorsFeature = "custom-descriptors";
const char* RelaxedAtomicsFeature = "relaxed-atomics";

} // namespace BinaryConsts::CustomSections

Expand Down
1 change: 1 addition & 0 deletions test/binaryen.js/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function test_features() {
console.log("Features.ExtendedConst: " + binaryen.Features.ExtendedConst);
console.log("Features.Strings: " + binaryen.Features.Strings);
console.log("Features.MultiMemory: " + binaryen.Features.MultiMemory);
console.log("Features.RelaxedAtomics: " + binaryen.Features.RelaxedAtomics);
console.log("Features.All: " + binaryen.Features.All);
}

Expand Down
3 changes: 2 additions & 1 deletion test/binaryen.js/kitchen-sink.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Features.RelaxedSIMD: 4096
Features.ExtendedConst: 8192
Features.Strings: 16384
Features.MultiMemory: 32768
Features.All: 4194303
Features.RelaxedAtomics: 4194304
Features.All: 8388607
InvalidId: 0
BlockId: 1
IfId: 2
Expand Down
2 changes: 2 additions & 0 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ void test_features() {
printf("BinaryenFeatureRelaxedSIMD: %d\n", BinaryenFeatureRelaxedSIMD());
printf("BinaryenFeatureExtendedConst: %d\n", BinaryenFeatureExtendedConst());
printf("BinaryenFeatureStrings: %d\n", BinaryenFeatureStrings());
printf("BinaryenFeatureRelaxedAtomics: %d\n",
BinaryenFeatureRelaxedAtomics());
printf("BinaryenFeatureAll: %d\n", BinaryenFeatureAll());
}

Expand Down
3 changes: 2 additions & 1 deletion test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ BinaryenFeatureMemory64: 2048
BinaryenFeatureRelaxedSIMD: 4096
BinaryenFeatureExtendedConst: 8192
BinaryenFeatureStrings: 16384
BinaryenFeatureAll: 4194303
BinaryenFeatureRelaxedAtomics: 4194304
BinaryenFeatureAll: 8388607
(f32.neg
(f32.const -33.61199951171875)
)
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-as.test
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-ctor-eval.test
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-dis.test
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-emscripten-finalize.test
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-metadce.test
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors
;; CHECK-NEXT: (RTTs) and exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic
;; CHECK-NEXT: memory operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic
;; CHECK-NEXT: memory operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-opt.test
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors
;; CHECK-NEXT: (RTTs) and exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic
;; CHECK-NEXT: memory operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic
;; CHECK-NEXT: memory operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-reduce.test
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm-split.test
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
;; CHECK-NEXT: exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic memory
;; CHECK-NEXT: operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
6 changes: 6 additions & 0 deletions test/lit/help/wasm2js.test
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,12 @@
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors
;; CHECK-NEXT: (RTTs) and exact references
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-relaxed-atomics Enable acquire/release atomic
;; CHECK-NEXT: memory operations
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-relaxed-atomics Disable acquire/release atomic
;; CHECK-NEXT: memory operations
;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
Expand Down
Loading
Loading