[WebAssembly] Add atomics target option

Reviewers: tlively

Subscribers: dschuff, sbc100, jgravelle-google, sunfish, jfb, cfe-commits

Tags: #clang

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

llvm-svn: 353260
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index 48edade..4e22aba 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -41,6 +41,7 @@
       .Case("sign-ext", HasSignExt)
       .Case("exception-handling", HasExceptionHandling)
       .Case("bulk-memory", HasBulkMemory)
+      .Case("atomics", HasAtomics)
       .Default(false);
 }
 
@@ -68,6 +69,8 @@
     Builder.defineMacro("__wasm_exception_handling__");
   if (HasBulkMemory)
     Builder.defineMacro("__wasm_bulk_memory__");
+  if (HasAtomics)
+    Builder.defineMacro("__wasm_atomics__");
 }
 
 void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
@@ -90,6 +93,7 @@
   if (CPU == "bleeding-edge") {
     Features["nontrapping-fptoint"] = true;
     Features["sign-ext"] = true;
+    Features["atomics"] = true;
     setSIMDLevel(Features, SIMD128);
   }
   // Other targets do not consider user-configured features here, but while we
@@ -104,6 +108,8 @@
     Features["exception-handling"] = true;
   if (HasBulkMemory)
     Features["bulk-memory"] = true;
+  if (HasAtomics)
+    Features["atomics"] = true;
 
   return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
 }
@@ -159,6 +165,14 @@
       HasBulkMemory = false;
       continue;
     }
+    if (Feature == "+atomics") {
+      HasAtomics = true;
+      continue;
+    }
+    if (Feature == "-atomics") {
+      HasAtomics = false;
+      continue;
+    }
 
     Diags.Report(diag::err_opt_not_valid_with_opt)
         << Feature << "-target-feature";