Skip to content

Commit 1bc2cd9

Browse files
authored
[WebAssembly] Enable nontrapping-fptoint and bulk-memory by default. (#112049)
We were prepared to enable these features [back in February], but they got pulled for what appear to be unrelated reasons. So let's have another try at enabling them! Another motivation here is that it'd be convenient for the [Lime1 proposal] if "lime1" is close to a subset of "generic" (missing only for extended-const). [back in February]: WebAssembly/tool-conventions#158 (comment) [Lime1 proposal]: #112035
1 parent cfde4fb commit 1bc2cd9

File tree

16 files changed

+74
-26
lines changed

16 files changed

+74
-26
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,15 @@ NetBSD Support
690690
WebAssembly Support
691691
^^^^^^^^^^^^^^^^^^^
692692

693+
The default target CPU, "generic", now enables the `-mnontrapping-fptoint`
694+
and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
695+
and [Non-trapping float-to-int Conversions] language features, which are
696+
[widely implemented in engines].
697+
698+
[Bulk Memory Operations]: https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
699+
[Non-trapping float-to-int Conversions]: https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
700+
[widely implemented in engines]: https://webassembly.org/features/
701+
693702
AVR Support
694703
^^^^^^^^^^^
695704

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,20 @@ bool WebAssemblyTargetInfo::initFeatureMap(
154154
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
155155
const std::vector<std::string> &FeaturesVec) const {
156156
auto addGenericFeatures = [&]() {
157+
Features["bulk-memory"] = true;
157158
Features["multivalue"] = true;
158159
Features["mutable-globals"] = true;
160+
Features["nontrapping-fptoint"] = true;
159161
Features["reference-types"] = true;
160162
Features["sign-ext"] = true;
161163
};
162164
auto addBleedingEdgeFeatures = [&]() {
163165
addGenericFeatures();
164166
Features["atomics"] = true;
165-
Features["bulk-memory"] = true;
166167
Features["exception-handling"] = true;
167168
Features["extended-const"] = true;
168169
Features["fp16"] = true;
169170
Features["multimemory"] = true;
170-
Features["nontrapping-fptoint"] = true;
171171
Features["tail-call"] = true;
172172
Features["wide-arithmetic"] = true;
173173
setSIMDLevel(Features, RelaxedSIMD, true);

clang/test/Preprocessor/wasm-target-features.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@
163163
// RUN: -target wasm64-unknown-unknown -mcpu=generic \
164164
// RUN: | FileCheck %s -check-prefix=GENERIC-INCLUDE
165165
//
166+
// GENERIC-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
166167
// GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
167168
// GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
169+
// GENERIC-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
168170
// GENERIC-INCLUDE-DAG: #define __wasm_reference_types__ 1{{$}}
169171
// GENERIC-INCLUDE-DAG: #define __wasm_sign_ext__ 1{{$}}
170172
//
@@ -176,12 +178,10 @@
176178
// RUN: | FileCheck %s -check-prefix=GENERIC
177179
//
178180
// GENERIC-NOT: #define __wasm_atomics__ 1{{$}}
179-
// GENERIC-NOT: #define __wasm_bulk_memory__ 1{{$}}
180181
// GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
181182
// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
182183
// GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
183184
// GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
184-
// GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
185185
// GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
186186
// GENERIC-NOT: #define __wasm_simd128__ 1{{$}}
187187
// GENERIC-NOT: #define __wasm_tail_call__ 1{{$}}

lld/test/wasm/custom-section-name.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -filetype=obj %s -o %t.o
1+
; RUN: llc -filetype=obj -mattr=-bulk-memory %s -o %t.o
22
; RUN: wasm-ld -no-gc-sections --no-entry -o %t.wasm %t.o
33
; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,NO-BSS
44
; RUN: wasm-ld -no-gc-sections --no-entry --import-memory -o %t.bss.wasm %t.o

lld/test/wasm/data-segments.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.o -mattr=+atomics
1+
; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.o -mattr=+atomics,-bulk-memory
22
; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.bulk-mem.o -mattr=+bulk-memory
33
; RUN: llc --mtriple=wasm64-unknown-unknown -filetype=obj %s -o %t.bulk-mem64.o -mattr=+bulk-memory
44
; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.atomics.bulk-mem.o -mattr=+atomics,+bulk-memory
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
22
target triple = "wasm32-unknown-unknown"
33

4-
define void @memcpy() {
4+
define void @memcpy() #0 {
55
ret void
66
}
7+
8+
attributes #0 = { "target-features"="-bulk-memory" }

lld/test/wasm/lto/libcall-archive.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
99
target triple = "wasm32-unknown-unknown"
1010

11-
define void @_start(ptr %a, ptr %b) {
11+
define void @_start(ptr %a, ptr %b) #0 {
1212
entry:
1313
call void @llvm.memcpy.p0.p0.i64(ptr %a, ptr %b, i64 1024, i1 false)
1414
ret void
1515
}
1616

1717
declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1)
1818

19+
attributes #0 = { "target-features"="-bulk-memory" }
20+
1921
; CHECK: - Type: CUSTOM
2022
; CHECK-NEXT: Name: name
2123
; CHECK-NEXT: FunctionNames:

lld/test/wasm/lto/stub-library-libcall.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t_main.o %t/main.s
33
# RUN: llvm-as %S/Inputs/foo.ll -o %t_foo.o
44
# RUN: llvm-as %S/Inputs/libcall.ll -o %t_libcall.o
5-
# RUN: wasm-ld %t_main.o %t_libcall.o %t_foo.o %p/Inputs/stub.so -o %t.wasm
5+
# RUN: wasm-ld -mllvm -mattr=-bulk-memory %t_main.o %t_libcall.o %t_foo.o %p/Inputs/stub.so -o %t.wasm
66
# RUN: obj2yaml %t.wasm | FileCheck %s
77

88
# The function `func_with_libcall` will generate an undefined reference to
@@ -12,7 +12,7 @@
1212
# If %t_foo.o is not included in the link we get an undefined symbol reported
1313
# to the dependency of memcpy on the foo export:
1414

15-
# RUN: not wasm-ld %t_main.o %t_libcall.o %p/Inputs/stub.so -o %t.wasm 2>&1 | FileCheck --check-prefix=MISSING %s
15+
# RUN: not wasm-ld -mllvm -mattr=-bulk-memory %t_main.o %t_libcall.o %p/Inputs/stub.so -o %t.wasm 2>&1 | FileCheck --check-prefix=MISSING %s
1616
# MISSING: stub.so: undefined symbol: foo. Required by memcpy
1717

1818
#--- main.s

llvm/docs/ReleaseNotes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ Changes to the RISC-V Backend
180180
Changes to the WebAssembly Backend
181181
----------------------------------
182182

183+
The default target CPU, "generic", now enables the `-mnontrapping-fptoint`
184+
and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
185+
and [Non-trapping float-to-int Conversions] language features, which are
186+
[widely implemented in engines].
187+
188+
[Bulk Memory Operations]: https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
189+
[Non-trapping float-to-int Conversions]: https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
190+
[widely implemented in engines]: https://webassembly.org/features/
191+
183192
Changes to the Windows Target
184193
-----------------------------
185194

llvm/lib/Target/WebAssembly/WebAssembly.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def : ProcessorModel<"mvp", NoSchedModel, []>;
114114
// consideration given to available support in relevant engines and tools, and
115115
// the importance of the features.
116116
def : ProcessorModel<"generic", NoSchedModel,
117-
[FeatureMultivalue, FeatureMutableGlobals,
117+
[FeatureBulkMemory, FeatureMultivalue,
118+
FeatureMutableGlobals, FeatureNontrappingFPToInt,
118119
FeatureReferenceTypes, FeatureSignExt]>;
119120

120121
// Latest and greatest experimental version of WebAssembly. Bugs included!

0 commit comments

Comments
 (0)