Skip to content

Lower Swiftcc by LLVM #371

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

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Mar 12, 2020

This PR is based on swiftwasm/llvm-project#3 and reviews.llvm.org/D76049

Changes

Revert thin-to-thick forwarder things

As @jckarter said, I changed LLVM to add extra swiftself and swifterror arguments while lowering LLVM IR into WebAssembly binary.

After this change, thin-to-thick forwarder is not necessary anymore, so I reverted #186 .
Actually thin-to-thick forwarder has reference counting bug which causes #331 issue. This new strategy resolves the issue also.

Add swiftcc attribute to runtime functions called from Swift code

After the LLVM change, all functions declared in Swift code always has swiftself and swifterror because they use swiftcc. But this causes type mismatch while linking because C++ side function declaration didn't have swiftcc attribute.

For example,

@_silgen_name("swift_retainCount")
public func _getRetainCount(_ Value: AnyObject) -> UInt
size_t swift::swift_retainCount(HeapObject *object) {
  ...
}

This Swift function is lowered as (i32, i32, i32) -> i32 function but the C++ side runtime function is lowered as (i32) -> i32. So I added swiftcc attribute to runtime functions linked with Swift using @_silgen_name.

@kateinoigakukun kateinoigakukun force-pushed the katei/swiftcc-lowering-rebase branch 2 times, most recently from 3dfec77 to a54d888 Compare March 12, 2020 02:05
@kateinoigakukun kateinoigakukun marked this pull request as ready for review March 12, 2020 10:48
@kateinoigakukun kateinoigakukun force-pushed the katei/swiftcc-lowering-rebase branch from a54d888 to a4814df Compare March 14, 2020 11:54
call->setAttributes(attrs);
// Remove swiftself and swifterror attribute to match signature generated from
// RuntimeFunctions.def. These two parameters are passed using swifterror and swiftself,
// but the definition of swift_willThrow generated from the def file doesn't has those

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// but the definition of swift_willThrow generated from the def file doesn't has those
// but the definition of swift_willThrow generated from the def file doesn't have those

// Notes:
// Remove swiftself and swifterror attribute to match signature generated from
// RuntimeFunctions.def. These two parameters are passed using swifterror and swiftself,
// but the definition of swift_willThrow generated from the def file doesn't has those

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// but the definition of swift_willThrow generated from the def file doesn't has those
// but the definition of swift_willThrow generated from the def file doesn't have those

Copy link

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit, just a minor comment typo

Copy link

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge 👍

@kateinoigakukun kateinoigakukun merged commit 30d34e9 into swiftwasm:swiftwasm Mar 15, 2020
pull bot pushed a commit that referenced this pull request May 25, 2021
Revert "Revert "[Build] Make cmark build a build-script product (#371
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants