mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
ProfileInfo interface tweaks.
- Add getExecutionCount(const Function). - Add helper Edge type. - constify. - No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75623 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -26,17 +26,22 @@
|
|||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class BasicBlock;
|
class BasicBlock;
|
||||||
|
class Function;
|
||||||
class Pass;
|
class Pass;
|
||||||
|
|
||||||
/// ProfileInfo Class - This class holds and maintains edge profiling
|
/// ProfileInfo Class - This class holds and maintains edge profiling
|
||||||
/// information for some unit of code.
|
/// information for some unit of code.
|
||||||
class ProfileInfo {
|
class ProfileInfo {
|
||||||
|
public:
|
||||||
|
// Types for handling profiling information.
|
||||||
|
typedef std::pair<const BasicBlock*, const BasicBlock*> Edge;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// EdgeCounts - Count the number of times a transition between two blocks is
|
// EdgeCounts - Count the number of times a transition between two blocks is
|
||||||
// executed. As a special case, we also hold an edge from the null
|
// executed. As a special case, we also hold an edge from the null
|
||||||
// BasicBlock to the entry block to indicate how many times the function was
|
// BasicBlock to the entry block to indicate how many times the function was
|
||||||
// entered.
|
// entered.
|
||||||
std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned> EdgeCounts;
|
std::map<Edge, unsigned> EdgeCounts;
|
||||||
public:
|
public:
|
||||||
static char ID; // Class identification, replacement for typeinfo
|
static char ID; // Class identification, replacement for typeinfo
|
||||||
virtual ~ProfileInfo(); // We want to be subclassed
|
virtual ~ProfileInfo(); // We want to be subclassed
|
||||||
@@ -44,10 +49,13 @@ namespace llvm {
|
|||||||
//===------------------------------------------------------------------===//
|
//===------------------------------------------------------------------===//
|
||||||
/// Profile Information Queries
|
/// Profile Information Queries
|
||||||
///
|
///
|
||||||
unsigned getExecutionCount(BasicBlock *BB) const;
|
unsigned getExecutionCount(const Function *F) const;
|
||||||
|
|
||||||
unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dest) const {
|
unsigned getExecutionCount(const BasicBlock *BB) const;
|
||||||
std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned>::const_iterator I=
|
|
||||||
|
unsigned getEdgeWeight(const BasicBlock *Src,
|
||||||
|
const BasicBlock *Dest) const {
|
||||||
|
std::map<Edge, unsigned>::const_iterator I =
|
||||||
EdgeCounts.find(std::make_pair(Src, Dest));
|
EdgeCounts.find(std::make_pair(Src, Dest));
|
||||||
return I != EdgeCounts.end() ? I->second : 0;
|
return I != EdgeCounts.end() ? I->second : 0;
|
||||||
}
|
}
|
||||||
|
@@ -26,8 +26,8 @@ char ProfileInfo::ID = 0;
|
|||||||
|
|
||||||
ProfileInfo::~ProfileInfo() {}
|
ProfileInfo::~ProfileInfo() {}
|
||||||
|
|
||||||
unsigned ProfileInfo::getExecutionCount(BasicBlock *BB) const {
|
unsigned ProfileInfo::getExecutionCount(const BasicBlock *BB) const {
|
||||||
pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
||||||
|
|
||||||
// Are there zero predecessors of this block?
|
// Are there zero predecessors of this block?
|
||||||
if (PI == PE) {
|
if (PI == PE) {
|
||||||
@@ -49,23 +49,23 @@ unsigned ProfileInfo::getExecutionCount(BasicBlock *BB) const {
|
|||||||
// has a LARGE number of in-edges. Handle the common case of having only a
|
// has a LARGE number of in-edges. Handle the common case of having only a
|
||||||
// few in-edges with special code.
|
// few in-edges with special code.
|
||||||
//
|
//
|
||||||
BasicBlock *FirstPred = *PI;
|
const BasicBlock *FirstPred = *PI;
|
||||||
unsigned Count = getEdgeWeight(FirstPred, BB);
|
unsigned Count = getEdgeWeight(FirstPred, BB);
|
||||||
++PI;
|
++PI;
|
||||||
if (PI == PE) return Count; // Quick exit for single predecessor blocks
|
if (PI == PE) return Count; // Quick exit for single predecessor blocks
|
||||||
|
|
||||||
BasicBlock *SecondPred = *PI;
|
const BasicBlock *SecondPred = *PI;
|
||||||
if (SecondPred != FirstPred) Count += getEdgeWeight(SecondPred, BB);
|
if (SecondPred != FirstPred) Count += getEdgeWeight(SecondPred, BB);
|
||||||
++PI;
|
++PI;
|
||||||
if (PI == PE) return Count; // Quick exit for two predecessor blocks
|
if (PI == PE) return Count; // Quick exit for two predecessor blocks
|
||||||
|
|
||||||
BasicBlock *ThirdPred = *PI;
|
const BasicBlock *ThirdPred = *PI;
|
||||||
if (ThirdPred != FirstPred && ThirdPred != SecondPred)
|
if (ThirdPred != FirstPred && ThirdPred != SecondPred)
|
||||||
Count += getEdgeWeight(ThirdPred, BB);
|
Count += getEdgeWeight(ThirdPred, BB);
|
||||||
++PI;
|
++PI;
|
||||||
if (PI == PE) return Count; // Quick exit for three predecessor blocks
|
if (PI == PE) return Count; // Quick exit for three predecessor blocks
|
||||||
|
|
||||||
std::set<BasicBlock*> ProcessedPreds;
|
std::set<const BasicBlock*> ProcessedPreds;
|
||||||
ProcessedPreds.insert(FirstPred);
|
ProcessedPreds.insert(FirstPred);
|
||||||
ProcessedPreds.insert(SecondPred);
|
ProcessedPreds.insert(SecondPred);
|
||||||
ProcessedPreds.insert(ThirdPred);
|
ProcessedPreds.insert(ThirdPred);
|
||||||
@@ -75,6 +75,10 @@ unsigned ProfileInfo::getExecutionCount(BasicBlock *BB) const {
|
|||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned ProfileInfo::getExecutionCount(const Function *F) const {
|
||||||
|
if (F->isDeclaration()) return -1;
|
||||||
|
return getExecutionCount(&F->getEntryBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Reference in New Issue
Block a user