swift icon indicating copy to clipboard operation
swift copied to clipboard

[Driver][Frontend] Introduce `load-pass-plugin` option

Open antoniofrighetto opened this issue 1 year ago • 16 comments

Allow dynamic loading of LLVM passes via load-pass-plugin option passed to the Swift compiler driver, similarly to current Apple Clang -fpass-plugin option.

Previous discussion: https://forums.swift.org/t/load-external-llvm-pass-plugins-via-swift-frontend/67596

antoniofrighetto avatar Oct 05 '23 14:10 antoniofrighetto

Please, let me know if anything needs to be improved as far as style conventions et alia is concerned, I'd be happy to do so.

antoniofrighetto avatar Oct 05 '23 14:10 antoniofrighetto

(cc/ @DougGregor)

antoniofrighetto avatar Oct 05 '23 15:10 antoniofrighetto

Gentle ping. Any feedback or suggestions would be duly appreciated. Alongside this, I believe the option should be added as part of Options.swift as well. May that be the case? (cc/ @DougGregor, @rintaro).

antoniofrighetto avatar Oct 17 '23 16:10 antoniofrighetto

Hey, this may not be getting much attention because the internal driver (this one) is considered legacy. The default driver as of Xcode 13 swift-driver. You might have better luck over there.

Note: I'm not affiliated with the Swift project in any way. Just a guy who'd love to see this merged

jslegendre avatar Oct 19 '23 03:10 jslegendre

There was some discussion on this previously in: https://github.com/apple/swift/pull/38017

The driver and frontend pieces are separate and yes, proper driver support would mean adding the logic in https://github.com/apple/swift-driver. Legacy (C++-based) driver support being optional/discouraged.

@lhames @aschwaighofer can comment better on the architecture of loading such passes in IRGen.

artemcm avatar Oct 19 '23 17:10 artemcm

Thanks a lot to both for the helpful insights. Support in the new swift-driver should be addressed by https://github.com/apple/swift-driver/pull/1472. The implementation should aim to ensure a clear separation between the driver and the frontend. Also, thanks for sharing #38017, was not aware of this. Reviewed the discussion there carefully, it was very informative.

antoniofrighetto avatar Oct 23 '23 16:10 antoniofrighetto

Fixed conflicts by rebasing to main, and changed test library type from MODULE to SHARED, as CMake seems to be defaulting to generate the plugin with .so extension on macOS too (rather than .dylib, this was previously leading the unittest to fail).

antoniofrighetto avatar Oct 27 '23 14:10 antoniofrighetto

Gentle ping (cc/ @lhames).

antoniofrighetto avatar Nov 14 '23 20:11 antoniofrighetto

Just wanted to express support for this here as it also helps with adding plugins for AD

wsmoses avatar Nov 22 '23 19:11 wsmoses

Also expressing support for this!

jslegendre avatar Nov 23 '23 01:11 jslegendre

Rebased to main, dropped unittest in Driver as part of recent legacy driver deprecation, added test coverage exercizing performLLVMOptimization. New driver support ready at https://github.com/apple/swift-driver/pull/1472. Kind ping @lhames, @aschwaighofer, @artemcm, @benlangmuir, @weliveindetail.

antoniofrighetto avatar Jan 22 '24 16:01 antoniofrighetto

@lhames, @airspeedswift Gentle ping. Any chance of this getting reviewed?

antoniofrighetto avatar Mar 25 '24 20:03 antoniofrighetto

Kind ping (maybe cc/ @adrian-prantl).

antoniofrighetto avatar Apr 16 '24 09:04 antoniofrighetto

@adrian-prantl Addressed comments and rebased to main, thank you for reviewing this!

antoniofrighetto avatar Apr 30 '24 18:04 antoniofrighetto

@swift-ci test

adrian-prantl avatar May 01 '24 00:05 adrian-prantl

Rebased to main, opened sister PR @ https://github.com/apple/llvm-project/pull/8678, reflecting changes (not sure if we should have targeted a different branch instead).

antoniofrighetto avatar May 02 '24 09:05 antoniofrighetto

@adrian-prantl Kind ping on this, CI was previously failing.

antoniofrighetto avatar May 16 '24 16:05 antoniofrighetto

Rebased to main (fixed conflicts), https://github.com/swiftlang/llvm-project/pull/8678 PR rebased to stable/20230725, which should be the expected branch. Very gentle remainder. I do not have commit access, could anyone kindly merge this?

antoniofrighetto avatar Jul 31 '24 17:07 antoniofrighetto

I assume this should be tested with:

Please test with following PR:
https://github.com/swiftlang/llvm-project/pull/8678
https://github.com/swiftlang/swift-driver/pull/1472

@swift-ci Please test

antoniofrighetto avatar Jul 31 '24 19:07 antoniofrighetto

https://github.com/swiftlang/llvm-project/pull/8678 https://github.com/swiftlang/swift-driver/pull/1472

@swift-ci test

JDevlieghere avatar Sep 09 '24 15:09 JDevlieghere

The macOS failure is:

/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/swift/stdlib/private/SwiftPrivate/IO.swift:21:8: error: failed to build module 'Darwin'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.9.2 (swiftlang-5.9.2.2.11 clang-1500.1.0.2.2)', while this compiler is 'Apple Swift version 6.1-dev effective-5.10 (LLVM 97c65ef47934098, Swift c06508954544f05)'). Please select a toolchain which matches the SDK.
 19 | #else
 20 | #if canImport(Darwin)
 21 | import Darwin
    |        `- error: failed to build module 'Darwin'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 5.9.2 (swiftlang-5.9.2.2.11 clang-1500.1.0.2.2)', while this compiler is 'Apple Swift version 6.1-dev effective-5.10 (LLVM 97c65ef47934098, Swift c06508954544f05)'). Please select a toolchain which matches the SDK.

edit: should have been fixed by https://github.com/swiftlang/swift/pull/76344

JDevlieghere avatar Sep 10 '24 02:09 JDevlieghere

https://github.com/swiftlang/llvm-project/pull/8678 https://github.com/swiftlang/swift-driver/pull/1472

@swift-ci test macos

JDevlieghere avatar Sep 10 '24 02:09 JDevlieghere