How to see the changes made by llvm transformation passes

1.3k Views Asked by At

How to see the changes made by transformation passes(like dead code elimination) in the c program.Like if I run following command on terminal it create a .bc file by which I can see the IR. But how to see the changes made by -dce in c program. command: $opt in.bc -o out.bc -dce

3

There are 3 best solutions below

2
On

You cannot see the changes made in the IR reflected in your C code - there's no transformation back. (Well there used to be a C back-end for LLVM, but (1) it's no longer supported and (2) it only preserves the semantics of your program, not its form).

What you can do is compile with debug info, and from the LLVM side query that info after the DCE to try and deduce how the pass affected your source code.

Alternatively, if it's important for you to be able to do transformations directly on the source code, you should be using something like Clang's frontend actions - but you'll have to implement a lot of logic yourself there, and you could not enjoy LLVM's optimization passes.

0
On

I think you can't see the changes in the c program.

The LLVM transformation passes work on the LLVM IR. So you can generate the LLVM IR (.ll format) corresponding to the c program. When you get the .bc file output of the pass, you can translate the .bc file to .ll format. Then you can compare the two .ll files, you can see the changes made by the pass (like: dce).

0
On

If your applying the DCE pass and would like to identify the modifications made by the Pass, I would suggest using llvm-nm. llvm-nm allows you view the symbols inside the bitcode file, including functions and data objects. By comparing the output of llvm-nm for the original bitcode file, and the optimized version, you can identify the functions that were removed by the DCE Pass