AU.addRequired <loopinfo>();崩溃;在LLVM传递

时间:2015-05-08 02:32:11

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

我有一个简单的函数传递,我试图在代码中获取循环信息。但是当我尝试在getAnalysisUsage()中添加AU.addRequired()时,模块崩溃了。甚至在调用getAnalysis()之前就会发生这种情况。它是一个动态加载的传递(.so)。

namespace
{
    class TestPass : public FunctionPass
    {
        public:
        static char ID;

        TestPass() : FunctionPass(ID) {}

        virtual void getAnalysisUsage(AnalysisUsage &AU) const
        {
            AU.addRequired<LoopInfo>();
            AU.setPreservesAll();
        }

        bool runOnFunction(Function &F) override
        {
            errs() << F.getName() << " : " << F.getBasicBlockList().size() << "\n";
            // LoopInfo &LI = getAnalysis<LoopInfo>();
            return false;
        }
    };
}

char TestPass::ID = 0;
static RegisterPass<TestPass> X("TestPass", "Test pass");

// register pass for clang use
static void registerTestPassPass(const PassManagerBuilder &, PassManagerBase &PM)
{
    PM.add(new TestPass());
}

static RegisterStandardPasses RegisterTestPassPass(PassManagerBuilder::EP_EarlyAsPossible , registerTestPassPass);

这是堆栈跟踪。

[armeabi-v7a] Compile thumb  : test <= test.c

Pass 'Test pass' is not initialized.
Verify if there is a pass dependency cycle.
Required Passes:
0  clang           0x0000000001492ec2 llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1  clang           0x0000000001490f61
2  libpthread.so.0 0x00002b15cbb4e340
3  clang           0x00000000011c86f7 llvm::PMTopLevelManager::schedulePass(llvm::Pass*) + 343
4  clang           0x00000000019c0401 llvm::PassManagerBuilder::addExtensionsToPM(llvm::PassManagerBuilder::ExtensionPointTy, llvm::legacy::PassManagerBase&) const + 225
5  clang           0x00000000019c054a llvm::PassManagerBuilder::populateFunctionPassManager(llvm::legacy::FunctionPassManager&) + 26
6  clang           0x0000000001837de3 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 1171
7  clang           0x000000000182a47f
8  clang           0x0000000001bdf043 clang::ParseAST(clang::Sema&, bool, bool) + 483
9  clang           0x0000000001603ba6 clang::FrontendAction::Execute() + 118
10 clang           0x00000000015e47b8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 280
11 clang           0x0000000001673b41 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1921
12 clang           0x0000000000820358 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1320
13 clang           0x00000000007fceaa main + 8298
14 libc.so.6       0x00002b15cc7b6ec5 __libc_start_main + 245
15 clang           0x000000000081e5d9

我错过了什么吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

找到解决方案。代码缺少新的LoopInfo()对象的创建,以便调用LoopInfo传递。

// register pass for clang use
static void registerTestPassPass(const PassManagerBuilder &, PassManagerBase &PM)
{
    PM.add(new LoopInfo());
    PM.add(new TestPass());
}