2004-02-10 22:11:42 +00:00
|
|
|
//===- ProfileInfo.cpp - Profile Info Interface ---------------------------===//
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2004-02-10 22:11:42 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 21:13:18 +00:00
|
|
|
//
|
2004-02-10 22:11:42 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the abstract ProfileInfo interface, and the default
|
|
|
|
// "no profile" implementation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-01-08 22:01:16 +00:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
2004-02-10 22:11:42 +00:00
|
|
|
#include "llvm/Analysis/ProfileInfo.h"
|
|
|
|
#include "llvm/Pass.h"
|
2004-03-08 22:04:08 +00:00
|
|
|
#include "llvm/Support/CFG.h"
|
2007-02-05 23:42:17 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2004-03-08 22:04:08 +00:00
|
|
|
#include <set>
|
2004-02-10 22:11:42 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2004-02-11 06:10:18 +00:00
|
|
|
// Register the ProfileInfo interface, providing a nice name to refer to.
|
2008-05-13 00:00:25 +00:00
|
|
|
static RegisterAnalysisGroup<ProfileInfo> Z("Profile Information");
|
2007-05-03 01:11:54 +00:00
|
|
|
char ProfileInfo::ID = 0;
|
2004-02-10 22:11:42 +00:00
|
|
|
|
|
|
|
ProfileInfo::~ProfileInfo() {}
|
|
|
|
|
2009-08-08 17:43:09 +00:00
|
|
|
double ProfileInfo::getExecutionCount(const BasicBlock *BB) {
|
|
|
|
std::map<const Function*, BlockCounts>::iterator J =
|
|
|
|
BlockInformation.find(BB->getParent());
|
|
|
|
if (J != BlockInformation.end()) {
|
|
|
|
BlockCounts::iterator I = J->second.find(BB);
|
|
|
|
if (I != J->second.end())
|
|
|
|
return I->second;
|
|
|
|
}
|
2009-08-05 21:51:16 +00:00
|
|
|
|
2009-07-14 06:58:59 +00:00
|
|
|
pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
2004-03-08 22:04:08 +00:00
|
|
|
|
|
|
|
// Are there zero predecessors of this block?
|
|
|
|
if (PI == PE) {
|
|
|
|
// If this is the entry block, look for the Null -> Entry edge.
|
2007-03-22 16:38:57 +00:00
|
|
|
if (BB == &BB->getParent()->getEntryBlock())
|
2009-08-08 17:43:09 +00:00
|
|
|
return getEdgeWeight(getEdge(0, BB));
|
2004-03-08 22:04:08 +00:00
|
|
|
else
|
|
|
|
return 0; // Otherwise, this is a dead block.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, if there are predecessors, the execution count of this block is
|
2009-08-08 17:43:09 +00:00
|
|
|
// the sum of the edge frequencies from the incoming edges.
|
2009-07-14 06:58:59 +00:00
|
|
|
std::set<const BasicBlock*> ProcessedPreds;
|
2009-08-08 17:43:09 +00:00
|
|
|
double Count = 0;
|
2004-03-08 22:04:08 +00:00
|
|
|
for (; PI != PE; ++PI)
|
2009-08-08 17:43:09 +00:00
|
|
|
if (ProcessedPreds.insert(*PI).second) {
|
|
|
|
double w = getEdgeWeight(getEdge(*PI, BB));
|
|
|
|
if (w == MissingValue) {
|
2009-08-19 05:44:39 +00:00
|
|
|
Count = MissingValue;
|
|
|
|
break;
|
2009-08-08 17:43:09 +00:00
|
|
|
}
|
|
|
|
Count += w;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockInformation[BB->getParent()][BB] = Count;
|
2004-03-08 22:04:08 +00:00
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
2009-08-08 17:43:09 +00:00
|
|
|
double ProfileInfo::getExecutionCount(const Function *F) {
|
2009-08-08 18:59:03 +00:00
|
|
|
if (F->isDeclaration()) return MissingValue;
|
2009-08-08 17:43:09 +00:00
|
|
|
std::map<const Function*, double>::iterator J =
|
|
|
|
FunctionInformation.find(F);
|
|
|
|
if (J != FunctionInformation.end())
|
|
|
|
return J->second;
|
2009-08-05 21:51:16 +00:00
|
|
|
|
2009-08-08 17:43:09 +00:00
|
|
|
double Count = getExecutionCount(&F->getEntryBlock());
|
|
|
|
FunctionInformation[F] = Count;
|
|
|
|
return Count;
|
2009-07-14 06:58:59 +00:00
|
|
|
}
|
2004-03-08 22:04:08 +00:00
|
|
|
|
2004-02-10 22:11:42 +00:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// NoProfile ProfileInfo implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace {
|
2007-02-05 23:42:17 +00:00
|
|
|
struct VISIBILITY_HIDDEN NoProfileInfo
|
2007-05-01 21:15:47 +00:00
|
|
|
: public ImmutablePass, public ProfileInfo {
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
2008-09-04 17:05:41 +00:00
|
|
|
NoProfileInfo() : ImmutablePass(&ID) {}
|
2007-05-01 21:15:47 +00:00
|
|
|
};
|
2008-05-13 00:00:25 +00:00
|
|
|
} // End of anonymous namespace
|
2005-04-21 21:13:18 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
char NoProfileInfo::ID = 0;
|
|
|
|
// Register this pass...
|
|
|
|
static RegisterPass<NoProfileInfo>
|
|
|
|
X("no-profile", "No Profile Information", false, true);
|
2004-02-10 22:11:42 +00:00
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
// Declare that we implement the ProfileInfo interface
|
|
|
|
static RegisterAnalysisGroup<ProfileInfo, true> Y(X);
|
2005-01-08 22:01:16 +00:00
|
|
|
|
|
|
|
ImmutablePass *llvm::createNoProfileInfoPass() { return new NoProfileInfo(); }
|