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();
AU.addRequired();
}
virtual bool runOnFunction(Function &F) {
DominatorTree *DT = &getAnalysis();
LoopInfo *li = &getAnalysis();
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;
}