I wrote a pass(that is to be loaded by opt) that I would like to use
in conjunction with MemoryDependenceAnalysis. I have tried using by
including its header and adding this to my pass:
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
errs() << "addRequired called\n";
AU.addRequired<MemoryDependenceAnalysis>();
}
And in my runOnFunction() method I have:
MD = &getAnalysis<MemoryDependenceAnalysis>();
The results in:
addRequired called
Assertion failed: (ResultPass && "getAnalysis*() called on an
analysis that was not " "'required' by pass!"), function getAnalysisID
I do not know why. I noticed the DeadStoreElimination pass also uses
this, but it does not use RegisterPass (like mine and the docs show).
Instead it has lines like:
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceAnalysis)
This gives me:
error: C++ requires a type specifier for all declarations
In runOnFunction(), you should check to see if the function F is a declaration before calling getAnalysis(F). Calling getAnalysis<FunctionPass>() on a function that is a declaration will trigger an assertion if the function is just a declaration.
To see if a function is a declaration, call its isDeclaration() method (i.e. if (F->isDeclaration()) ... )
If Hello is a FunctionPass then you try MemoryDependenceAnalysis *MD = &getAnalysis<MemoryDependenceAnalysis>()
If Hello is a ModulePass then you try if (!F.isDeclaration()) MemoryDependenceAnalysis *MD = &getAnalysis<MemoryDependenceAnalysis>(F)