[WebAssembly] Add mutable globals feature

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

llvm-svn: 357321
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index 4e22aba..2fceed2 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -42,6 +42,7 @@
       .Case("exception-handling", HasExceptionHandling)
       .Case("bulk-memory", HasBulkMemory)
       .Case("atomics", HasAtomics)
+      .Case("mutable-globals", HasMutableGlobals)
       .Default(false);
 }
 
@@ -71,6 +72,8 @@
     Builder.defineMacro("__wasm_bulk_memory__");
   if (HasAtomics)
     Builder.defineMacro("__wasm_atomics__");
+  if (HasMutableGlobals)
+    Builder.defineMacro("__wasm_mutable_globals__");
 }
 
 void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
@@ -94,6 +97,7 @@
     Features["nontrapping-fptoint"] = true;
     Features["sign-ext"] = true;
     Features["atomics"] = true;
+    Features["mutable-globals"] = true;
     setSIMDLevel(Features, SIMD128);
   }
   // Other targets do not consider user-configured features here, but while we
@@ -110,6 +114,8 @@
     Features["bulk-memory"] = true;
   if (HasAtomics)
     Features["atomics"] = true;
+  if (HasMutableGlobals)
+    Features["mutable-globals"] = true;
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
@@ -173,6 +179,14 @@
       HasAtomics = false;
       continue;
     }
+    if (Feature == "+mutable-globals") {
+      HasMutableGlobals = true;
+      continue;
+    }
+    if (Feature == "-mutable-globals") {
+      HasMutableGlobals = false;
+      continue;
+    }
 
     Diags.Report(diag::err_opt_not_valid_with_opt)
         << Feature << "-target-feature";