<div dir="ltr"><div dir="ltr"><div class="gmail-markdown-here-wrapper"><p style="margin:0px 0px 1.2em">Hi all,</p><p style="margin:0px 0px 1.2em"><br>I tried to have a LoopInfo object in a function pass, and add addRequired<span> in getAnalysisUsage, and then use getAnalysis<span> in runOnFunction(). It worked OK.<br>Now I want to have a module pass to traverse the functions, and similarly, I want to have to loop information of the functions.<br>When I did the above in runOnModule, and build the module pass, the following error popped out, and the compile did not succeed:</span></span></p>
<pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">[ 50%] Building CXX object src/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o
/home/**/Desktop/skeleton/src/Skeleton.cpp: In member function ‘virtual bool llvm::SkeletonPass::runOnModule(llvm::Module&)’:
/home/**/Desktop/skeleton/src/Skeleton.cpp:47:43: error: no matching function for call to ‘llvm::SkeletonPass::getAnalysis(llvm::Function*&)’
LoopInfo &LI = getAnalysis<LoopInfo>(F);
...
home/**/Work/llvm-6.0.1.src/include/llvm/PassAnalysisSupport.h: In instantiation of ‘llvm::AnalysisUsage& llvm::AnalysisUsage::addRequired() [with PassClass = llvm::LoopInfo]’:
/home/**/Desktop/skeleton/src/Skeleton.cpp:24:38: required from here
/home/**/Work/llvm-6.0.1.src/include/llvm/PassAnalysisSupport.h:67:39: error: ‘ID’ is not a member of ‘llvm::LoopInfo’
return addRequiredID(PassClass::ID);
^
</code></pre><p style="margin:0px 0px 1.2em">Here is my source code:<span style="font-size:0.85em;background-color:rgb(248,248,248);color:rgb(51,51,51);font-family:Consolas,Inconsolata,Courier,monospace;white-space:pre"> </span></p><pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="gmail-hljs gmail-language-cpp" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248);display:block">#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/Dominators.h"
#include "llvm/Analysis/LoopInfo.h"
namespace llvm
{
class SkeletonPass : public ModulePass
{
public:
static char ID;
SkeletonPass() : ModulePass(ID) {}
bool runOnModule(Module &M) override;
virtual StringRef getPassName() const override
{
return "Skeleton";
}
virtual void getAnalysisUsage(AnalysisUsage &AU) const override {
errs() << "get analysis usage method.\n";
AU.addRequired<LoopInfo>();
}
};
Pass *createSkeletonPass()
{
return new SkeletonPass();
}
char SkeletonPass::ID = 0;
Pass *createSkeletonPass();
void initializeSkeletonPass(PassRegistry &Registry);
} // namespace llvm
using namespace llvm;
using namespace std;
bool SkeletonPass::runOnModule(llvm::Module &M){
errs() << "=============start=============\n";
auto F = M.getFunction("main");
LoopInfo &LI = getAnalysis<LoopInfo>(F);
LI.print(errs());
errs() << "==========================\n";
}
static RegisterPass<SkeletonPass> X("run", "Hello world pass", false, false);</code></pre><p style="margin:0px 0px 1.2em">The version of LLVM is 6.0.1, can anyone tell me the correct way to handle this in a module pass? Thanks a lot!</p>
<p style="margin:0px 0px 1.2em">Best,<br>Liu</p>
<div title="MDH:PGRpdiBkaXI9Imx0ciI+PGRpdiBkaXI9Imx0ciI+PGRpdiBkaXI9Imx0ciI+PGRpdiBkaXI9Imx0
ciI+PGRpdiBkaXI9Imx0ciI+SGkgYWxsLDxkaXY+PGJyPjwvZGl2PjxkaXY+PGRpdj5JIHRyaWVk
IHRvIGhhdmUgYSBMb29wSW5mbyBvYmplY3QgaW4gYSBmdW5jdGlvbiBwYXNzLCBhbmQgYWRkIGFk
ZFJlcXVpcmVkJmx0O0xvb3BJbmZvJmd0OyBpbi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