[WebAssembly] Add reference types target feature
Summary:
This adds the reference types target feature. This does not enable any
more functionality in LLVM/clang for now, but this is necessary to embed
the info in the target features section, which is used by Binaryen and
Emscripten. It turned out that after D69832 `-fwasm-exceptions` crashed
because we didn't have the reference types target feature.
Reviewers: tlively
Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D73320
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp
index b16442b..ca07697 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -45,6 +45,7 @@
.Case("mutable-globals", HasMutableGlobals)
.Case("multivalue", HasMultivalue)
.Case("tail-call", HasTailCall)
+ .Case("reference-types", HasReferenceTypes)
.Default(false);
}
@@ -80,6 +81,8 @@
Builder.defineMacro("__wasm_multivalue__");
if (HasTailCall)
Builder.defineMacro("__wasm_tail_call__");
+ if (HasReferenceTypes)
+ Builder.defineMacro("__wasm_reference_types__");
}
void WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap<bool> &Features,
@@ -126,6 +129,8 @@
Features["multivalue"] = true;
if (HasTailCall)
Features["tail-call"] = true;
+ if (HasReferenceTypes)
+ Features["reference-types"] = true;
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
}
@@ -213,6 +218,14 @@
HasTailCall = false;
continue;
}
+ if (Feature == "+reference-types") {
+ HasReferenceTypes = true;
+ continue;
+ }
+ if (Feature == "-reference-types") {
+ HasReferenceTypes = false;
+ continue;
+ }
Diags.Report(diag::err_opt_not_valid_with_opt)
<< Feature << "-target-feature";