LLVM Error When Using a Pass from Another Pass

匆匆过客 提交于 2019-12-12 01:52:58

问题


Here is my 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);

When I try to compile it, I receive the following error:

In file included from /usr/local/include/llvm/Pass.h:388:0,
from /home/ahmad/Codes/LLVM/MyPass/myPass.cpp:3: /usr/local/include/llvm/PassAnalysisSupport.h: In instantiation of ‘AnalysisType& llvm::Pass::getAnalysis() const [with AnalysisType = llvm::MemoryDependenceAnalysis]’: /home/ahmad/Codes/LLVM/MyPass/myPass.cpp:18:79: required from here /usr/local/include/llvm/PassAnalysisSupport.h:223:37: error: no matching function for call to ‘llvm::Pass::getAnalysisID(void* (*)()) const’ return getAnalysisID(&AnalysisType::ID); ^

How can I compile it without error?


回答1:


I believe the canonical way is

MemoryDependenceResults &MDA =
    getAnalysis<MemoryDependenceWrapperPass>().getMemDep();

And likewise,

AU.addRequired<MemoryDependenceWrapperPass>();

You can find examples of the above in the LLVM codebase.



来源:https://stackoverflow.com/questions/41338149/llvm-error-when-using-a-pass-from-another-pass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!