📖2015 LLVM Developers’ Meeting: Joseph Groff & Chris Lattner “Swift's High-Level IR: A Case Study..."
- url
- https://www.youtube.com/watch?v=Ntj8ab-5cvE
- slides
https://llvm.org/devmtg/2015-10/slides/GroffLattner-SILHighLevelIR.pdf
even though C/C++ are pretty low-level languages, the gap between C/C++ and LLVM IR is still great
LLVM IR is too low-level for language analysis (uninitialized, unreachable, etc), so clang developed a side pipeline
design of SIL
very similar to LLVM IR
high-level type system (including generics)
$Swift.Int is just a structure
struct Int { var value: Builtin.Int64 }
constants are instructions
attached source location
no value/constant divide
phi nodes → basic block arguments (jump with arguments)
more uniform IR
more natural
(maps nicely to CPS’s continuation call)
builtin can reference LLVM instructions directly
SIL passes
raw SIL + canonical SIL
there are some mandatory optimizations that always guaranteed run
Lowering
SILGen handles operational lowering
IRGen handles type lowering & concretization of the target
SIL is a big investment: lowering, pass manager, inliner, testing infrastructure, etc. (lots of duplication)