]> granicus.if.org Git - clang/commitdiff
[WebAssembly] Add atomics target option
authorHeejin Ahn <aheejin@gmail.com>
Wed, 6 Feb 2019 01:41:26 +0000 (01:41 +0000)
committerHeejin Ahn <aheejin@gmail.com>
Wed, 6 Feb 2019 01:41:26 +0000 (01:41 +0000)
Reviewers: tlively

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

Tags: #clang

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

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

include/clang/Driver/Options.td
lib/Basic/Targets/WebAssembly.cpp
lib/Basic/Targets/WebAssembly.h
test/Preprocessor/wasm-target-features.c

index e8d5873572a6348250d9979b285cda4eeab897f0..8c938e2fb658febc17668bab7c7393506322b61a 100644 (file)
@@ -2160,6 +2160,8 @@ def mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Featur
 def mno_exception_handing : Flag<["-"], "mno-exception-handling">, Group<m_wasm_Features_Group>;
 def mbulk_memory : Flag<["-"], "mbulk-memory">, Group<m_wasm_Features_Group>;
 def mno_bulk_memory : Flag<["-"], "mno-bulk-memory">, Group<m_wasm_Features_Group>;
+def matomics : Flag<["-"], "matomics">, Group<m_wasm_Features_Group>;
+def mno_atomics : Flag<["-"], "mno-atomics">, Group<m_wasm_Features_Group>;
 
 def mamdgpu_debugger_abi : Joined<["-"], "mamdgpu-debugger-abi=">,
   Flags<[HelpHidden]>,
index 48edaded5125707ca51d5f15bd3649c7454ae18e..4e22abaaa8b7a1f56dd630afefdc4ce4ab178bcf 100644 (file)
@@ -41,6 +41,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
       .Case("sign-ext", HasSignExt)
       .Case("exception-handling", HasExceptionHandling)
       .Case("bulk-memory", HasBulkMemory)
+      .Case("atomics", HasAtomics)
       .Default(false);
 }
 
@@ -68,6 +69,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
     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 @@ bool WebAssemblyTargetInfo::initFeatureMap(
   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 @@ bool WebAssemblyTargetInfo::initFeatureMap(
     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 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
       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";
index 1d41f2011bb1edeb7322e5f5e997a5c48cb72c2e..efd32c7acf9db0fc1523624569e8534c253dc224 100644 (file)
@@ -34,6 +34,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasAtomics = false;
 
 public:
   explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
index 8c10cd7808ac4be806844e6052371e0a61483e9f..30bc76abae53e2d1f5c099476b1caedf9058ddcc 100644 (file)
 // BULK-MEMORY:#define __wasm_bulk_memory__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN:     -target wasm32-unknown-unknown -matomics \
+// RUN:   | FileCheck %s -check-prefix=ATOMICS
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN:     -target wasm64-unknown-unknown -matomics \
+// RUN:   | FileCheck %s -check-prefix=ATOMICS
+//
+// ATOMICS:#define __wasm_atomics__ 1{{$}}
+//
+// RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN:     -target wasm32-unknown-unknown -mcpu=mvp \
 // RUN:   | FileCheck %s -check-prefix=MVP
 // RUN: %clang -E -dM %s -o - 2>&1 \
@@ -65,6 +74,7 @@
 // MVP-NOT:#define __wasm_sign_ext__
 // MVP-NOT:#define __wasm_exception_handling__
 // MVP-NOT:#define __wasm_bulk_memory__
+// MVP-NOT:#define __wasm_atomics__
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN:     -target wasm32-unknown-unknown -mcpu=bleeding-edge \
 // RUN:     -target wasm64-unknown-unknown -mcpu=bleeding-edge \
 // RUN:   | FileCheck %s -check-prefix=BLEEDING-EDGE
 //
-// BLEEDING-EDGE:#define __wasm_nontrapping_fptoint__ 1{{$}}
-// BLEEDING-EDGE:#define __wasm_sign_ext__ 1{{$}}
-// BLEEDING-EDGE:#define __wasm_simd128__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_nontrapping_fptoint__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_sign_ext__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_simd128__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}}
 // BLEEDING-EDGE-NOT:#define __wasm_unimplemented_simd128__ 1{{$}}
 //
 // RUN: %clang -E -dM %s -o - 2>&1 \