Writing an LLVM Pass for the new PassManager
A Pass in LLVM is the basic unit that is required to perform certain actions against LLVM IR. It is similar to a single production step in a factory, where the products that need to be processed are LLVM IR and the factory workers are the Passes. In the same way that a normal factory usually has multiple manufacturing steps, LLVM also consists of multiple Passes that are executed in sequential order, called the Pass pipeline. Figure 9.1 shows an example of the Pass pipeline:
In the preceding diagram, multiple Passes are arranged in a straight line. The LLVM IR for the foo
function is processed by one Pass after another. Pass B, for instance, performs code optimization on foo
and replaces an arithmetic multiplication (mul
) by 2 with left shifting (shl
) by 1, which is considered easier than multiplication in most hardware architectures...