[LLVMdev] Pass Manager Restriction?

Devang Patel dpatel at apple.com
Fri Apr 10 11:53:01 PDT 2009


"A module pass can use function level passes (e.g. dominators) using  
getAnalysis interfacegetAnalysis<DominatorTree>(Function), if the  
function pass does not require any module passes."

http://llvm.org/docs/WritingAnLLVMPass.html

In your case, A module pass (ModPass2) is trying tu use function level  
pass (FunPass1) which uses module level pass (ModPass1). This is not  
supported.

-
Devang

On Apr 9, 2009, at 3:13 PM, Joseph Blomstedt wrote:

> Having a ModulePass that requires a FunctionPass that in turn requires
> another ModulePass results in an assertion being fired. Is this
> expected behavior (that seems to be undocumented), or a bug?
>
> Specifically, the following code will emit the assertion:
> [VMCore/PassManager.cpp:1597: virtual void
> llvm::ModulePass::assignPassManager(llvm::PMStack&,
> llvm::PassManagerType): Assertion `!PMS.empty() && "Unable to find
> appropriate Pass Manager"' failed]
>
> ******
> struct ModPass1 : public ModulePass {
>  static char ID;
>  ModPass1() : ModulePass((intptr_t)&ID) {}
>  virtual bool runOnModule(Module &M) { return false; }
>  virtual void getAnalysisUsage(AnalysisUsage &AU) const {}
> };
>
> struct FunPass1 : public FunctionPass {
>  static char ID;
>  FunPass1() : FunctionPass((intptr_t)&ID) {}
>  virtual bool runOnFunction(Function &F) {return false; }
>  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>    AU.addRequired<ModPass1>();
>  }
> };
>
> struct ModPass2 : public ModulePass {
>  static char ID;
>  ModPass2() : ModulePass((intptr_t)&ID) {}
>  virtual bool runOnModule(Module &M) { return false; }
>  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>    AU.addRequired<FunPass1>();
>  }
> };
>
> char ModPass1::ID = 0;
> char FunPass1::ID = 0;
> char ModPass2::ID = 0;
>
> RegisterPass<ModPass1> A("modpass1", "");
> RegisterPass<FunPass1> B("funpass1", "");
> RegisterPass<ModPass2> C("modpass2", "");
>
> int main(int argc, char argv) {
>  PassManager PM;
>  PM.add(new ModPass2);
> }
> ******
>
> Also of note, if the first module requires TargetData, then the code
> will fail earlier with the assertion
> [include/llvm/Target/TargetData.h:114: llvm::TargetData::TargetData():
> Assertion `0 && "ERROR
> : Bad TargetData ctor used.  " "Tool did not specify a TargetData to
> use?"' failed]. This occurs even when a valid TargetData object is
> added to the PassManager. Specifically, if ModPass1 above is
> changed to have addRequired<TargetData> then the first of the
> following code works, but the second fails with the TargetData
> assertion:
>
> ******
> // Works!
> int main(int argc, char argv) {
>  PassManager PM;
>  Module TestMod = ...;
>  PM.add(new TargetData(TestMod));
>  PM.add(new FunPass1);
> }
> ******
> // Breaks with TargetData assertion rather than PMS.empty assertion
> int main(int argc, char argv) {
>  PassManager PM;
>  Module TestMod = ...;
>  PM.add(new TargetData(TestMod));
>  PM.add(new ModPass2);
> }
> ******
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list