我正在尝试创建分析通道。我的代码如下所示。我正在使用Adrian Sampson方法来构建.so文件(https://www.cs.cornell.edu/~asampson/blog/llvm.html)。
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "DataDependence.h"
#include "ControlDependence.h"
#include "llvm/IR/Module.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
using namespace llvm;
namespace {
struct SkeletonPass : public ModulePass {
static char ID;
SkeletonPass() : ModulePass(ID) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<DominatorTreeWrapperPass>();
// AU.addPreserved<AliasAnalysis>();
// AU.setPreservesCFG();
// AU.addRequired<PostDominatorTree>();
}
virtual bool runOnModule(Module &M);
};
bool SkeletonPass::runOnModule(Module &M) {
for (auto mi = M.begin(); mi != M.end(); ++mi) {
if (mi->isDeclaration())
continue;
// MemoryDependenceAnalysis &MDA = getAnalysis<MemoryDependenceAnalysis>(*mi);
PostDominatorTree &PDT = getAnalysis<PostDominatorTree>(*mi); //Error is Here
}
errs() << "Test:\n";
}
}
char SkeletonPass::ID = 0;
static RegisterPass<SkeletonPass> X("SkeletonPass", "Hello World Pass",
false /* Only looks at CFG */,
true /* Analysis Pass */);
我得到的错误在
之下 In file included from /usr/local/include/llvm/Pass.h:388:0,
from /media/quentinmayo/storage/Research/LLVM Dev/llvm-pass-skeleton/skeleton/Skeleton.cpp:1:
/usr/local/include/llvm/PassAnalysisSupport.h: In instantiation of ‘AnalysisType& llvm::Pass::getAnalysis(llvm::Function&) [with AnalysisType = llvm::PostDominatorTree]’:
/media/quentinmayo/storage/Research/LLVM Dev/llvm-pass-skeleton/skeleton/Skeleton.cpp:34:71: required from here
/usr/local/include/llvm/PassAnalysisSupport.h:253:38: error: ‘ID’ is not a member of ‘llvm::PostDominatorTree’
return getAnalysisID<AnalysisType>(&AnalysisType::ID, F);
^
skeleton/CMakeFiles/SkeletonPass.dir/build.make:62: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o' failed
make[2]: *** [skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o] Error 1
CMakeFiles/Makefile2:85: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/all' failed
make[1]: *** [skeleton/CMakeFiles/SkeletonPass.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
错误是说我缺少AnalysisType :: ID。我想将AliasAnalysis指针传递给另一个类进行分析。我很困惑这个AnalysisType :: ID会是什么?另外,在创建分析通道时,有人可以解释getAnalysisUsage和getAnalysis之间的关系吗?理解编译器理论并不能帮助我使用LLVM。
http://llvm.org/docs/doxygen/html/classllvm_1_1Pass.html#ab78af013d3a11515403da8517f8f3d4a
答案 0 :(得分:1)
我需要调用类成员getDomTree。
DominatorTree&amp; DI = getAnalysis(* mi).getDomTree();
对他人的建议:与doxygen页面友好相关并阅读头文件。如果涉及到它,请查看当前LLVM构建的来源。
另外,AliasAnalysis现在是AAResultsWrapperPass。