Repeated application of optimization passes

Within the LLVM pass manager infrastructure, suppose we have two transformation passes, pass A makes some improvements, then pass B does likewise, but this creates opportunities for pass A to create further improvements (e.g. suppose B was function inlining) so it’s desirable to run A again.

How does the LLVM pass manager currently deal with this?

Some passes are already applied repeatedly by the passmanager, just add
them twice when relevant.

for instance in lib/Transforms/IPO/PassManagerBuilder.cpp,

MPM.add(createGVNPass(...)) is called twice (conditionnaly)

Hope it helps,

I don’t suppose there’s any way to find out whether the second iteration did anything? That is, suppose you have a module and you run some passes over it - if something changed, further iterations might be fruitful, but if nothing changed then further iterations definitely won’t do anything so you can stop. In principle one could make a copy of the module beforehand and then compare, but being a large complex data structure, it probably doesn’t provide equality comparison by value?

What you’re looking for is a dynamic pass pipeline, which the current pass manager can’t support. But I believe the new pass manager will be able to at least express this.