[LLVMdev] Questions about trip count

Eli Friedman eli.friedman at gmail.com
Sat Aug 14 12:38:18 PDT 2010


On Sat, Aug 14, 2010 at 9:16 AM, Douglas do Couto Teixeira
<douglasdocouto at gmail.com> wrote:
> But when I use that same function within a class I get some compiler errors.
> I'm trying to use this function like this:
>
> #define DEBUG_TYPE "hello"
> #include "llvm/Pass.h"
> #include "llvm/Function.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/ADT/Statistic.h"
> #include "llvm/Analysis/LoopInfo.h"
> #include "llvm/Analysis/ScalarEvolution.h"
> using namespace llvm;
> STATISTIC(HelloCounter, "Counts number of functions greeted");
> namespace {
> struct Hello: public FunctionPass {
> static char ID; // Pass identification, replacement for typeid
> Hello() : FunctionPass(&ID) {}
> class testLoopInfo {
> void getLoopInfo(const Function& F) const {
> const LoopInfo *LI = &getAnalysis<LoopInfo> ();
> ScalarEvolution *SE = &getAnalysis<ScalarEvolution> ();
> Function::const_iterator BB = F.begin(), E = F.end();
> for (; BB != E; ++BB) {
> const Loop* L = LI->getLoopFor(&*BB);
> if (L != NULL) {
> errs() << "Trip count: " << *SE->getBackedgeTakenCount(L);
> L->dump();
> }
> }
> }
> };
> virtual bool runOnFunction(Function &F) {
> HelloCounter++;
> errs() << "Hello: ";
> errs().write_escaped(F.getName()) << '\n';
> //getLoopInfo(F);
> return false;
> }
> // We don't modify the program, so we preserve all analyses
> virtual void getAnalysisUsage(AnalysisUsage &AU) const {
> AU.setPreservesAll();
> AU.addRequired<LoopInfo> ();
> AU.addRequired<ScalarEvolution> ();
> }
> };
> }
> char Hello::ID = 0;
> static RegisterPass<Hello> Y("hello",
> "Hello World Pass (with getAnalysisUsage implemented)");
> I get the following errors:
> **** Build of configuration Debug for project HelloLLVM ****
> make all
> llvm[0]: Compiling Hello.cpp for Release build (PIC)
> Hello.cpp: In member function
> ‘void<unnamed>::Hello::testLoopInfo::getLoopInfo(const llvm::Function&)
> const’:
> Hello.cpp:37: error: no matching function for call to
> ‘llvm::Pass::getAnalysis()’
> /home/douglas/Programas/llvm-2.7/include/llvm/PassAnalysisSupport.h:209:
> note: candidates are: AnalysisType& llvm::Pass::getAnalysis() const [with
> AnalysisType = llvm::LoopInfo] <near match>
> Hello.cpp:38: error: no matching function for call to
> ‘llvm::Pass::getAnalysis()’
> /home/douglas/Programas/llvm-2.7/include/llvm/PassAnalysisSupport.h:209:
> note: candidates are: AnalysisType& llvm::Pass::getAnalysis() const [with
> AnalysisType = llvm::ScalarEvolution] <near match>
> Hello.cpp: In member function ‘virtual
> bool<unnamed>::Hello::runOnFunction(llvm::Function&)’:
> Hello.cpp:57: error: ‘getLoopInfo’ was not declared in this scope
> make: **
> [/home/douglas/Programas/llvm-2.7/lib/Transforms/Hello/Release/Hello.o] Erro
> 1
>
> Anyone know how can I fix it?

Umm, pass in a "Pass* P", then use "P->getAnalysis<LoopInfo> ()"?  C++
isn't Java :)

-Eli




More information about the llvm-dev mailing list