What is a pass?
A lot of the interesting pieces of the LLVM infrastructure are articulated around the concept of a pass.
In a nutshell, a pass is a class that does the following:
- Encapsulates a transformation (for example, an analysis, an optimization, …)
- Describes the dependencies of this transformation (for example, the transformation needs to have access to the dominator tree analysis)
- Returns the effect of this transformation on the intermediate representation (IR) (for example, the transformation modified the control flow graph (CFG))
A pass also applies to a scope, meaning it can only modify elements within this scope. For instance, a loop-scoped pass can only modify what is within the loop that the pass is currently processing. In other words, the pass can modify all the basic blocks and instructions that live within this loop, but it is not allowed to modify unrelated loops or its parent loop (if any) or parent function, for instance...