Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.

;; RUN: foreach %s %t wasm-opt --safe-heap --enable-threads --enable-simd --enable-memory64 -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --safe-heap --enable-threads --enable-simd --enable-memory64 --enable-relaxed-atomics -S -o - | filecheck %s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding relaxed-atomics to each of these files, let's make a new file that enables just relaxed atomics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, this test wouldn't pass without --enabled-relaxed-atomics because --safe-heap combined with --enable-threads will cause us to generate safe heap methods that use acqrel ordering (which the next PR fixes but we need this PR first). In the next PR #8193 I add an equivalent test without --enable-relaxed-atomics to show that the acqrel methods aren't added. Also we anyway need a test that enables both relaxed atomics and safe heap to show that the safe acqrel methods are added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. LGTM to land this as-is because of the dependencies between PRs. I think ultimately we don't need to have more than one SafeHeap test that enables relaxed-atomics, though. (Also we can make the test file names much shorter now that they are lit tests.)


(module
(memory i64 100 100 shared)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.

;; RUN: foreach %s %t wasm-opt --safe-heap --enable-threads --enable-simd -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --safe-heap --enable-threads --enable-simd --enable-relaxed-atomics -S -o - | filecheck %s

(module
(memory 100 100 shared)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up.

;; RUN: foreach %s %t wasm-opt --safe-heap --low-memory-unused --enable-threads --enable-simd -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --safe-heap --low-memory-unused --enable-threads --enable-simd --enable-relaxed-atomics -S -o - | filecheck %s

(module
(memory 100 100 shared)
Expand Down
20 changes: 20 additions & 0 deletions test/lit/validation/relaxed-atomics.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;; Test the feature flag for --relaxed-atomics
;; The below tests set --enable-threads since it's required for shared memories.

;; text
;; RUN: wasm-opt --enable-threads --enable-relaxed-atomics %s 2>&1
;; RUN: not wasm-opt --enable-threads --disable-relaxed-atomics %s 2>&1 | filecheck %s

;; binary
;; RUN: wasm-opt --enable-threads --enable-relaxed-atomics %s -o %t.wasm
;; RUN: not wasm-opt --enable-threads --disable-relaxed-atomics %t.wasm 2>&1 | filecheck %s

(module
(memory 1 1 shared)
(func $acqrel (result i32)
;; CHECK: Acquire/release operations require relaxed atomics [--enable-relaxed-atomics]
(i32.atomic.load acqrel
(i32.const 1)
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
--enable-bulk-memory-opt
--enable-call-indirect-overlong
--enable-custom-descriptors
--enable-relaxed-atomics
(module
(type $0 (func (result v128 externref)))
(func $foo (type $0) (result v128 externref)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import utils


# Consider adding new tests to test/lit/validation instead
class FeatureValidationTest(utils.BinaryenTestCase):
def check_feature(self, module, error, flag, const_flags=[]):
p = shared.run_process(shared.WASM_OPT +
Expand Down Expand Up @@ -454,4 +455,5 @@ def test_emit_all_features(self):
'--enable-bulk-memory-opt',
'--enable-call-indirect-overlong',
'--enable-custom-descriptors',
'--enable-relaxed-atomics',
], p2.stdout.splitlines())
Loading