[LLVMdev] Pass Manager Restriction?
Joseph Blomstedt
Joseph.Blomstedt at colorado.edu
Thu Apr 9 15:13:05 PDT 2009
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);
}
******
More information about the llvm-dev
mailing list