我遇到了一个试图在模块传递(LLVM 3.4)中使用AliasAnalysis的问题。这似乎是一个相当普遍的问题,有两个主要的解决方案,但我还没有能够让它发挥作用。
使用以下简单的测试程序:
#include <stdio.h>
static int gX;
void f() {
gX = 1;
}
int main() {
printf("Hello.\n");
return 0;
}
编译如下:clang++ -O0 -c -emit-llvm -o test.bc test.cpp
我的简单传球:
class DebugPass : public ModulePass {
public:
static char ID;
DebugPass() : ModulePass(ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<AliasAnalysis>();
}
virtual bool runOnModule(Module &M) {
for (Module::iterator fit = M.begin(), fite = M.end(); fit != fite; ++fit) {
Function *F = fit;
if (F->isDeclaration()) continue;
errs() << "Getting AA for " << F->getName() << "\n";
AliasAnalysis &AA = getAnalysis<AliasAnalysis>(*F);
}
return false;
}
}
char DebugPass::ID = 0;
static RegisterPass<DebugPass> X("testdebug", "Debugging pass", false, false);
通过调用我的传递:opt -load ../Debug+Asserts/lib/TestLib.dylib -basicaa -testdebug < test.bc > /dev/null
我看到以下断言失败:
Getting AA for _Z1fv
Assertion failed: (FPP && "Unable to find on the fly pass"), function getOnTheFlyPass, file LegacyPassManager.cpp, line 1682.
...
6 opt 0x0000000102e5ba62 abort + 18
7 opt 0x0000000102e5ba41 __assert_rtn + 129
8 opt 0x0000000102d94820 (anonymous namespace)::MPPassManager::getOnTheFlyPass(llvm::Pass*, void const*, llvm::Function&) + 144
9 opt 0x0000000102d949cf non-virtual thunk to (anonymous namespace)::MPPassManager::getOnTheFlyPass(llvm::Pass*, void const*, llvm::Function&) + 63
10 opt 0x0000000102d8ed4e llvm::AnalysisResolver::findImplPass(llvm::Pass*, void const*, llvm::Function&) + 78
11 TestLib.dylib 0x0000000104ba9bac llvm::AliasAnalysis& llvm::Pass::getAnalysisID<llvm::AliasAnalysis>(void const*, llvm::Function&) + 236
12 TestLib.dylib 0x0000000104b9eef6 llvm::AliasAnalysis& llvm::Pass::getAnalysis<llvm::AliasAnalysis>(llvm::Function&) + 134
13 TestLib.dylib 0x0000000104bdc287 DebugPass::runOnModule(llvm::Module&) + 215
任何人都可以提供一些有关出错的信息吗?
编辑:这是通过-debug-pass=Structure
传递的结构:
Pass Arguments: -targetlibinfo -datalayout -notti -basictti -x86tti -no-aa -basicaa -testdebug -preverify -domtree -verify
Target Library Information
Data Layout
No target information
Target independent code generator's TTI
X86 Target Transform Info
No Alias Analysis (always returns 'may' alias)
Basic Alias Analysis (stateless AA impl)
ModulePass Manager
Debugging pass
FunctionPass Manager
Preliminary module verification
Dominator Tree Construction
Module Verifier
Bitcode Writer
我的调试过程在FunctionPass管理器之前发生了吗?我没有练习解释传递结构输出。