LLVM API Documentation
00001 //===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the generic ProfileInfo interface, which is used as the 00011 // common interface used by all clients of profiling information, and 00012 // implemented either by making static guestimations, or by actually reading in 00013 // profiling information gathered by running the program. 00014 // 00015 // Note that to be useful, all profile-based optimizations should preserve 00016 // ProfileInfo, which requires that they notify it when changes to the CFG are 00017 // made. (This is not implemented yet.) 00018 // 00019 //===----------------------------------------------------------------------===// 00020 00021 #ifndef LLVM_ANALYSIS_PROFILEINFO_H 00022 #define LLVM_ANALYSIS_PROFILEINFO_H 00023 00024 #include "llvm/BasicBlock.h" 00025 #include <cassert> 00026 #include <string> 00027 #include <map> 00028 00029 namespace llvm { 00030 class Function; 00031 class Pass; 00032 00033 /// ProfileInfo Class - This class holds and maintains profiling 00034 /// information for some unit of code. 00035 class ProfileInfo { 00036 public: 00037 // Types for handling profiling information. 00038 typedef std::pair<const BasicBlock*, const BasicBlock*> Edge; 00039 typedef std::map<Edge, double> EdgeCounts; 00040 typedef std::map<const BasicBlock*, double> BlockCounts; 00041 00042 protected: 00043 // EdgeCounts - Count the number of times a transition between two blocks is 00044 // executed. As a special case, we also hold an edge from the null 00045 // BasicBlock to the entry block to indicate how many times the function was 00046 // entered. 00047 std::map<const Function*, EdgeCounts> EdgeInformation; 00048 00049 // BlockCounts - Count the number of times a block is executed. 00050 std::map<const Function*, BlockCounts> BlockInformation; 00051 00052 // FunctionCounts - Count the number of times a function is executed. 00053 std::map<const Function*, double> FunctionInformation; 00054 public: 00055 static char ID; // Class identification, replacement for typeinfo 00056 virtual ~ProfileInfo(); // We want to be subclassed 00057 00058 // MissingValue - The value that is returned for execution counts in case 00059 // no value is available. 00060 static const int MissingValue = -1; 00061 00062 // getFunction() - Returns the Function for an Edge, checking for validity. 00063 static const Function* getFunction(Edge e) { 00064 assert(e.second && "Invalid ProfileInfo::Edge"); 00065 return e.second->getParent(); 00066 } 00067 00068 // getEdge() - Creates an Edge from two BasicBlocks. 00069 static Edge getEdge(const BasicBlock* Src, const BasicBlock* Dest) { 00070 return std::make_pair(Src, Dest); 00071 } 00072 00073 //===------------------------------------------------------------------===// 00074 /// Profile Information Queries 00075 /// 00076 double getExecutionCount(const Function *F); 00077 00078 double getExecutionCount(const BasicBlock *BB); 00079 00080 double getEdgeWeight(Edge e) const { 00081 std::map<const Function*, EdgeCounts>::const_iterator J = 00082 EdgeInformation.find(getFunction(e)); 00083 if (J == EdgeInformation.end()) return MissingValue; 00084 00085 EdgeCounts::const_iterator I = J->second.find(e); 00086 if (I == J->second.end()) return MissingValue; 00087 00088 return I->second; 00089 } 00090 00091 //===------------------------------------------------------------------===// 00092 /// Analysis Update Methods 00093 /// 00094 00095 }; 00096 00097 /// createProfileLoaderPass - This function returns a Pass that loads the 00098 /// profiling information for the module from the specified filename, making 00099 /// it available to the optimizers. 00100 Pass *createProfileLoaderPass(const std::string &Filename); 00101 } // End llvm namespace 00102 00103 #endif