<html><body><p><tt>Thanks for your responses so far. It took me a while to fully appreciate</tt><br><tt>what all this means.</tt><br><br><tt>I have read through John's mail thread on llvm-dev about adding the swiftcc</tt><br><tt>convention to LLVM/Clang. I don't think that discussion mentioned adding</tt><br><tt>Clang support for C++ functions returning aggregates in multiple registers</tt><br><tt>for targets that currently use sret, because, in John's words, "we don't</tt><br><tt>use the Swift CC to call C functions." But aren't these runtime functions</tt><br><tt>using TwoWordPair::Return doing exactly that?</tt><br><br><tt>On i386 and ARM, the TwoWordPair::Return type is masqueraded as a 64-bit</tt><br><tt>unsigned long long so that the returned values are passed in a register</tt><br><tt>pair. This trick is not portable, and infeasible on at least s390x.</tt><br><br><tt>A portable solution would be to implement such runtime functions in Swift,</tt><br><tt>and make them retrieve the needed results from two calls to C++, instead</tt><br><tt>of one call to a C++ function that returns a pair. The Swift function</tt><br><tt>can then return value pairs as usual. This seems much cleaner and simpler.</tt><br><br><tt>Bryan</tt><br><br><br><tt>rjmccall@apple.com wrote on 2016-03-22 03:51:52 PM:<br><br>> On Mar 22, 2016, at 12:25 PM, Joe Groff <jgroff@apple.com> wrote:</tt><br><tt>> > On Mar 22, 2016, at 12:06 PM, Bryan Chan <bryan.chan@ca.ibm.com> wrote:</tt><br><tt>> > <br>> > > jgroff@apple.com wrote on 2016-03-22 02:37:47 PM:<br>> > > <br>> > > > The runtime functions are hacked in various unsavory ways to give <br>> > > > them Swift-like calling conventions. Many of them also have <br>> > > > important semantics that the compiler needs to be aware of, so if <br>> > > > they aren't exported as standard library API in some way, you really<br>> > > > shouldn't interact with them directly. <br>> > > > (swift_class_getInstanceExtents happens to be OK, but what are you <br>> > > > trying to do with it?)<br>> > > <br>> > > I am trying to build Swift on a different architecture (s390x). This<br>> > > function was causing crashes due to the ABI mismatch, and I also<br>> > > found that the issue is not 100% fixed on x86 either, so I wondered<br>> > > if the community has an opinion on the right way to deal with this<br>> > > in the runtime, or if the answer is simply "don't do this for<br>> > > 3-scalar returns".</tt><br><tt>> ></tt><br><tt>> > Yeah, there's no good way right now to return three scalars from <br>> > Clang. swift_class_getInstanceExtents and a few other runtime <br>> > entrypoints like allocBox and allocError use the <br>> > `TwoWordPair::Return` hack to use types that happen to return in two<br>> > registers on i386, x86_64, armv7, and arm64. If s390x's C ABI <br>> > doesn't define any such types, you might need to wait for proper <br>> > support for Swift calling conventions in Clang. I believe it's on <br>> > John McCall's near-term todo list to do that.</tt><br><tt>> <br>> To be clear, you'll still need to implement the swiftcc convention <br>> for your target in LLVM/clang, so it will still take some compiler <br>> implementation expertise to get right. But at least the <br>> compatibility assumptions will be explicit.</tt><BR>
</body></html>