Skip to content

Commit 35cce40

Browse files
sunfishcodeaheejin
andauthored
[WebAssembly] Support the new "Lime1" CPU (#112035)
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 --------- Co-authored-by: Heejin Ahn <[email protected]>
1 parent e9dc6c5 commit 35cce40

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

clang/docs/ReleaseNotes.rst

+6
Original file line numberDiff line numberDiff line change
@@ -935,9 +935,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
935935
and [Non-trapping float-to-int Conversions] language features, which are
936936
[widely implemented in engines].
937937

938+
A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition of
939+
the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
940+
-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
941+
and -mextended-const.
942+
938943
[Bulk Memory Operations]: https://github.com./WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
939944
[Non-trapping float-to-int Conversions]: https://github.com./WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
940945
[widely implemented in engines]: https://webassembly.org/features/
946+
[here]: https://github.com./WebAssembly/tool-conventions/blob/main/Lime.md#lime1
941947

942948
AVR Support
943949
^^^^^^^^^^^

clang/lib/Basic/Targets/WebAssembly.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static constexpr Builtin::Info BuiltinInfo[] = {
3131
};
3232

3333
static constexpr llvm::StringLiteral ValidCPUNames[] = {
34-
{"mvp"}, {"bleeding-edge"}, {"generic"}};
34+
{"mvp"}, {"bleeding-edge"}, {"generic"}, {"lime"}};
3535

3636
StringRef WebAssemblyTargetInfo::getABI() const { return ABI; }
3737

@@ -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["bulk-memory-opt"] = true;
174+
Features["call-indirect-overlong"] = true;
175+
Features["extended-const"] = true;
176+
Features["multivalue"] = true;
177+
Features["mutable-globals"] = true;
178+
Features["nontrapping-fptoint"] = true;
179+
Features["sign-ext"] = 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

+6
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
226226
and [Non-trapping float-to-int Conversions] language features, which are
227227
[widely implemented in engines].
228228

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

233239
Changes to the Windows Target
234240
-----------------------------

llvm/lib/Target/WebAssembly/WebAssembly.td

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ def : ProcessorModel<"generic", NoSchedModel,
127127
FeatureMutableGlobals, FeatureNontrappingFPToInt,
128128
FeatureReferenceTypes, FeatureSignExt]>;
129129

130+
// Lime1: <https://github.com./WebAssembly/tool-conventions/blob/main/Lime.md#lime1>
131+
def : ProcessorModel<"lime1", NoSchedModel,
132+
[FeatureBulkMemoryOpt, FeatureCallIndirectOverlong,
133+
FeatureExtendedConst, FeatureMultivalue,
134+
FeatureMutableGlobals, FeatureNontrappingFPToInt,
135+
FeatureSignExt]>;
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

+27
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)