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 Answers
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.

- 26,231
- 8
- 93
- 152
-
I want to make a sample pass for extracting loop information like loop induction variable names their boundaries. So how should start writing a pass because there are lots of file on loops like LoopPass,LoopInfo,LoopExtractor etc and I just struck on how to use the function which function or which file be useful for me. I have already gone through this link:http://llvm.org/docs/WritingAnLLVMPass.html#introduction-what-is-a-pass – user2167322 Jul 23 '13 at 17:39
-
@user2167322 for best results, ask a new question about that on stackoverflow and see if someone can help you. – Oak Jul 23 '13 at 19:33
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).

- 79
- 5
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

- 81
- 1
- 4