1 //===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the generic ProfileInfo interface, which is used as the
11 // common interface used by all clients of profiling information, and
12 // implemented either by making static guestimations, or by actually reading in
13 // profiling information gathered by running the program.
15 // Note that to be useful, all profile-based optimizations should preserve
16 // ProfileInfo, which requires that they notify it when changes to the CFG are
17 // made. (This is not implemented yet.)
19 //===----------------------------------------------------------------------===//
21 #ifndef LLVM_ANALYSIS_PROFILEINFO_H
22 #define LLVM_ANALYSIS_PROFILEINFO_H
24 #include "llvm/BasicBlock.h"
33 /// ProfileInfo Class - This class holds and maintains profiling
34 /// information for some unit of code.
37 // Types for handling profiling information.
38 typedef std::pair<const BasicBlock*, const BasicBlock*> Edge;
39 typedef std::map<Edge, double> EdgeCounts;
40 typedef std::map<const BasicBlock*, double> BlockCounts;
43 // EdgeCounts - Count the number of times a transition between two blocks is
44 // executed. As a special case, we also hold an edge from the null
45 // BasicBlock to the entry block to indicate how many times the function was
47 std::map<const Function*, EdgeCounts> EdgeInformation;
49 // BlockCounts - Count the number of times a block is executed.
50 std::map<const Function*, BlockCounts> BlockInformation;
52 // FunctionCounts - Count the number of times a function is executed.
53 std::map<const Function*, double> FunctionInformation;
55 static char ID; // Class identification, replacement for typeinfo
56 virtual ~ProfileInfo(); // We want to be subclassed
58 // MissingValue - The value that is returned for execution counts in case
59 // no value is available.
60 static const int MissingValue = -1;
62 // getFunction() - Returns the Function for an Edge, checking for validity.
63 static const Function* getFunction(Edge e) {
64 assert(e.second && "Invalid ProfileInfo::Edge");
65 return e.second->getParent();
68 // getEdge() - Creates an Edge from two BasicBlocks.
69 static Edge getEdge(const BasicBlock* Src, const BasicBlock* Dest) {
70 return std::make_pair(Src,Dest);
73 //===------------------------------------------------------------------===//
74 /// Profile Information Queries
76 double getExecutionCount(const Function *F);
78 double getExecutionCount(const BasicBlock *BB);
80 double getEdgeWeight(Edge e) const {
81 std::map<const Function*, EdgeCounts>::const_iterator J =
82 EdgeInformation.find(getFunction(e));
83 if (J == EdgeInformation.end()) return MissingValue;
85 EdgeCounts::const_iterator I = J->second.find(e);
86 if (I == J->second.end()) return MissingValue;
91 //===------------------------------------------------------------------===//
92 /// Analysis Update Methods
97 /// createProfileLoaderPass - This function returns a Pass that loads the
98 /// profiling information for the module from the specified filename, making
99 /// it available to the optimizers.
100 Pass *createProfileLoaderPass(const std::string &Filename);
101 } // End llvm namespace