I changed one FunctionPass into ModulePass. I met one problem, which only occured when running program directly.
In other words, when I try to use GDB to debug, it did not happen. So I could only use original debugging technology by instrumenting print statement.
Step by step, at last I found two AnalysisPass (LoopInfo & DominatorTree) changed their behaviors after my change.
In conclusion,
when the original pass is FunctionPass, we can get the analysis result for two analysis passes anywhere. DominatorTree will not affect LoopInfo.
When we changed the original pass into FunctionPass, we should be careful.
Because DominatorTree may release previous analysis result of LoopInfo if we got them in other places instead of within runOnFunction().
E.G.
runOnFunction(Function* F) {
....
LoopInfo &LI = getAnalysis<LoopInfo>(*F);
Loop* L = LI->begin();
....
doSomething(F, L);
....
}
doSomething(Function* F, Loop* L) {
....
DominatorTree* DT = &getAnalysis<DominatorTree>(*F);
//Now the previous result of LoopInfo may be released and 'L' will be dangling pointer.
...
}