- Abhishek Bapat (abapat28@vt.edu)
- Monami Dutta Gupta (monami@vt.edu)
LLVM and Clang 11
This pass reports the following information about all the functions in a program.
* Name of the function
* Number of arguments
* Number of direct call sites
* Number of basic blocks
* Number of instructions
* Number of add, sub, mul, div and branch (conditional and unconditional) instructions.
This pass implements simple algebraic optimizations on the basic blocks.
* Algebraic identities
* Strength reduction
* Constant folding
-
We have implemented a class called IterativeFramework which is a generic framework for solving data flow analysis problems.
-
The class is instantiated with the following parameters:
* direction
* meet operator
* boundary
* initial vector
* gen vector
* kill vector
* number of basic blocks
* number of elements in the domain.
-
The iterative framework has a virtual member function called transfer function which has to be overridden in the pass with the transfer function logic.
-
Based on the transfer function the final value gets computed in the compute method.
The Available Expressions pass runs on every binary operator instruction inside every basic block to compute the domain, gen set and kill set to instantiate the iterative framework.
It prints the basic block name, gen set, kill set, IN and OUT values for every basic block.
The liveness pass runs on every instruction inside every basic block to compute the domain, use set and def set to instantiate the iterative framework.
It prints the basic block name, use set, def set, IN and OUT values for every basic block.
In this assignment we need to create passes which will improve the code by eliminating redundant and unused computations. We implement a pass for Dead Code Elimination (DCE) and another for Loop Invariant Code Motion (LICM).
- For dead code elimination, we first created a faint analysis pass which uses the Iterative Dataflow Framework that we had developed in Assignment-2.
- We compute the set of faint variables by passing the domain, gen, the dependent and constant kill sets and other relevant info to the dataflow framework.
- The dead code elimination pass takes this set of faint variables and iterates through the instructions in reverse order to determine which instructions are redundant.
- These instructions can be safely eliminated from the basic blocks which optimizes our code by reducing the number of instructions to be computed.
-
Here we need to identify and hoist loop-invariant instructions outside the loop which will reduce the number of times the instruction is performed and speed up code execution.
-
For the LICM pass to work successfully, we first need to compute the set of reaching definitions and the set of dominators. We compute these sets in two separate passes and retrieve their results in the LICM pass.
-
The reaching definitions pass helps us identify the instructions that have definitions present outside the loop, which in turn can be marked as loop invariant. Using the dominators pass we identify the instructions which dominate the use in the loop as well as the exit, and hoist only those instructions outside the loop.
-
We have implemented a landing pad to hoist out the instructions that do not dominate the exit. To implement the landing pad, we first create a new basic block between the loop header and the preheader. The loop conditions are removed from the header and moved to the preheader and also to the loop latch. This makes sure that the loop conditions are tested before executing the landing pad and the loops with a zero iteration path are taken care of.