Skip to content
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

[Feature Request] Link-time optimization support #587

Open
Absolucy opened this issue Apr 13, 2021 · 4 comments
Open

[Feature Request] Link-time optimization support #587

Absolucy opened this issue Apr 13, 2021 · 4 comments

Comments

@Absolucy
Copy link

Absolucy commented Apr 13, 2021

It would be nice, especially for larger projects, if there was support for Clang's LTO.

It would likely require changes to the compilation process, mainly because LTO consists of emitting LLVM bitcode (.bc) files rather than object fiiles (.o), and then linking them together with LLD

This would also allow for cross-language (ObjC / C / C++ / Swift) optimization, because well, it's all bitcode in the end


    .m --clang--> .bc --LLVM--> .bc (opt) ---------+
                                                   |
    .c --clang--> .bc --LLVM--> .bc (opt) ---------+
                                                   |
                                                   +-ld+LLVM--> bin/dylib
    .swift --+                                     |
             |                                     |
    .swift --+--swiftc--> .bc --LLVM--> .bc (opt) -+
             |
    .swift --+

@kabiroberai
Copy link
Member

The structure of the compilation process seems roughly the same so I don't think it'd require many changes. Have you tried enabling LTO yourself by adding -flto to your CFLAGS and LDFLAGS? (Swift support for LTO is still WIP afaik.)

If it works for you we could consider making it a default.

@Absolucy
Copy link
Author

Oh hm, that works. I forgot why it failed for me earlier but it does now?

Also, Swift seems to have -emit-bc, and there's also this

@kabiroberai
Copy link
Member

kabiroberai commented Apr 30, 2021

Taking a look at the corresponding Swift Driver changes, it seems that enabling LTO in swiftc is as easy as -lto (EDIT: you might also need -Xfrontend -emit-bc). In conjunction with supplying -flto in the C and LDFLAGS, this should enable LTO across Theos. I'm not sure what the impact of making this the default setting would be but we could possibly add a flag to enable it; something like instance_LTO = 1.

@kirb
Copy link
Member

kirb commented Sep 12, 2021

Going to reopen as this is still of interest to the Theos team to implement.

@kirb kirb reopened this Sep 12, 2021
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

No branches or pull requests

3 participants