Michael Ilseman
2011-May-30 23:56 UTC
[LLVMdev] Segfault when trying to schedule custom ImmutablePass
I'm in a debug build with assertions turned on for llvm-2.9, and I get a segfault whenever I try to schedule one of my own immutable passes in a pass manager. It seems that one of the passes that I'm scheduling (IndVarSimplify) attempts to ask for TargetData if it's available (I'm not providing it), and that's when it segfaults. If I split that pass into it's own pass manager, then everything works fine. It might be the case that I'm not properly identifying myself to the pass manager as an immutable pass, but I'm trying to handle myself identically to how e.g. TargetData is handled. Should I submit this as a bug? Also, even if I'm just using this wrong, maybe there should be an assert. I've searched the mailing list archives, but didn't find anything related. Here's the code that segfaults: llvm::PassManager canonicalize; canonicalize.add(llvm::createIndVarSimplifyPass()); canonicalize.add(gla_llvm::createCanonicalizeCFGPass()); canonicalize.add(gla_llvm::createBackEndPointerPass(backEnd)); canonicalize.add(gla_llvm::createCanonicalizeInstsPass()); canonicalize.run(*module); where BackEndPointer is the Immutable Pass. This segfaults when ScalarEvolution tries to get TargetData if available. Below is the complete stack trace: #0 0x083ae6fd in std::vector<llvm::PassInfo const*, std::allocator<llvm::PassInfo const*> >::begin (this=0x10) at /usr/include/c++/4.4/bits/stl_vector.h:435 #1 0x083a63c8 in llvm::PMTopLevelManager::findAnalysisPass (this=0x85f6ad4, AID=0x85eef30) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:673 #2 0x083a7f0e in llvm::PMDataManager::findAnalysisPass (this=0x88931b8, AID=0x85eef30, SearchParent=true) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1062 #3 0x083a8b09 in llvm::AnalysisResolver::getAnalysisIfAvailable (this=0x876a960, ID=0x85eef30, dir=true) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1215 #4 0x08120ee2 in llvm::Pass::getAnalysisIfAvailable<llvm::TargetData> (this=0x860fd98) at /home/michael/LunarGLASS/LLVM/llvm-2.9/include/llvm/PassAnalysisSupport.h:181 #5 0x082b5e3b in llvm::ScalarEvolution::runOnFunction (this=0x860fd98, F=...) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/Analysis/ScalarEvolution.cpp:5965 #6 0x083a9c73 in llvm::FPPassManager::runOnFunction (this=0x88931a8, F=...) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1483 #7 0x083a9e2d in llvm::FPPassManager::runOnModule (this=0x88931a8, M=...) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1503 #8 0x083aa118 in llvm::MPPassManager::runOnModule (this=0x86099a8, M=...) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1557 #9 0x083aa5ce in llvm::PassManagerImpl::run (this=0x85f6a00, M=...) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1638 #10 0x083aaabf in llvm::PassManager::run (this=0xbffe95a4, M=...) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1682 #11 0x0808fa08 in gla::PrivateManager::runLLVMOptimizations1 (this=0x86ef860) at ../LunarGLASS/TopToBottom.cpp:251 #12 0x0808f1f3 in gla::PrivateManager::translateTopToBottom (this=0x86ef860) at ../LunarGLASS/TopToBottom.cpp:66 #13 0x081064aa in main (argc=2, argv=0xbffff174) at main.cpp:388 If I schedule the immutable pass for earlier, then it segfaults when just trying to add the IndVarSimplify pass. llvm::PassManager canonicalize; canonicalize.add(gla_llvm::createBackEndPointerPass(backEnd)); canonicalize.add(llvm::createIndVarSimplifyPass()); canonicalize.add(gla_llvm::createCanonicalizeCFGPass()); canonicalize.add(gla_llvm::createCanonicalizeInstsPass()); canonicalize.run(*module); #0 0x083ae6fd in std::vector<llvm::PassInfo const*, std::allocator<llvm::PassInfo const*> >::begin (this=0x10) at /usr/include/c++/4.4/bits/stl_vector.h:435 #1 0x083a63c8 in llvm::PMTopLevelManager::findAnalysisPass (this=0x85f6ad4, AID=0x85eef60) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:673 #2 0x083a6131 in llvm::PMTopLevelManager::schedulePass (this=0x85f6ad4, P=0x86d9f98) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:614 #3 0x083ac844 in llvm::PassManagerImpl::add (this=0x85f6a00, P=0x86d9f98) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:396 #4 0x083aa885 in llvm::PassManager::addImpl (this=0xbffe95a4, P=0x86d9f98) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1659 #5 0x083aa9aa in llvm::PassManager::add (this=0xbffe95a4, P=0x86d9f98) at /home/michael/LunarGLASS/LLVM/llvm-2.9/lib/VMCore/PassManager.cpp:1672 #6 0x0808f9cb in gla::PrivateManager::runLLVMOptimizations1 (this=0x86ef860) at ../LunarGLASS/TopToBottom.cpp:248 #7 0x0808f1f3 in gla::PrivateManager::translateTopToBottom (this=0x86ef860) at ../LunarGLASS/TopToBottom.cpp:66 #8 0x081064aa in main (argc=2, argv=0xbffff174) at main.cpp:388 However splitting things out works just fine: llvm::PassManager canonicalize; llvm::PassManager canonicalize2; canonicalize.add(llvm::createIndVarSimplifyPass()); canonicalize.run(*module); canonicalize2.add(gla_llvm::createCanonicalizeCFGPass()); canonicalize2.add(gla_llvm::createBackEndPointerPass(backEnd)); canonicalize2.add(gla_llvm::createCanonicalizeInstsPass()); canonicalize2.run(*module); I can also provide how BackEndPointer is implemented/initialized (identically to TargetData as far as I can tell). Thanks for any help.
Devang Patel
2011-May-31 17:27 UTC
[LLVMdev] Segfault when trying to schedule custom ImmutablePass
On May 30, 2011, at 4:56 PM, Michael Ilseman wrote:> I'm in a debug build with assertions turned on for llvm-2.9, and I get > a segfault whenever I try to schedule one of my own immutable passes > in a pass manager. It seems that one of the passes that I'm scheduling > (IndVarSimplify) attempts to ask for TargetData if it's available (I'm > not providing it), and that's when it segfaults. If I split that pass > into it's own pass manager, then everything works fine. It might be > the case that I'm not properly identifying myself to the pass manager > as an immutable pass, but I'm trying to handle myself identically to > how e.g. TargetData is handled. Should I submit this as a bug?yup, that's a good idea. Please include a reproduce test case (i.e. skeleton of all your passes such that anyone can reproduce this crash using the info) to help investigate the issue. Thanks! - Devang