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. 00018 // 00019 //===----------------------------------------------------------------------===// 00020 00021 #ifndef LLVM_ANALYSIS_PROFILEINFO_H 00022 #define LLVM_ANALYSIS_PROFILEINFO_H 00023 00024 #include <string> 00025 #include <map> 00026 00027 namespace llvm { 00028 class BasicBlock; 00029 class Pass; 00030 00031 /// ProfileInfo Class - This class holds and maintains edge profiling 00032 /// information for some unit of code. 00033 class ProfileInfo { 00034 protected: 00035 // EdgeCounts - Count the number of times a transition between two blocks is 00036 // executed. As a special case, we also hold an edge from the null 00037 // BasicBlock to the entry block to indicate how many times the function was 00038 // entered. 00039 std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned> EdgeCounts; 00040 public: 00041 static char ID; // Class identification, replacement for typeinfo 00042 virtual ~ProfileInfo(); // We want to be subclassed 00043 00044 //===------------------------------------------------------------------===// 00045 /// Profile Information Queries 00046 /// 00047 unsigned getExecutionCount(BasicBlock *BB) const; 00048 00049 unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dest) const { 00050 std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned>::const_iterator I= 00051 EdgeCounts.find(std::make_pair(Src, Dest)); 00052 return I != EdgeCounts.end() ? I->second : 0; 00053 } 00054 00055 //===------------------------------------------------------------------===// 00056 /// Analysis Update Methods 00057 /// 00058 00059 }; 00060 00061 /// createProfileLoaderPass - This function returns a Pass that loads the 00062 /// profiling information for the module from the specified filename, making 00063 /// it available to the optimizers. 00064 Pass *createProfileLoaderPass(const std::string &Filename); 00065 } // End llvm namespace 00066 00067 #endif