From c78bf8703eb7a482709e75d6bcf9fbdd15b47b2b Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Tue, 9 Apr 2019 19:58:04 -0700 Subject: [PATCH 1/4] WebAssembly: allow swiftcall attribute This removes the warning when attempting to compile a swiftcall function. I'm not sure why https://reviews.llvm.org/D19414 didn't add this... --- lib/Basic/Targets/WebAssembly.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Basic/Targets/WebAssembly.h b/lib/Basic/Targets/WebAssembly.h index 9665156b143..55d90db267e 100644 --- a/lib/Basic/Targets/WebAssembly.h +++ b/lib/Basic/Targets/WebAssembly.h @@ -114,6 +114,16 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { ? (IsSigned ? SignedLongLong : UnsignedLongLong) : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned); } + + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { + switch (CC) { + case CC_C: + case CC_Swift: + return CCCR_OK; + default: + return CCCR_Warning; + } + } }; class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo : public WebAssemblyTargetInfo { From 44c0dde0b273f06bf362a1fa97b5479f0697b848 Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Wed, 10 Apr 2019 17:48:58 -0700 Subject: [PATCH 2/4] hack: define __EMSCRIPTEN__ when compiling to wasm Too lazy to backport the Emscripten target to this version of LLVM --- lib/Basic/Targets/WebAssembly.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Basic/Targets/WebAssembly.cpp b/lib/Basic/Targets/WebAssembly.cpp index b16442b99b6..d4560b8e573 100644 --- a/lib/Basic/Targets/WebAssembly.cpp +++ b/lib/Basic/Targets/WebAssembly.cpp @@ -60,6 +60,8 @@ void WebAssemblyTargetInfo::fillValidCPUList( void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { defineCPUMacros(Builder, "wasm", /*Tuning=*/false); + // HACK: too lazy to backport the -emscripten target here + Builder.defineMacro("__EMSCRIPTEN__"); if (SIMDLevel >= SIMD128) Builder.defineMacro("__wasm_simd128__"); if (SIMDLevel >= UnimplementedSIMD128) From bfaa96e79a0cb30cad9a86c14dd65dca02933210 Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Fri, 12 Apr 2019 22:24:09 -0700 Subject: [PATCH 3/4] Switch to a WASI define --- lib/Basic/Targets/WebAssembly.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Basic/Targets/WebAssembly.cpp b/lib/Basic/Targets/WebAssembly.cpp index d4560b8e573..78402153a7c 100644 --- a/lib/Basic/Targets/WebAssembly.cpp +++ b/lib/Basic/Targets/WebAssembly.cpp @@ -60,8 +60,10 @@ void WebAssemblyTargetInfo::fillValidCPUList( void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { defineCPUMacros(Builder, "wasm", /*Tuning=*/false); - // HACK: too lazy to backport the -emscripten target here - Builder.defineMacro("__EMSCRIPTEN__"); + // HACK: too lazy to backport the WASI target here + Builder.defineMacro("__wasi__"); + // HACK: globally enable WASI mmap emulation + Builder.defineMacro("_WASI_EMULATED_MMAN"); if (SIMDLevel >= SIMD128) Builder.defineMacro("__wasm_simd128__"); if (SIMDLevel >= UnimplementedSIMD128) From 8676838ae3d4657f9209581b4320e013c38e65dd Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Fri, 19 Apr 2019 13:17:06 -0700 Subject: [PATCH 4/4] WebAssembly: default to disabling exceptions on WebAssembly --- lib/Driver/ToolChains/Clang.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index a126b764dea..8cb8760eabe 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -448,6 +448,9 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, // Disable C++ EH by default on XCore and PS4. bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU(); + // WebAssembly: no exception handling on WASI + if (Triple.isOSBinFormatWasm()) + CXXExceptionsEnabled = false; Arg *ExceptionArg = Args.getLastArg( options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, options::OPT_fexceptions, options::OPT_fno_exceptions);