[LLVMdev] Trouble with using PassManager to execute custom passes that have dependencies.
Paul Vario
paul.paul.mit at gmail.com
Thu Jan 23 16:15:55 PST 2014
Hi,
I wrote my own FunctionPass that depends on DominatorTree and LoopInfo
passes. Then my own pass is executed outside the LLVM optimizer
infrastructure (I.e., in a main file). However, I got the following error:
LLVM/llvm-3.3.src/lib/IR/PassManager.cpp:637: void
llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI &&
"Expected required passes to be initialized"' failed.
Since the pass was not executed by opt, I took it that I did not need
to register the pass or modify the LLVM code base to accommodate it ...
Then I try to fix the problem by calling INITIALIZE_PASS_DEPENDENCY right
after char XXXPass::ID=0. Then the compiler complains something about it
has to be declared inside the llvm namespace. Any hints on how to fix that?
Best Regards,
Paulie
--------------------------- Code -----------------------------------
using namespace llvm;
class XXXPass : public FunctionPass {
public:
XXXPass() : FunctionPass(ID) {}
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
AU.addRequired<DominatorTree>();
AU.addRequired<LoopInfo>();
}
virtual bool runOnFunction(Function &F) {
DominatorTree *DT = &getAnalysis<DominatorTree>();
LoopInfo *li = &getAnalysis<LoopInfo>();
return false;
}
static char ID;
};
char XXXPass::ID = 0;
int main(int argc, char **argv) {
SMDiagnostic Err;
Module *Mod = ParseIRFile(argv[2], Err, getGlobalContext());
if (!Mod) {
Err.print(argv[0], errs());
return 1;
}
Function *Func = Mod->getFunction("test");
PassManager PM;
PM.add(new XXXPass());
PM.run(*Mod);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140123/553abfaf/attachment.html>
More information about the llvm-dev
mailing list