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