[LLVMdev] New idea thoughts: Optimization passes have callbacks to identify changes made to IR

Greg Fitzgerald garious at gmail.com
Tue Feb 17 13:39:07 PST 2015


On Tue, Feb 17, 2015 at 12:01 PM, Hayden Livingston
<halivingston at gmail.com> wrote:
> I'm currently developing a tool based on LLVM to understand how the LLVM IR
> changes after optimization passes are run.
>
> Today it's a tedious but automatic process at a function level in my
> language, where I first dump the IR before running any passes, and then do
> it for the 10 or so passes I care about one-at-a-time to understand which
> pass affected the change.

I have a tool that, diffdump.  I use it to diff the output of opt with
various optimization passes enabled.

    https://github.com/garious/diffdump

For example, to see what constprop does to the IR:

    $ diffdump -u --cmd=opt --arg=-S --arg2=-constprop basictest.ll

Gives you an output:

diff -u a/dump.txt b/dump.txt
--- a/dump.txt  2012-10-31 11:28:31.000000000 -0700
+++ b/dump.txt  2012-10-31 11:28:31.000000000 -0700
@@ -6,34 +6,28 @@
   br i1 %B, label %BB1, label %BB2

 BB1:                                              ; preds = %0
-  %Val = add i32 0, 0
   br label %BB3

 BB2:                                              ; preds = %0
   br label %BB3

 BB3:                                              ; preds = %BB2, %BB1
-  %Ret = phi i32 [ %Val, %BB1 ], [ 1, %BB2 ]
+  %Ret = phi i32 [ 0, %BB1 ], [ 1, %BB2 ]
   ret i32 %Ret
 }


-Greg



More information about the llvm-dev mailing list