这是我的LLVM Pass:
#include <llvm/IR/Function.h>
#include <llvm/Pass.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Analysis/MemoryDependenceAnalysis.h>
using namespace llvm;
namespace
{
struct MemDepend : public FunctionPass
{
static char ID;
MemDepend() : FunctionPass(ID){}
virtual bool runOnFunction(Function &F)
{
MemoryDependenceAnalysis *MDA = &getAnalysis<MemoryDependenceAnalysis>();
return false;
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const
{
AU.setPreservesAll();
}
};
}
char MemDepend::ID = 0;
static RegisterPass<MemDepend> X("memdep", "Memory Pass", false, false);
当我尝试编译它时,收到以下错误:
在/usr/local/include/llvm/Pass.h:388:0中包含的文件中,
来自/home/ahmad/Codes/LLVM/MyPass/myPass.cpp:3: /usr/local/include/llvm/PassAnalysisSupport.h:实例化'AnalysisType&amp; llvm :: Pass :: getAnalysis()const [with AnalysisType = llvm :: MemoryDependenceAnalysis]': /home/ahmad/Codes/LLVM/MyPass/myPass.cpp:18:79:从这里要求 /usr/local/include/llvm/PassAnalysisSupport.h:223:37:错误:没有匹配函数来调用'llvm :: Pass :: getAnalysisID(void *(*)())const' return getAnalysisID(&amp; AnalysisType :: ID); ^
如何编译它而没有错误?
答案 0 :(得分:1)
我相信规范的方式是
MemoryDependenceResults &MDA =
getAnalysis<MemoryDependenceWrapperPass>().getMemDep();
同样,
AU.addRequired<MemoryDependenceWrapperPass>();
您可以在LLVM代码库中找到上述示例。