clang questions

Two more quick questions about clang:

1) Do the different levels of optimization (-O0 through -O4)
correspond to particular optimization passes of the LLVM optimizer,
and if so, what are they, and can I apply them after-the-fact on a
program that was compiled with -O0? Not that this is necessarily
practical, but I'm just trying to understand; the idea of separate
optimization passes is intriguing.

2) Does llvm-dis have a name-demangling option, or is there an
external demangler tool? I don't want to actually change the code, but
it would be nice to see in the disassembled comments something like

; int Bar::sum2(int a, int b)
define i32 @_ZN3Bar4sum2Eii(%class.Bar* nocapture %this, i32 %a, i32
%b) nounwind readnone align 2 {

--Jason

Two more quick questions about clang:

1) Do the different levels of optimization (-O0 through -O4)
correspond to particular optimization passes of the LLVM optimizer,
and if so, what are they, and can I apply them after-the-fact on a
program that was compiled with -O0? Not that this is necessarily
practical, but I'm just trying to understand; the idea of separate
optimization passes is intriguing.

Sort of... opt -O3 runs the same optimization passes as clang -O3, but
the result won't be precisely the same because the -O flags also
affect the translation from C to IR. For debugging, the flag "-mllvm
-disable-llvm-optzns" can be useful.

2) Does llvm-dis have a name-demangling option, or is there an
external demangler tool? I don't want to actually change the code, but
it would be nice to see in the disassembled comments something like

; int Bar::sum2(int a, int b)
define i32 @_ZN3Bar4sum2Eii(%class.Bar* nocapture %this, i32 %a, i32
%b) nounwind readnone align 2 {

Have you tried just piping a .ll file through c++filt?

-Eli