]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Add mutable globals feature
authorThomas Lively <tlively@google.com>
Fri, 29 Mar 2019 22:00:18 +0000 (22:00 +0000)
committerThomas Lively <tlively@google.com>
Fri, 29 Mar 2019 22:00:18 +0000 (22:00 +0000)
Summary:
This feature is not actually used for anything in the WebAssembly
backend, but adding it allows users to get it into the target features
sections of their objects, which makes these objects
future-compatible.

Reviewers: aheejin, dschuff

Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, jdoerfert, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D60013

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357321 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssembly.td
lib/Target/WebAssembly/WebAssemblySubtarget.h
test/CodeGen/WebAssembly/mutable-globals.ll [new file with mode: 0644]

index 230c1208e54d703ad4428b80ccd9e16efe84b2eb..9138683d4984540bec5f75d6a7b2f5bb150a2888 100644 (file)
@@ -51,6 +51,10 @@ def FeatureBulkMemory :
       SubtargetFeature<"bulk-memory", "HasBulkMemory", "true",
                        "Enable bulk memory operations">;
 
+def FeatureMutableGlobals :
+      SubtargetFeature<"mutable-globals", "HasMutableGlobals", "true",
+                       "Enable mutable globals">;
+
 //===----------------------------------------------------------------------===//
 // Architectures.
 //===----------------------------------------------------------------------===//
index ae1f3fe39468f20500501f538c75d203568fdd1b..22e11726f33e7fa3788b624b8027d72618509d12 100644 (file)
@@ -44,6 +44,7 @@ class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasMutableGlobals = false;
 
   /// String name of used CPU.
   std::string CPUString;
@@ -97,6 +98,7 @@ public:
   bool hasSignExt() const { return HasSignExt; }
   bool hasExceptionHandling() const { return HasExceptionHandling; }
   bool hasBulkMemory() const { return HasBulkMemory; }
+  bool hasMutableGlobals() const { return HasMutableGlobals; }
 
   /// Parses features string setting specified subtarget options. Definition of
   /// function is auto generated by tblgen.
diff --git a/test/CodeGen/WebAssembly/mutable-globals.ll b/test/CodeGen/WebAssembly/mutable-globals.ll
new file mode 100644 (file)
index 0000000..45b4854
--- /dev/null
@@ -0,0 +1,16 @@
+; RUN: llc < %s -mattr=+mutable-globals | FileCheck %s
+
+; Test that mutable globals is properly emitted into the target features section
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+define void @foo() {
+  ret void
+}
+
+; CHECK-LABEL: .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 15
+; CHECK-NEXT: .ascii "mutable-globals"