I am trying to add an analysis pass as a FunctionPass, and let LICM (LoopPass) depends upon it. So in LICM.cpp, I have the following: virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); AU.addRequired<DominatorTree>(); AU.addRequired<LoopInfo>(); AU.addRequiredID(LoopSimplifyID); AU.addRequired<AliasAnalysis>(); AU.addRequired<MyAnalysis>(); // Add this AU.addPreserved<AliasAnalysis>(); AU.addPreserved("scalar-evolution"); AU.addPreservedID(LoopSimplifyID); } char LICM::ID = 0; INITIALIZE_PASS_BEGIN(LICM, "licm", "Loop Invariant Code Motion", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTree) INITIALIZE_PASS_DEPENDENCY(LoopInfo) INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_DEPENDENCY(MyAnalysis) // add this dependency INITIALIZE_AG_DEPENDENCY(AliasAnalysis) INITIALIZE_PASS_END(LICM, "licm", "Loop Invariant Code Motion", false, false) Howerver, I got an infinite loop when trying opt -O3 t.bc -o out.bc Where t.bc is created using clang from int main() { return 0; } What am I missing ? All files are attacahed (include/Analysis/MyAnalysis.h, lib/Analysis/MyAnanlysis.cpp, and diffs to the existing files). Thanks Junjie -------------- next part -------------- A non-text attachment was scrubbed... Name: MyAnalysis.cpp Type: text/x-c++src Size: 158 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110822/c50f4d77/attachment.cpp> -------------- next part -------------- A non-text attachment was scrubbed... Name: MyAnalysis.h Type: text/x-chdr Size: 451 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110822/c50f4d77/attachment.h> -------------- next part -------------- A non-text attachment was scrubbed... Name: myana.diff Type: application/octet-stream Size: 3141 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110822/c50f4d77/attachment.obj>
I think I know what goes wrong. LICM acutally requires another transformation : LoopSimplify, which does not preserve MyAnalysis. So LICM first schedules MyAnalysis before running LICM, then schedule LoopSimplify, but scheduling LoopSimplify causes MyAnalysis to be removed because it is not preserved, And LICM keeps repeating this schedule & remove, and thus infinite loop. It's nice for LLVM to add mechanism to detect this kind of conflicting requirements.... On Mon, Aug 22, 2011 at 3:03 PM, Junjie Gu <jgu222 at gmail.com> wrote:> I am trying to add an analysis pass as a FunctionPass, and let LICM > (LoopPass) depends upon it. So in LICM.cpp, I have the following: > > virtual void getAnalysisUsage(AnalysisUsage &AU) const { > AU.setPreservesCFG(); > AU.addRequired<DominatorTree>(); > AU.addRequired<LoopInfo>(); > AU.addRequiredID(LoopSimplifyID); > AU.addRequired<AliasAnalysis>(); > AU.addRequired<MyAnalysis>(); // Add this > AU.addPreserved<AliasAnalysis>(); > AU.addPreserved("scalar-evolution"); > AU.addPreservedID(LoopSimplifyID); > } > > > char LICM::ID = 0; > INITIALIZE_PASS_BEGIN(LICM, "licm", "Loop Invariant Code Motion", false, false) > INITIALIZE_PASS_DEPENDENCY(DominatorTree) > INITIALIZE_PASS_DEPENDENCY(LoopInfo) > INITIALIZE_PASS_DEPENDENCY(LoopSimplify) > INITIALIZE_PASS_DEPENDENCY(MyAnalysis) > // add this dependency > INITIALIZE_AG_DEPENDENCY(AliasAnalysis) > INITIALIZE_PASS_END(LICM, "licm", "Loop Invariant Code Motion", false, false) > > > Howerver, I got an infinite loop when trying > > opt -O3 t.bc -o out.bc > > Where t.bc is created using clang from > int main() { return 0; } > > What am I missing ? > > All files are attacahed (include/Analysis/MyAnalysis.h, > lib/Analysis/MyAnanlysis.cpp, and diffs to the existing files). > > Thanks > Junjie >
Seemingly Similar Threads
- [LLVMdev] Adding dependency on MemoryDependenceAnalysis pass to LICM causes opt to get stuck in addPass
- [LLVMdev] Adding dependency on MemoryDependenceAnalysis pass to LICM causes opt to get stuck in addPass
- [LLVMdev] Error when trying to chain two llvm transform passes
- [LLVMdev] Function Pass Manager
- [LLVMdev] AnalysisUsage & Call Graph SCC Pass Manager