Skip to content

Commit 486c001

Browse files
committed
[WebAssembly] Support the new "Lime1" CPU
This adds WebAssembly support for the new [Lime1 CPU]. First, this defines some new target features. These are subsets of existing features that reflect implementation concerns: - "call-indirect-overlong" - implied by "reference-types"; just the overlong encoding for the `call_indirect` immediate, and not the actual reference types. - "bulk-memory-opt" - implied by "bulk-memory": just `memory.copy` and `memory.fill`, and not the other instructions in the bulk-memory proposal. Next, this defines a new target CPU, "lime1", which enables mutable-globals, bulk-memory-opt, multivalue, sign-ext, nontrapping-fptoint, extended-const, and call-indirect-overlong. Unlike the default "generic" CPU, "lime1" is meant to be frozen, and followed up by "lime2" and so on when new features are desired. [Lime1 CPU]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
1 parent 2c26e66 commit 486c001

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
854854
and [Non-trapping float-to-int Conversions] language features, which are
855855
[widely implemented in engines].
856856

857+
A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition of
858+
the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
859+
-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
860+
and -mextended-const.
861+
857862
[Bulk Memory Operations]: https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
858863
[Non-trapping float-to-int Conversions]: https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
859864
[widely implemented in engines]: https://webassembly.org/features/
865+
[here]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
860866

861867
AVR Support
862868
^^^^^^^^^^^

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ bool WebAssemblyTargetInfo::initFeatureMap(
167167
Features["reference-types"] = true;
168168
Features["sign-ext"] = true;
169169
};
170+
auto addLime1Features = [&]() {
171+
// Lime1:
172+
// <https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1>
173+
Features["multivalue"] = true;
174+
Features["mutable-globals"] = true;
175+
Features["call-indirect-overlong"] = true;
176+
Features["sign-ext"] = true;
177+
Features["bulk-memory-opt"] = true;
178+
Features["nontrapping-fptoint"] = true;
179+
Features["extended-const"] = true;
180+
};
170181
auto addBleedingEdgeFeatures = [&]() {
171182
addGenericFeatures();
172183
Features["atomics"] = true;
@@ -180,6 +191,8 @@ bool WebAssemblyTargetInfo::initFeatureMap(
180191
};
181192
if (CPU == "generic") {
182193
addGenericFeatures();
194+
} else if (CPU == "lime1") {
195+
addLime1Features();
183196
} else if (CPU == "bleeding-edge") {
184197
addBleedingEdgeFeatures();
185198
}

llvm/docs/ReleaseNotes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
221221
and [Non-trapping float-to-int Conversions] language features, which are
222222
[widely implemented in engines].
223223

224+
A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition of
225+
the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
226+
-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
227+
and -mextended-const.
228+
224229
[Bulk Memory Operations]: https://github.com/WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
225230
[Non-trapping float-to-int Conversions]: https://github.com/WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
226231
[widely implemented in engines]: https://webassembly.org/features/
232+
[here]: https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1
227233

228234
Changes to the Windows Target
229235
-----------------------------

llvm/lib/Target/WebAssembly/WebAssembly.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ def : ProcessorModel<"generic", NoSchedModel,
127127
FeatureNontrappingFPToInt, FeatureReferenceTypes,
128128
FeatureCallIndirectOverlong, FeatureSignExt]>;
129129

130+
// Lime1: <https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1>
131+
def : ProcessorModel<"lime1", NoSchedModel,
132+
[FeatureMultivalue, FeatureMutableGlobals,
133+
FeatureCallIndirectOverlong, FeatureSignExt,
134+
FeatureBulkMemoryOpt, FeatureNontrappingFPToInt,
135+
FeatureExtendedConst]>;
136+
130137
// Latest and greatest experimental version of WebAssembly. Bugs included!
131138
def : ProcessorModel<"bleeding-edge", NoSchedModel,
132139
[FeatureAtomics, FeatureBulkMemory, FeatureBulkMemoryOpt,

llvm/test/CodeGen/WebAssembly/target-features-cpus.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; RUN: llc < %s -mcpu=mvp | FileCheck %s --check-prefixes MVP
22
; RUN: llc < %s -mcpu=generic | FileCheck %s --check-prefixes GENERIC
3+
; RUN: llc < %s -mcpu=lime1 | FileCheck %s --check-prefixes LIME1
34
; RUN: llc < %s | FileCheck %s --check-prefixes GENERIC
45
; RUN: llc < %s -mcpu=bleeding-edge | FileCheck %s --check-prefixes BLEEDING-EDGE
56

@@ -39,6 +40,32 @@ target triple = "wasm32-unknown-unknown"
3940
; GENERIC-NEXT: .int8 8
4041
; GENERIC-NEXT: .ascii "sign-ext"
4142

43+
; lime1: +bulk-memory-opt, +call-indirect-overlong, +extended-const, +multivalue,
44+
; +mutable-globals, +nontrapping-fptoint, +sign-ext
45+
; LIME1-LABEL: .custom_section.target_features,"",@
46+
; LIME1-NEXT: .int8 7
47+
; LIME1-NEXT: .int8 43
48+
; LIME1-NEXT: .int8 15
49+
; LIME1-NEXT: .ascii "bulk-memory-opt"
50+
; LIME1-NEXT: .int8 43
51+
; LIME1-NEXT: .int8 22
52+
; LIME1-NEXT: .ascii "call-indirect-overlong"
53+
; LIME1-NEXT: .int8 43
54+
; LIME1-NEXT: .int8 14
55+
; LIME1-NEXT: .ascii "extended-const"
56+
; LIME1-NEXT: .int8 43
57+
; LIME1-NEXT: .int8 10
58+
; LIME1-NEXT: .ascii "multivalue"
59+
; LIME1-NEXT: .int8 43
60+
; LIME1-NEXT: .int8 15
61+
; LIME1-NEXT: .ascii "mutable-globals"
62+
; LIME1-NEXT: .int8 43
63+
; LIME1-NEXT: .int8 19
64+
; LIME1-NEXT: .ascii "nontrapping-fptoint"
65+
; LIME1-NEXT: .int8 43
66+
; LIME1-NEXT: .int8 8
67+
; LIME1-NEXT: .ascii "sign-ext"
68+
4269
; bleeding-edge: +atomics, +bulk-memory, +bulk-memory-opt,
4370
; +call-indirect-overlong, +exception-handling,
4471
; +extended-const, +fp16, +multimemory, +multivalue,

0 commit comments

Comments
 (0)