X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FProfileVerifierPass.cpp;h=c8896de89301e3ee19106149817c0c76826562f3;hb=318b7cc7f10d41370929ff93274de29c11f87b81;hp=36a80baf539d21110c145dd040a68edd010f4e41;hpb=8c30abec6d53e02c87c50ed7585ccd2ecac752aa;p=oota-llvm.git diff --git a/lib/Analysis/ProfileVerifierPass.cpp b/lib/Analysis/ProfileVerifierPass.cpp index 36a80baf539..c8896de8930 100644 --- a/lib/Analysis/ProfileVerifierPass.cpp +++ b/lib/Analysis/ProfileVerifierPass.cpp @@ -12,17 +12,18 @@ // //===----------------------------------------------------------------------===// #define DEBUG_TYPE "profile-verifier" -#include "llvm/Instructions.h" -#include "llvm/Module.h" -#include "llvm/Pass.h" +#include "llvm/Analysis/Passes.h" #include "llvm/Analysis/ProfileInfo.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/CallSite.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/Module.h" +#include "llvm/Pass.h" #include "llvm/Support/CFG.h" +#include "llvm/Support/CallSite.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/Format.h" #include "llvm/Support/InstIterator.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/Debug.h" #include using namespace llvm; @@ -30,7 +31,7 @@ static cl::opt ProfileVerifierDisableAssertions("profile-verifier-noassert", cl::desc("Disable assertions")); -namespace llvm { +namespace { template class ProfileVerifierPassT : public FunctionPass { @@ -59,11 +60,13 @@ namespace llvm { public: static char ID; // Class identification, replacement for typeinfo - explicit ProfileVerifierPassT () : FunctionPass(&ID) { + explicit ProfileVerifierPassT () : FunctionPass(ID) { + initializeProfileVerifierPassPass(*PassRegistry::getPassRegistry()); DisableAssertions = ProfileVerifierDisableAssertions; } - explicit ProfileVerifierPassT (bool da) : FunctionPass(&ID), + explicit ProfileVerifierPassT (bool da) : FunctionPass(ID), DisableAssertions(da) { + initializeProfileVerifierPassPass(*PassRegistry::getPassRegistry()); } void getAnalysisUsage(AnalysisUsage &AU) const { @@ -96,13 +99,13 @@ namespace llvm { double inWeight = 0; int inCount = 0; std::set ProcessedPreds; - for ( pred_const_iterator bbi = pred_begin(BB), bbe = pred_end(BB); - bbi != bbe; ++bbi ) { + for (const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB); + bbi != bbe; ++bbi ) { if (ProcessedPreds.insert(*bbi).second) { typename ProfileInfoT::Edge E = PI->getEdge(*bbi,BB); double EdgeWeight = PI->getEdgeWeight(E); if (EdgeWeight == ProfileInfoT::MissingValue) { EdgeWeight = 0; } - errs() << "calculated in-edge " << E << ": " + dbgs() << "calculated in-edge " << E << ": " << format("%20.20g",EdgeWeight) << "\n"; inWeight += EdgeWeight; inCount++; @@ -117,14 +120,14 @@ namespace llvm { typename ProfileInfoT::Edge E = PI->getEdge(BB,*bbi); double EdgeWeight = PI->getEdgeWeight(E); if (EdgeWeight == ProfileInfoT::MissingValue) { EdgeWeight = 0; } - errs() << "calculated out-edge " << E << ": " + dbgs() << "calculated out-edge " << E << ": " << format("%20.20g",EdgeWeight) << "\n"; outWeight += EdgeWeight; outCount++; } } - errs() << "Block " << BB->getNameStr() << " in " - << BB->getParent()->getNameStr() << ":" + dbgs() << "Block " << BB->getName() << " in " + << BB->getParent()->getName() << ":" << "BBWeight=" << format("%20.20g",BBWeight) << "," << "inWeight=" << format("%20.20g",inWeight) << "," << "inCount=" << inCount << "," @@ -141,8 +144,8 @@ namespace llvm { template void ProfileVerifierPassT::debugEntry (DetailedBlockInfo *DI) { - errs() << "TROUBLE: Block " << DI->BB->getNameStr() << " in " - << DI->BB->getParent()->getNameStr() << ":" + dbgs() << "TROUBLE: Block " << DI->BB->getName() << " in " + << DI->BB->getParent()->getName() << ":" << "BBWeight=" << format("%20.20g",DI->BBWeight) << "," << "inWeight=" << format("%20.20g",DI->inWeight) << "," << "inCount=" << DI->inCount << "," @@ -191,21 +194,21 @@ namespace llvm { } #define ASSERTMESSAGE(M) \ - { errs() << "ASSERT:" << (M) << "\n"; \ + { dbgs() << "ASSERT:" << (M) << "\n"; \ if (!DisableAssertions) assert(0 && (M)); } template double ProfileVerifierPassT::ReadOrAssert(typename ProfileInfoT::Edge E) { double EdgeWeight = PI->getEdgeWeight(E); if (EdgeWeight == ProfileInfoT::MissingValue) { - errs() << "Edge " << E << " in Function " - << ProfileInfoT::getFunction(E)->getNameStr() << ": "; + dbgs() << "Edge " << E << " in Function " + << ProfileInfoT::getFunction(E)->getName() << ": "; ASSERTMESSAGE("Edge has missing value"); return 0; } else { if (EdgeWeight < 0) { - errs() << "Edge " << E << " in Function " - << ProfileInfoT::getFunction(E)->getNameStr() << ": "; + dbgs() << "Edge " << E << " in Function " + << ProfileInfoT::getFunction(E)->getName() << ": "; ASSERTMESSAGE("Edge has negative value"); } return EdgeWeight; @@ -218,8 +221,8 @@ namespace llvm { DetailedBlockInfo *DI) { if (Error) { DEBUG(debugEntry(DI)); - errs() << "Block " << DI->BB->getNameStr() << " in Function " - << DI->BB->getParent()->getNameStr() << ": "; + dbgs() << "Block " << DI->BB->getName() << " in Function " + << DI->BB->getParent()->getName() << ": "; ASSERTMESSAGE(Message); } return; @@ -242,7 +245,7 @@ namespace llvm { // Read predecessors. std::set ProcessedPreds; - pred_const_iterator bpi = pred_begin(BB), bpe = pred_end(BB); + const_pred_iterator bpi = pred_begin(BB), bpe = pred_end(BB); // If there are none, check for (0,BB) edge. if (bpi == bpe) { DI.inWeight += ReadOrAssert(PI->getEdge(0,BB)); @@ -287,7 +290,7 @@ namespace llvm { i != ie; ++i) { if (const CallInst *CI = dyn_cast(&*i)) { FType *F = CI->getCalledFunction(); - if (F && (F->getNameStr() == "_setjmp")) { + if (F && (F->getName() == "_setjmp")) { isSetJmpTarget = true; break; } } @@ -366,8 +369,11 @@ namespace llvm { char ProfileVerifierPassT::ID = 0; } -static RegisterPass -X("profile-verifier", "Verify profiling information", false, true); +INITIALIZE_PASS_BEGIN(ProfileVerifierPass, "profile-verifier", + "Verify profiling information", false, true) +INITIALIZE_AG_DEPENDENCY(ProfileInfo) +INITIALIZE_PASS_END(ProfileVerifierPass, "profile-verifier", + "Verify profiling information", false, true) namespace llvm { FunctionPass *createProfileVerifierPass() {