[llvm-dev] pass invalidation

serge guelton via llvm-dev llvm-dev at lists.llvm.org
Sun Jun 19 00:59:49 PDT 2016


On Sun, Jun 19, 2016 at 05:44:01AM +0000, Yuxi Chen via llvm-dev wrote:
> Hi All,
> 
> When I use llvm, I encounter a problem like "unable to schedule pass A required by C"
> I investigated deeper. It's like:
> I have three passes, say A, B, C(all are on function level)
> A would modify IR code. (change instruction order)
> 
> For pass B,
> I would use the result of pass A, I use addRequired<B>(), and &getAnalysis<B>(), it works.
> 
> void getAnalysisUsage(AU){
> AU.addRequired<A>();
> }
> 
> 
> For pass C, it will use the results of pass A and B.
> I use the way as used for pass B, but it failed, even for LoopInfo analysis pass(which is the built-in analysis pass).
> void getAnalysisUsage(AU){
> AU.addRequired<A>();
> AU.addRequired<B>();
> }
> 
> 
> It seems because A would modify IR code, so for pass C, I need first load pass A then pass B, otherwise it will be invalidated.
> However, when I change the using order, I still got error "unable to schedule pass A required by C".
> 
> Does anyone encounter the same problem before and have a solution?
> Any help is appreciated.

Hi,

It looks like A is not an analyse, as it modifies IR code, while
analysis don't modify IR. You cannot specify this kind of dependencies
in the getAnalysisUsage method.

What you can do though is create a pass ABC that spawns a new
Passmanager that calls A, B and C in that order, something like:

    llvm::legacy::FunctionPassManager FPM(Module);
    FPM.add(createA());
    FPM.add(createB());
    FPM.add(createC());

    bool modified = false;
    modified |= FPM.doInitialization();
    for (Function &F : Module)
      modified |= FPM.run(F);
    modified |= FPM.doFinalization();


More information about the llvm-dev mailing list