Skip to content

[WebAssembly] Support the new "Lime1" CPU #112035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 4, 2024
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
6 changes: 6 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
and [Non-trapping float-to-int Conversions] language features, which are
[widely implemented in engines].

A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition of
the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
and -mextended-const.

[Bulk Memory Operations]: https://github.com./WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
[Non-trapping float-to-int Conversions]: https://github.com./WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
[widely implemented in engines]: https://webassembly.org/features/
[here]: https://github.com./WebAssembly/tool-conventions/blob/main/Lime.md#lime1

AVR Support
^^^^^^^^^^^
Expand Down
15 changes: 14 additions & 1 deletion clang/lib/Basic/Targets/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static constexpr Builtin::Info BuiltinInfo[] = {
};

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

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

Expand Down Expand Up @@ -167,6 +167,17 @@ bool WebAssemblyTargetInfo::initFeatureMap(
Features["reference-types"] = true;
Features["sign-ext"] = true;
};
auto addLime1Features = [&]() {
// Lime1:
// <https://github.com./WebAssembly/tool-conventions/blob/main/Lime.md#lime1>
Features["bulk-memory-opt"] = true;
Features["call-indirect-overlong"] = true;
Features["extended-const"] = true;
Features["multivalue"] = true;
Features["mutable-globals"] = true;
Features["nontrapping-fptoint"] = true;
Features["sign-ext"] = true;
};
auto addBleedingEdgeFeatures = [&]() {
addGenericFeatures();
Features["atomics"] = true;
Expand All @@ -180,6 +191,8 @@ bool WebAssemblyTargetInfo::initFeatureMap(
};
if (CPU == "generic") {
addGenericFeatures();
} else if (CPU == "lime1") {
addLime1Features();
} else if (CPU == "bleeding-edge") {
addBleedingEdgeFeatures();
}
Expand Down
6 changes: 6 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,15 @@ and `-mbulk-memory` flags, which correspond to the [Bulk Memory Operations]
and [Non-trapping float-to-int Conversions] language features, which are
[widely implemented in engines].

A new Lime1 target CPU is added, -mcpu=lime1. This CPU follows the definition of
the Lime1 CPU [here], and enables -mmultivalue, -mmutable-globals,
-mcall-indirect-overlong, -msign-ext, -mbulk-memory-opt, -mnontrapping-fptoint,
and -mextended-const.

[Bulk Memory Operations]: https://github.com./WebAssembly/bulk-memory-operations/blob/master/proposals/bulk-memory-operations/Overview.md
[Non-trapping float-to-int Conversions]: https://github.com./WebAssembly/spec/blob/master/proposals/nontrapping-float-to-int-conversion/Overview.md
[widely implemented in engines]: https://webassembly.org/features/
[here]: https://github.com./WebAssembly/tool-conventions/blob/main/Lime.md#lime1

Changes to the Windows Target
-----------------------------
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Target/WebAssembly/WebAssembly.td
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ def : ProcessorModel<"generic", NoSchedModel,
FeatureMutableGlobals, FeatureNontrappingFPToInt,
FeatureReferenceTypes, FeatureSignExt]>;

// Lime1: <https://github.com./WebAssembly/tool-conventions/blob/main/Lime.md#lime1>
def : ProcessorModel<"lime1", NoSchedModel,
[FeatureBulkMemoryOpt, FeatureCallIndirectOverlong,
FeatureExtendedConst, FeatureMultivalue,
FeatureMutableGlobals, FeatureNontrappingFPToInt,
FeatureSignExt]>;

// Latest and greatest experimental version of WebAssembly. Bugs included!
def : ProcessorModel<"bleeding-edge", NoSchedModel,
[FeatureAtomics, FeatureBulkMemory, FeatureBulkMemoryOpt,
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; RUN: llc < %s -mcpu=mvp | FileCheck %s --check-prefixes MVP
; RUN: llc < %s -mcpu=generic | FileCheck %s --check-prefixes GENERIC
; RUN: llc < %s -mcpu=lime1 | FileCheck %s --check-prefixes LIME1
; RUN: llc < %s | FileCheck %s --check-prefixes GENERIC
; RUN: llc < %s -mcpu=bleeding-edge | FileCheck %s --check-prefixes BLEEDING-EDGE

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

; lime1: +bulk-memory-opt, +call-indirect-overlong, +extended-const, +multivalue,
; +mutable-globals, +nontrapping-fptoint, +sign-ext
; LIME1-LABEL: .custom_section.target_features,"",@
; LIME1-NEXT: .int8 7
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 15
; LIME1-NEXT: .ascii "bulk-memory-opt"
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 22
; LIME1-NEXT: .ascii "call-indirect-overlong"
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 14
; LIME1-NEXT: .ascii "extended-const"
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 10
; LIME1-NEXT: .ascii "multivalue"
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 15
; LIME1-NEXT: .ascii "mutable-globals"
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 19
; LIME1-NEXT: .ascii "nontrapping-fptoint"
; LIME1-NEXT: .int8 43
; LIME1-NEXT: .int8 8
; LIME1-NEXT: .ascii "sign-ext"

; bleeding-edge: +atomics, +bulk-memory, +bulk-memory-opt,
; +call-indirect-overlong, +exception-handling,
; +extended-const, +fp16, +multimemory, +multivalue,
Expand Down
Loading