如何在模块传递中获取LoopInfo?

时间:2019-07-15 04:46:13

标签: llvm llvm-ir llvm-c++-api

我需要在模块传递中获取LoopInfo。该通行证可以成功编译,但通过opt运行时会崩溃。通行证的核心部分是波纹管。

virtual bool runOnModule (Module &M) override {
    for (auto &F: M) {
        if(F.isDeclaration())
            continue;

        errs()<<F.getName()<<"() <<<<<<<<<<<<<< \n";
        // crash at the following line
        LoopInfo & LI = getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();
    }
    return true;
}
// Here is the pass registering part.
static RegisterPass<LoopPrimary> X("loop-primary", "About Loop information");
static void register_pass(const PassManagerBuilder &PMB,
                          legacy::PassManagerBase &PM)
{
    PM.add(new LoopPrimary());
}

版本为llvm-6.0.1。 并且崩溃堆栈信息为:

-> % opt -S -load ../build/LoopAnalysis/libLLVMLoopPrimary.so -loop-primary loop.bc >/dev/null
loop() <<<<<<<<<<<<<< 
LLVMSymbolizer: error reading file: No such file or directory
#0 0x0000000001d7b26a (opt+0x1d7b26a)
#1 0x0000000001d7934e (opt+0x1d7934e)
#2 0x0000000001d7949c (opt+0x1d7949c)
#3 0x00007ffba6004390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#4 0x00000000018236e0 (opt+0x18236e0)
#5 0x000000000182c142 (opt+0x182c142)
#6 0x00007ffba4b3d9a4 llvm::LoopInfoWrapperPass& llvm::Pass::getAnalysisID<llvm::LoopInfoWrapperPass>(void const*, llvm::Function&) (../build/LoopAnalysis/libLLVMLoopPrimary.so+0x59a4)
#7 0x00007ffba4b3d6c2 llvm::LoopInfoWrapperPass& llvm::Pass::getAnalysis<llvm::LoopInfoWrapperPass>(llvm::Function&) (../build/LoopAnalysis/libLLVMLoopPrimary.so+0x56c2)
#8 0x00007ffba4b3ccfd (anonymous namespace)::LoopPrimary::runOnModule(llvm::Module&) (../build/LoopAnalysis/libLLVMLoopPrimary.so+0x4cfd)

我试图通过函数传递成功获取LoopInfo。仍然,我不知道为什么它在模块传递中失败。 有没有错误的代码?任何帮助将不胜感激。

0 个答案:

没有答案