[all-commits] [llvm/llvm-project] 08670d: [WebAssembly] Support swiftself and swifterror for...

Yuta Saito via All-commits all-commits at lists.llvm.org
Thu Mar 19 17:42:38 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 08670d435bb41b4519bae21be87331699ccb98c8
      https://github.com/llvm/llvm-project/commit/08670d435bb41b4519bae21be87331699ccb98c8
  Author: Yuta Saito <kateinoigakukun at gmail.com>
  Date:   2020-03-19 (Thu, 19 Mar 2020)

  Changed paths:
    M llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
    M llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
    A llvm/test/CodeGen/WebAssembly/swiftcc.ll

  Log Message:
  -----------
  [WebAssembly] Support swiftself and swifterror for WebAssembly target

Summary:
Swift ABI is based on basic C ABI described here https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
Swift Calling Convention on WebAssembly is a little deffer from swiftcc
on another architectures.

On non WebAssembly arch, swiftcc accepts extra parameters that are
attributed with swifterror or swiftself by caller. Even if callee
doesn't have these parameters, the invocation succeed ignoring extra
parameters.

But WebAssembly strictly checks that callee and caller signatures are
same. https://github.com/WebAssembly/design/blob/master/Semantics.md#calls
So at WebAssembly level, all swiftcc functions end up extra arguments
and all function definitions and invocations explicitly have additional
parameters to fill swifterror and swiftself.

This patch support signature difference for swiftself and swifterror cc
is swiftcc.

e.g.
```
declare swiftcc void @foo(i32, i32)
@data = global i8* bitcast (void (i32, i32)* @foo to i8*)
define swiftcc void @bar() {
  %1 = load i8*, i8** @data
  %2 = bitcast i8* %1 to void (i32, i32, i32)*
  call swiftcc void %2(i32 1, i32 2, i32 swiftself 3)
  ret void
}
```

For swiftcc, emit additional swiftself and swifterror parameters
if there aren't while lowering. These additional parameters are added
for both callee and caller.
They are necessary to match callee and caller signature for direct and
indirect function call.

Differential Revision: https://reviews.llvm.org/D76049




More information about the All-commits mailing list