aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/Targets/WebAssembly.cpp
diff options
context:
space:
mode:
authorDan Gohman <dev@sunfishcode.online>2024-12-02 17:08:07 -0800
committerGitHub <noreply@github.com>2024-12-02 17:08:07 -0800
commitc3536b263f253a69fb336fb0617ee33a01a5c5dd (patch)
tree3be2dbe8cdd9338a7a5ee3e7ef60cfea762478fd /clang/lib/Basic/Targets/WebAssembly.cpp
parentf71ea4bc1b01fd7e29048db82b3e21fba74e8dab (diff)
downloadllvm-c3536b263f253a69fb336fb0617ee33a01a5c5dd.zip
llvm-c3536b263f253a69fb336fb0617ee33a01a5c5dd.tar.gz
llvm-c3536b263f253a69fb336fb0617ee33a01a5c5dd.tar.bz2
[WebAssembly] Define call-indirect-overlong and bulk-memory-opt features (#117087)
This defines some new target features. These are subsets of existing features that reflect implementation concerns: - "call-indirect-overlong" - implied by "reference-types"; just the overlong encoding for the `call_indirect` immediate, and not the actual reference types. - "bulk-memory-opt" - implied by "bulk-memory": just `memory.copy` and `memory.fill`, and not the other instructions in the bulk-memory proposal. This is split out from https://github.com/llvm/llvm-project/pull/112035. --------- Co-authored-by: Heejin Ahn <aheejin@gmail.com>
Diffstat (limited to 'clang/lib/Basic/Targets/WebAssembly.cpp')
-rw-r--r--clang/lib/Basic/Targets/WebAssembly.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index 0b380bd..d9d01bc 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -47,6 +47,8 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
return llvm::StringSwitch<bool>(Feature)
.Case("atomics", HasAtomics)
.Case("bulk-memory", HasBulkMemory)
+ .Case("bulk-memory-opt", HasBulkMemoryOpt)
+ .Case("call-indirect-overlong", HasCallIndirectOverlong)
.Case("exception-handling", HasExceptionHandling)
.Case("extended-const", HasExtendedConst)
.Case("fp16", HasFP16)
@@ -79,6 +81,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__wasm_atomics__");
if (HasBulkMemory)
Builder.defineMacro("__wasm_bulk_memory__");
+ if (HasBulkMemoryOpt)
+ Builder.defineMacro("__wasm_bulk_memory_opt__");
if (HasExceptionHandling)
Builder.defineMacro("__wasm_exception_handling__");
if (HasExtendedConst)
@@ -155,6 +159,8 @@ bool WebAssemblyTargetInfo::initFeatureMap(
const std::vector<std::string> &FeaturesVec) const {
auto addGenericFeatures = [&]() {
Features["bulk-memory"] = true;
+ Features["bulk-memory-opt"] = true;
+ Features["call-indirect-overlong"] = true;
Features["multivalue"] = true;
Features["mutable-globals"] = true;
Features["nontrapping-fptoint"] = true;
@@ -200,6 +206,22 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasBulkMemory = false;
continue;
}
+ if (Feature == "+bulk-memory-opt") {
+ HasBulkMemoryOpt = true;
+ continue;
+ }
+ if (Feature == "-bulk-memory-opt") {
+ HasBulkMemoryOpt = false;
+ continue;
+ }
+ if (Feature == "+call-indirect-overlong") {
+ HasCallIndirectOverlong = true;
+ continue;
+ }
+ if (Feature == "-call-indirect-overlong") {
+ HasCallIndirectOverlong = false;
+ continue;
+ }
if (Feature == "+exception-handling") {
HasExceptionHandling = true;
continue;
@@ -310,6 +332,18 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
<< Feature << "-target-feature";
return false;
}
+
+ // bulk-memory-opt is a subset of bulk-memory.
+ if (HasBulkMemory) {
+ HasBulkMemoryOpt = true;
+ }
+
+ // The reference-types feature included the change to `call_indirect`
+ // encodings to support overlong immediates.
+ if (HasReferenceTypes) {
+ HasCallIndirectOverlong = true;
+ }
+
return true;
}