summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2019-03-29 22:00:18 +0000
committerThomas Lively <tlively@google.com>2019-03-29 22:00:18 +0000
commit5f0c4c67bbff5374b196578486a16147cb786548 (patch)
treee66d05e4810f760c273b7a4a3d477ceefd008103
parent32fd32bc6f6de46b96c9e09575694d34f248d6ee (diff)
downloadbcm5719-llvm-5f0c4c67bbff5374b196578486a16147cb786548.tar.gz
bcm5719-llvm-5f0c4c67bbff5374b196578486a16147cb786548.zip
[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
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/lib/Basic/Targets/WebAssembly.cpp14
-rw-r--r--clang/lib/Basic/Targets/WebAssembly.h1
-rw-r--r--clang/test/Preprocessor/wasm-target-features.c11
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssembly.td4
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h2
-rw-r--r--llvm/test/CodeGen/WebAssembly/mutable-globals.ll16
7 files changed, 50 insertions, 0 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ea7c9cdfb7b..abff15311a9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2177,6 +2177,8 @@ def matomics : Flag<["-"], "matomics">, Group<m_wasm_Features_Group>;
def mno_atomics : Flag<["-"], "mno-atomics">, 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 mmutable_globals : Flag<["-"], "mmutable-globals">, Group<m_wasm_Features_Group>;
+def mno_mutable_globals : Flag<["-"], "mno-mutable-globals">, Group<m_wasm_Features_Group>;
def mamdgpu_debugger_abi : Joined<["-"], "mamdgpu-debugger-abi=">,
Flags<[HelpHidden]>,
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index 4e22abaaa8b..2fceed2ad1f 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -42,6 +42,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
.Case("exception-handling", HasExceptionHandling)
.Case("bulk-memory", HasBulkMemory)
.Case("atomics", HasAtomics)
+ .Case("mutable-globals", HasMutableGlobals)
.Default(false);
}
@@ -71,6 +72,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
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 @@ bool WebAssemblyTargetInfo::initFeatureMap(
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 @@ bool WebAssemblyTargetInfo::initFeatureMap(
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 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
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";
diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h
index efd32c7acf9..a0516da286c 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -35,6 +35,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
bool HasExceptionHandling = false;
bool HasBulkMemory = false;
bool HasAtomics = false;
+ bool HasMutableGlobals = false;
public:
explicit WebAssemblyTargetInfo(const llvm::Triple &T, const TargetOptions &)
diff --git a/clang/test/Preprocessor/wasm-target-features.c b/clang/test/Preprocessor/wasm-target-features.c
index d32c1b00be4..2bf94398a1d 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -71,6 +71,15 @@
// PTHREAD:#define __wasm_atomics__ 1{{$}}
// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mmutable-globals \
+// RUN: | FileCheck %s -check-prefix=MUTABLE-GLOBALS
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mmutable-globals \
+// RUN: | FileCheck %s -check-prefix=MUTABLE-GLOBALS
+//
+// MUTABLE-GLOBALS:#define __wasm_mutable_globals__ 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 \
@@ -84,6 +93,7 @@
// MVP-NOT:#define __wasm_exception_handling__
// MVP-NOT:#define __wasm_bulk_memory__
// MVP-NOT:#define __wasm_atomics__
+// MVP-NOT:#define __wasm_mutable_globals__
// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \
@@ -96,6 +106,7 @@
// BLEEDING-EDGE-DAG:#define __wasm_sign_ext__ 1{{$}}
// BLEEDING-EDGE-DAG:#define __wasm_simd128__ 1{{$}}
// BLEEDING-EDGE-DAG:#define __wasm_atomics__ 1{{$}}
+// BLEEDING-EDGE-DAG:#define __wasm_mutable_globals__ 1{{$}}
// BLEEDING-EDGE-NOT:#define __wasm_unimplemented_simd128__ 1{{$}}
// RUN: %clang -E -dM %s -o - 2>&1 \
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 230c1208e54..9138683d498 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -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.
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
index ae1f3fe3946..22e11726f33 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -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/llvm/test/CodeGen/WebAssembly/mutable-globals.ll b/llvm/test/CodeGen/WebAssembly/mutable-globals.ll
new file mode 100644
index 00000000000..45b485482c8
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/mutable-globals.ll
@@ -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"
OpenPOWER on IntegriCloud