State of Swift/LLVM Passes

Hey guys. I have a couple of questions to understand how to navigate the Swift codebase and the state of LLVM passes here. Pardon the super newbie questions :)

  • Which LLVM version is Swift (let's say 5.2) based on?
  • I have a few passes that are used to add a few extensions to the language with the usage of function annotations. Would it be easy to use an existing LLVM pass in Swift or should one create it anew?
  • If one would create a new Swift pass, is there a "hello world" example somewhere? If not, would lib/SILOptimizer/Transforms or lib/LLVMPasses be a good place to start?
  • What is SILOptimizer (and what is SIL)?
  • Finally, would Apple Appstore accept apps made with a custom-built Swift toolchain, or would they completely refuse anything outside of XCode's toolchain, even if bitcode is bundled?

Many thanks!

SIL stands for Swift Intermediate Language, it was created with the purpose of doing static analysis and generation of diagnostics after the AST and before lowering to LLVM IR.

SILOptimizer is in charge of optimizing the raw SIL to canonical SIL, it performs optimizations like constant folding etc, and also can produce really helpful diagnostics, additionally (This I am not sure of) it performs several optimizations to enhance the final result of the executable.

Here is the awesome documentation that is on the swift repository:

Additionally here is a blog post by Slava Pestov (@Slava_Pestov) which is a core member of the Swift team that wrote an in depth article about SIL.

And lastly the last resource I know of is a talk in a LLVM conference by Joseph Groff (@Joe_Groff) & Chris Lattner (@Chris_Lattner3) called Swift's High-Level IR: A Case Study...

Many thanks for your answer @gabeiglio!

Are Apple okay with non-official SIL optimization passes? Lemme rephrase: how does Apple feel about publishing away from the official XCode toolchain?

1 Like

That's an Apple policy question which isn't really right for this forums.

That said, if they do accept it, you will need to be careful not to change anything in the runtime or ABI, and to not deploy your own version of the runtime as it will conflict with the system's version.

That answers it. Many thanks @Karl!

Which LLVM version is Swift (let's say 5.2) based on?

I don't know anything about SIL but you can check this for yourself, by adding the -Xcc -v flag when compiling hello world. Here's what I get with the latest 5.2.5 release and a recent 5.3 snapshot:

> ./swift-5.2.5-RELEASE-ubuntu20.04/usr/bin/swift -Xcc -v hello.swift
clang version 7.0.0 ( c4513204aeb003122d2c69bd454ab8781298453b)

> ./swift-5.3-DEVELOPMENT-SNAPSHOT-2020-07-20-a-ubuntu18.04/usr/bin/swift -Xcc -v hello.swift
clang version 10.0.0 ( 13a8e5d9406f7191462094c45d30b49c342ef5eb)

This tells you the version of libclang that the Swift compiler has baked in, along with a bunch of other clang info that I've snipped. Since Swift uses a forked LLVM, I suppose it's theoretically possible that's only the version of libclang and not the underlying LLVM, but the build scripts and CMake config all show those same versions for LLVM too.

For documentation, you might want to look at docs/ and docs/ in the repository.

For the App Store policies, you probably want to consult the App Store Guidelines:

Apps distributed via the Mac App Store have some additional requirements to keep in mind:


  • (ii) They must be packaged and submitted using technologies provided in Xcode; no third-party installers allowed. They must also be self-contained, single application installation bundles and cannot install code or resources in shared locations.

or ask the support team

Terms of Service

Privacy Policy

Cookie Policy