-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable swiftasynccall
calling convention with tail-call feature
#5568
Comments
-mtail-call
is enabledswiftasynccall
calling convention with tail-call feature
I tried to enable LLVM patchdiff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h
index 9484898fe1c5..87ddcf8392d8 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -155,7 +155,7 @@ private:
case CC_Swift:
return CCCR_OK;
case CC_SwiftAsync:
- return CCCR_Error;
+ return hasFeature("tail-call") ? CCCR_OK : CCCR_Error;
default:
return CCCR_Warning;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index f00d02ad4190..483b5e481c09 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
@@ -27,6 +27,7 @@
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/SelectionDAG.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
+#include "llvm/IR/CallingConv.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/Function.h"
@@ -964,7 +965,7 @@ static void fail(const SDLoc &DL, SelectionDAG &DAG, const char *Msg) {
}
// Test whether the given calling convention is supported.
-static bool callingConvSupported(CallingConv::ID CallConv) {
+static bool callingConvSupported(CallingConv::ID CallConv, const WebAssemblySubtarget *Subtarget) {
// We currently support the language-independent target-independent
// conventions. We don't yet have a way to annotate calls with properties like
// "cold", and we don't have any call-clobbered registers, so these are mostly
@@ -975,7 +976,8 @@ static bool callingConvSupported(CallingConv::ID CallConv) {
CallConv == CallingConv::PreserveAll ||
CallConv == CallingConv::CXX_FAST_TLS ||
CallConv == CallingConv::WASM_EmscriptenInvoke ||
- CallConv == CallingConv::Swift;
+ CallConv == CallingConv::Swift ||
+ (Subtarget->hasTailCall() && CallConv == CallingConv::SwiftTail);
}
SDValue
@@ -989,7 +991,7 @@ WebAssemblyTargetLowering::LowerCall(CallLoweringInfo &CLI,
auto Layout = MF.getDataLayout();
CallingConv::ID CallConv = CLI.CallConv;
- if (!callingConvSupported(CallConv))
+ if (!callingConvSupported(CallConv, Subtarget))
fail(DL, DAG,
"WebAssembly doesn't support language-specific or target-specific "
"calling conventions yet");
@@ -1273,7 +1275,7 @@ SDValue WebAssemblyTargetLowering::LowerReturn(
SelectionDAG &DAG) const {
assert((Subtarget->hasMultivalue() || Outs.size() <= 1) &&
"MVP WebAssembly can only return up to one value");
- if (!callingConvSupported(CallConv))
+ if (!callingConvSupported(CallConv, Subtarget))
fail(DL, DAG, "WebAssembly doesn't support non-C calling conventions");
SmallVector<SDValue, 4> RetOps(1, Chain);
@@ -1300,7 +1302,7 @@ SDValue WebAssemblyTargetLowering::LowerFormalArguments(
SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
- if (!callingConvSupported(CallConv))
+ if (!callingConvSupported(CallConv, Subtarget))
fail(DL, DAG, "WebAssembly doesn't support non-C calling conventions");
MachineFunction &MF = DAG.getMachineFunction(); Swift patchdiff --git a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py
index af138d71ae7..f34c9ea3392 100644
--- a/utils/swift_build_support/swift_build_support/products/wasmstdlib.py
+++ b/utils/swift_build_support/swift_build_support/products/wasmstdlib.py
@@ -97,6 +97,10 @@ class WasmStdlib(cmake_product.CMakeProduct):
self.cmake_options.define('SWIFT_PATH_TO_STRING_PROCESSING_SOURCE:PATH',
os.path.join(self.source_dir, '..',
'swift-experimental-string-processing'))
+ self.cmake_options.define('SWIFT_STDLIB_EXTRA_SWIFT_COMPILE_FLAGS:STRING',
+ '-Xcc;-mtail-call')
+ self.cmake_options.define('SWIFT_STDLIB_EXTRA_C_COMPILE_FLAGS:STRING',
+ '-mtail-call')
# Test configuration
self.cmake_options.define('SWIFT_INCLUDE_TESTS:BOOL', 'TRUE')
diff --git a/utils/wasm-run.py b/utils/wasm-run.py
index 74bacafa805..1da974f0824 100755
--- a/utils/wasm-run.py
+++ b/utils/wasm-run.py
@@ -24,7 +24,7 @@ class WasmtimeRunner(object):
subprocess.check_call(command)
def invocation(self, args):
- command = ["wasmkit-cli", "run"]
+ command = ["wasmtime", "run", "--wasm", "tail-call"]
envs = collect_wasm_env()
for key in envs:
command.append("--env")
|
WIP branch: swiftlang/llvm-project@stable/20230725...kateinoigakukun:llvm-project:yt/wasm-swifttailcc The main problem here is Wasm's call is split into two CALL_PARAMS and CALL_RESULTS, and SSP tries to insert check code among them |
Safari TP 202 shipped tail-call support https://developer.apple.com/documentation/safari-technology-preview-release-notes/stp-release-202 |
Currently, we are using simple recursive call for coroutine lowering in CoroSplit LLVM pass. However, it limits number of suspension chains due to the limitation of number of call frames.
In theory, with tail-call feature, which is now in standardizing phase, we can use
swiftasynccall
calling convention andmusttail call
to ensure the call is tail-called, and it will remove the limitation of the length of suspension chain.Blockers
The text was updated successfully, but these errors were encountered: