Writing a simple constant propagation optimization
To help you master LLVM APIs, this section offers a hands-on exercise where you will implement your own constant propagation optimization at the LLVM IR level.
To be able to complete this exercise, you will have to take a closer look at the APIs of the classes that we introduced earlier, mainly the Module
, Function
, BasicBlock
, and Instruction
classes, but believe it or not, you have been exposed to almost everything you need to be able to do that.
A possible solution is given in ch4/simple_constant_propagation
, and the README.md
file in this directory explains how to use your implementation in the provided framework.
Before we give you the few APIs that you need to complete this exercise, let us introduce the problem properly.
The optimization
The constant propagation optimization is as simple as it sounds: you find constant values in your programs, and you try to form more constants by simulating the computations...