Another Pass Manager Assertion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Another Pass Manager Assertion

John Criswell
Dear All,

The attached code (which is a contrived test case) hits the following
assertion:

test:
/home/vadve/criswell/src/llvm22/include/llvm/PassAnalysisSupport.h:226:
AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*,
llvm::Function&) [with AnalysisType = Pass1]: Assertion `ResultPass &&
"getAnalysis*() called on an analysis that was not " "'required' by
pass!"' failed.
Abort

Does anyone see anything wrong with my use of the pass manager
interface?  As far as I can tell, the code looks correct.

-- John T.


#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/PassManager.h"
#include "llvm/Type.h"

using namespace llvm;

struct Pass1 : public FunctionPass {
  public :
    static char ID;
    Pass1 () : FunctionPass ((intptr_t) &ID) {}
    const char *getPassName() const { return "Pass 1"; }
    virtual bool runOnFunction(Function &F) {
      return false;
    }
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      return;
    }
};

struct BottomPass : public ModulePass {
  public :
    static char ID;
    BottomPass () : ModulePass ((intptr_t) &ID) {
    }
    const char *getPassName() const { return "Bottom Pass"; }
    virtual bool runOnModule(Module &M) {
      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
        Function &F = *I;
        Pass1 &P = getAnalysis<Pass1>(F);
      }
      return false;
    }
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<Pass1>();
    }
};

int main(int argc, char **argv) {
  Module M("testmodule");
  M.getOrInsertFunction ("main", Type::VoidTy, NULL);
  PassManager Passes;
  Passes.add(new BottomPass());
  Passes.run(M);
  return 1;
}

char Pass1::ID = 0;
char BottomPass::ID = 0;

RegisterPass<Pass1> R1("p1","Pass 1");
RegisterPass<BottomPass> R3("b","Bottom Pass");


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Another Pass Manager Assertion

Devang Patel

On Dec 18, 2007, at 10:55 AM, John Criswell wrote:

> Dear All,
>
> The attached code (which is a contrived test case) hits the following
> assertion:
>
> test:
> /home/vadve/criswell/src/llvm22/include/llvm/PassAnalysisSupport.h:
> 226:
> AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*,
> llvm::Function&) [with AnalysisType = Pass1]: Assertion `ResultPass &&
> "getAnalysis*() called on an analysis that was not " "'required' by
> pass!"' failed.
> Abort
>
> Does anyone see anything wrong with my use of the pass manager
> interface?  As far as I can tell, the code looks correct.

Your pass manager interface is OK.

You are requesting PassManager to make a Function level analysis pass  
(Pass1) available to Module level transformation pass (BottomPass).  
In real life you could use it to request Dominator information for a  
module level pass. This is supported and it works. The reason it fails  
for your test case is that the function "main" is just a declaration.  
There is no analysis info to generate.

If you add a "main" function body in your module then it should work.  
Or you should check whether F.isDeclaration() is true or not before  
invoking getAnalysis<Pass1>(F);

I agree, the assertion message is not very helpful here.

-
Devang


> -- John T.
>
> #include "llvm/Pass.h"
> #include "llvm/Module.h"
> #include "llvm/PassManager.h"
> #include "llvm/Type.h"
>
> using namespace llvm;
>
> struct Pass1 : public FunctionPass {
>  public :
>    static char ID;
>    Pass1 () : FunctionPass ((intptr_t) &ID) {}
>    const char *getPassName() const { return "Pass 1"; }
>    virtual bool runOnFunction(Function &F) {
>      return false;
>    }
>    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>      return;
>    }
> };
>
> struct BottomPass : public ModulePass {
>  public :
>    static char ID;
>    BottomPass () : ModulePass ((intptr_t) &ID) {
>    }
>    const char *getPassName() const { return "Bottom Pass"; }
>    virtual bool runOnModule(Module &M) {
>      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
>        Function &F = *I;
>        Pass1 &P = getAnalysis<Pass1>(F);
>      }
>      return false;
>    }
>    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>      AU.addRequired<Pass1>();
>    }
> };
>
> int main(int argc, char **argv) {
>  Module M("testmodule");
>  M.getOrInsertFunction ("main", Type::VoidTy, NULL);
>  PassManager Passes;
>  Passes.add(new BottomPass());
>  Passes.run(M);
>  return 1;
> }
>
> char Pass1::ID = 0;
> char BottomPass::ID = 0;
>
> RegisterPass<Pass1> R1("p1","Pass 1");
> RegisterPass<BottomPass> R3("b","Bottom Pass");
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-
Devang



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Another Pass Manager Assertion

