[llvm] 5694dbc - [WebAssembly] support Memory64 in target_features section
Wouter van Oortmerssen via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 25 09:31:58 PDT 2021
Author: Wouter van Oortmerssen
Date: 2021-10-25T09:31:45-07:00
New Revision: 5694dbccc3c8c778024fdfe3ff688cd838b45349
URL: https://github.com/llvm/llvm-project/commit/5694dbccc3c8c778024fdfe3ff688cd838b45349
DIFF: https://github.com/llvm/llvm-project/commit/5694dbccc3c8c778024fdfe3ff688cd838b45349.diff
LOG: [WebAssembly] support Memory64 in target_features section
Differential Revision: https://reviews.llvm.org/D112266
Added:
llvm/test/CodeGen/WebAssembly/memory64-feature.ll
Modified:
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
llvm/test/MC/WebAssembly/debug-info64.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 66acd3519623..3851300f615e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -503,6 +503,15 @@ void WebAssemblyAsmPrinter::EmitTargetFeatures(Module &M) {
// This pseudo-feature tells the linker whether shared memory would be safe
EmitFeature("shared-mem");
+ // This is an "architecture", not a "feature", but we emit it as such for
+ // the benefit of tools like Binaryen and consistency with other producers.
+ // FIXME: Subtarget is null here, so can't Subtarget->hasAddr64() ?
+ if (M.getDataLayout().getMaxPointerSize() == 8) {
+ // Can't use EmitFeature since "wasm-feature-memory64" is not a module
+ // flag.
+ EmittedFeatures.push_back({wasm::WASM_FEATURE_PREFIX_USED, "memory64"});
+ }
+
if (EmittedFeatures.size() == 0)
return;
diff --git a/llvm/test/CodeGen/WebAssembly/memory64-feature.ll b/llvm/test/CodeGen/WebAssembly/memory64-feature.ll
new file mode 100644
index 000000000000..53fccfe08888
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/memory64-feature.ll
@@ -0,0 +1,15 @@
+; RUN: llc < %s | FileCheck %s
+
+; Test that wasm64 is properly emitted into the target features section
+
+target triple = "wasm64-unknown-unknown"
+
+define void @foo() {
+ ret void
+}
+
+; CHECK-LABEL: .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 8
+; CHECK-NEXT: .ascii "memory64"
diff --git a/llvm/test/MC/WebAssembly/debug-info64.ll b/llvm/test/MC/WebAssembly/debug-info64.ll
index a8d9a24a1f2b..60fa0cbfe987 100644
--- a/llvm/test/MC/WebAssembly/debug-info64.ll
+++ b/llvm/test/MC/WebAssembly/debug-info64.ll
@@ -129,6 +129,12 @@
; CHECK-NEXT: Offset: 1073
; CHECK-NEXT: Name: producers
; CHECK-NEXT: }
+; CHECK-NEXT: Section {
+; CHECK-NEXT: Type: CUSTOM (0x0)
+; CHECK-NEXT: Size: 11
+; CHECK-NEXT: Offset: 1166
+; CHECK-NEXT: Name: target_features
+; CHECK-NEXT: }
; CHECK-NEXT: ]
; CHECK-NEXT: Relocations [
; CHECK-NEXT: Section (7) DATA {
More information about the llvm-commits
mailing list