LLVM GetAnalysis() 因所需的传递而失败

LLVM GetAnalysis() failing with required passes

我有一组使用 LLVM 创建的自定义通行证 运行 在某些位码上。 我已经设法让它编译,但是每当我尝试使用在另一个传递类型上调用 getAnalysis() 的传递来 运行 它时,它会失败:

Assertion `ResultPass && "getAnalysis*() called on an analysis that was not " "'required' by pass!"' failed.

调用 getAnalysis() 的自定义通行证需要其类型,特别是;

bool Operators::doInitialization(){
ParseConfig &parseConfig = getAnalysis<ParseConfig>(); // Fails here.
}
.
.
.
void Operators::getAnalysisUsage(AnalysisUsage &AU) const{
    AU.addRequired<ParseConfig>();
    return;
}

我在这上面花了几天时间,很迷茫。我知道以下是正确的:

重要说明:我最终会在用 Flang 编译的 Fortran 项目上使用它,因此 LLVM 库版本 I我使用的是 Flang 叉子(发现 here)。该分支就在 LLVM 7.1 附近,但与注册通行证相关的特定文件似乎与当前的 LLVM 库没有什么不同。

getAnalysis 功能从 doInitialization 移至 runOnFunction 即可。


来自 LLVM page

This method call getAnalysis* returns a reference to the pass desired. You may get a runtime assertion failure if you attempt to get an analysis that you did not declare as required in your getAnalysisUsage implementation. This method can be called by your run* method implementation, or by any other local method invoked by your run* method.