John Criswell-2
Devang Patel wrote:
> On Dec 18, 2007, at 10:55 AM, John Criswell wrote:
>  
Thanks!.  I didn't realize that functions needed bodies in order to pull
up their analysis information.

-- John T.

>  
>> Dear All,
>>
>> The attached code (which is a contrived test case) hits the following
>> assertion:
>>
>> test:
>> /home/vadve/criswell/src/llvm22/include/llvm/PassAnalysisSupport.h:
>> 226:
>> AnalysisType& llvm::Pass::getAnalysisID(const llvm::PassInfo*,
>> llvm::Function&) [with AnalysisType = Pass1]: Assertion `ResultPass &&
>> "getAnalysis*() called on an analysis that was not " "'required' by
>> pass!"' failed.
>> Abort
>>
>> Does anyone see anything wrong with my use of the pass manager
>> interface?  As far as I can tell, the code looks correct.
>>    
>
> Your pass manager interface is OK.
>
> You are requesting PassManager to make a Function level analysis pass
> (Pass1) available to Module level transformation pass (BottomPass).
> In real life you could use it to request Dominator information for a
> module level pass. This is supported and it works. The reason it fails
> for your test case is that the function "main" is just a declaration.
> There is no analysis info to generate.
>
> If you add a "main" function body in your module then it should work.
> Or you should check whether F.isDeclaration() is true or not before
> invoking getAnalysis<Pass1>(F);
>
> I agree, the assertion message is not very helpful here.
>
> -
> Devang
>
>
>  
>> -- John T.
>>
>> #include "llvm/Pass.h"
>> #include "llvm/Module.h"
>> #include "llvm/PassManager.h"
>> #include "llvm/Type.h"
>>
>> using namespace llvm;
>>
>> struct Pass1 : public FunctionPass {
>>  public :
>>    static char ID;
>>    Pass1 () : FunctionPass ((intptr_t) &ID) {}
>>    const char *getPassName() const { return "Pass 1"; }
>>    virtual bool runOnFunction(Function &F) {
>>      return false;
>>    }
>>    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>>      return;
>>    }
>> };
>>
>> struct BottomPass : public ModulePass {
>>  public :
>>    static char ID;
>>    BottomPass () : ModulePass ((intptr_t) &ID) {
>>    }
>>    const char *getPassName() const { return "Bottom Pass"; }
>>    virtual bool runOnModule(Module &M) {
>>      for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
>>        Function &F = *I;
>>        Pass1 &P = getAnalysis<Pass1>(F);
>>      }
>>      return false;
>>    }
>>    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>>      AU.addRequired<Pass1>();
>>    }
>> };
>>
>> int main(int argc, char **argv) {
>>  Module M("testmodule");
>>  M.getOrInsertFunction ("main", Type::VoidTy, NULL);
>>  PassManager Passes;
>>  Passes.add(new BottomPass());
>>  Passes.run(M);
>>  return 1;
>> }
>>
>> char Pass1::ID = 0;
>> char BottomPass::ID = 0;
>>
>> RegisterPass<Pass1> R1("p1","Pass 1");
>> RegisterPass<BottomPass> R3("b","Bottom Pass");
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> [hidden email]         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>    
>
> -
> Devang
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>  

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev