A completely mostly useless LLVM pass. Based on the tutorial by Adrian Sampson (@sampsyo).
Build:
$ cd llvm-pass-skeleton
$ mkdir build
$ cd build
$ cmake ..
$ make
$ cd ..
Run:
$ clang -Xclang -load -Xclang build/skeleton/libSkeletonPass.* something.c helpers.c
This modified pass inserts calls to simple functions that print out messages when certain reducible operations are executed. The flagged operations are:
a + 0
- Could be replaced bya
a - 0
- Could be replaced bya
a * 0
- Could be replaced by0
a / 1
(int div) - Could be replaced bya
a * 1
- Could be replaced bya
a & 0
- Could be replaced by0
a ^ 0
- Could be replaced bya
a | -1
- Could be replaced by-1
a ^ a
- Could be replaced by0
a | a
- Could be replaced bya
a & a
- Could be replaced bya
The pass doesn't remove any of these actions, it just places a call to the printing function after the computation. This will in fact make the program execute slower which we can pretend is a means of discouraging such behavior.