LLVM unable to get a required analysis -


i writing pass needs information loops. therefore overriding getanalysisusage(analysisusage&) let pass manager know pass depends on loopinfowrapperpass. however, when try result of analysis, llvm asserts analysis wasn't required pass. here's simple pass i'm having trouble with:

#include <llvm/pass.h> #include <llvm/support/raw_ostream.h> #include <llvm/analysis/loopinfo.h>  struct example : public modulepass {     static char id;     example() : modulepass(id) {}      bool runonmodule(module& m) override {         errs() << "what\n";         loopinfo& loops = getanalysis<loopinfowrapperpass>().getloopinfo();         loops.print(errs());          return false;     }      virtual void getanalysisusage(analysisusage& au) const override {         errs() << "here\n";         au.addrequired<loopinfowrapperpass>();     } };  char example::id = 0; static registerpass<example> x("example", "an example", false, false); 

when run pass, 2 debug statements printed in correct order (here what) when getanalysis<loopinfowrapperpass>() called, assertion error:

opt: /home/matt/llvm/llvm/include/llvm/passanalysissupport.h:211: analysistype& llvm::pass::getanalysisid(llvm::analysisid) const [with analysistype = llvm::loopinfowrapperpass; llvm::analysisid = const void*]: assertion `resultpass && "getanalysis*() called on analysis not " "'required' pass!"' failed. 

this same method given in llvm's documentation on writing passes, i'm not quite sure what's going wrong here. point me in right direction?

loopinfowrapperpass derived functionpass. example class, however, derives modulepass. works on module level, you'll need tell loopinfowrapperpass function want analyze. basically, might want loop every function f in module, , use getanalysis<loopinfowrapperpass>(f).

alternatively, easiest way fix code above replace modulepass functionpass , runonmodule(module& m) runonfunction(function& f). then, getanalysis<loopinfowrapperpass>() should work fine.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -