standard passes

I'd like to hack into the standard passes when using the command line
option -std-compile-opts. What I'd like to do is to stop after each
pass and see the current program representation before the next pass is
run in gdb. What is the favorite way to do this?

Lu

If you're in GDB, then use something like this:

  M->dump()

where M is the current Module. You can execute the same call with Function, BasicBlock, etc.

If you're running opt on the command line directly, then use the "-p" option. See "-help" for more information on that.

-bw

If you're running opt on the command line directly, then use the
"-p" option. See "-help" for more information on that.

-bw

I have a couple of more questions.

1. Does -std-compile-opts of opt do the same optimization with llvm-gcc
with -O[1-3] options? If I want to debug into passes through llvm-gcc,
how do I set a breakpoint right before pass execution? In my gdb
llvm-gcc session, I don't have llvm::PassManager available.

2. When I use "-p" with opt, there is nothing I can see from the
output. Instead, "--debug-pass=Details" gives me more detailed info. Did
I miss other stuffs that are required to be with "-p?"

Thanks.
Lu

If you're running opt on the command line directly, then use the
"-p" option. See "-help" for more information on that.

-bw

I have a couple of more questions.

1. Does -std-compile-opts of opt do the same optimization with llvm-gcc
with -O[1-3] options?

The does not map -O[1-3] options directly.

If I want to debug into passes through llvm-gcc,
how do I set a breakpoint right before pass execution? In my gdb
llvm-gcc session, I don't have llvm::PassManager available.

You have access to PerFunctionPasses and PerModulePasses.

Hi,

1. Does -std-compile-opts of opt do the same optimization with llvm-gcc
with -O[1-3] options?

almost but not quite. Firstly, llvm-gcc won't schedule all passes
unless the optimization level is high enough. It won't unroll loops
unless given -funroll-loops etc.

That said, there are a few curious differences between llvm-gcc and
opt. I'm not sure if they are intentional or a mistake:

- llvm-gcc schedules the SimplifyLibCalls pass near the beginning,
opt near the end.

- opt schedules DeadTypeElimination followed by ConstantMerge; while
llvm-gcc schedules ConstantMerge followed by StripDeadPrototypes.
So opt doesn't run StripDeadPrototypes while llvm-gcc
doesn't run DeadTypeElimination.

- opt schedules LowerSetJmp while llvm-gcc does not.

Finally, llvm-gcc runs the following passes on each function
immediately after it is created:

CFGSimplification, PromoteMemoryToRegister,
ScalarReplAggregates, InstructionCombining.

These sometimes mean you get better code from llvm-gcc than
from opt.

If I want to debug into passes through llvm-gcc,
how do I set a breakpoint right before pass execution? In my gdb
llvm-gcc session, I don't have llvm::PassManager available.

Break on a line number in the appropriate file.

2. When I use "-p" with opt, there is nothing I can see from the
output. Instead, "--debug-pass=Details" gives me more detailed info. Did
I miss other stuffs that are required to be with "-p?"

I never managed to get -p to work. With opt I use -debug-pass=Arguments
and with llvm-gcc -fdebug-pass-arguments

Ciao,

Duncan.