LLVM API Documentation
00001 //===- PathProfileInfo.h --------------------------------------*- 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 outlines the interface used by optimizers to load path profiles. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ANALYSIS_PATHPROFILEINFO_H 00015 #define LLVM_ANALYSIS_PATHPROFILEINFO_H 00016 00017 #include "llvm/Analysis/PathNumbering.h" 00018 #include "llvm/IR/BasicBlock.h" 00019 00020 namespace llvm { 00021 00022 class ProfilePath; 00023 class ProfilePathEdge; 00024 class PathProfileInfo; 00025 00026 typedef std::vector<ProfilePathEdge> ProfilePathEdgeVector; 00027 typedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator; 00028 00029 typedef std::vector<BasicBlock*> ProfilePathBlockVector; 00030 typedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator; 00031 00032 typedef std::map<unsigned int,ProfilePath*> ProfilePathMap; 00033 typedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator; 00034 00035 typedef std::map<Function*,unsigned int> FunctionPathCountMap; 00036 typedef std::map<Function*,ProfilePathMap> FunctionPathMap; 00037 typedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator; 00038 00039 class ProfilePathEdge { 00040 public: 00041 ProfilePathEdge(BasicBlock* source, BasicBlock* target, 00042 unsigned duplicateNumber); 00043 00044 inline unsigned getDuplicateNumber() { return _duplicateNumber; } 00045 inline BasicBlock* getSource() { return _source; } 00046 inline BasicBlock* getTarget() { return _target; } 00047 00048 protected: 00049 BasicBlock* _source; 00050 BasicBlock* _target; 00051 unsigned _duplicateNumber; 00052 }; 00053 00054 class ProfilePath { 00055 public: 00056 ProfilePath(unsigned int number, unsigned int count, 00057 double countStdDev, PathProfileInfo* ppi); 00058 00059 double getFrequency() const; 00060 00061 inline unsigned int getNumber() const { return _number; } 00062 inline unsigned int getCount() const { return _count; } 00063 inline double getCountStdDev() const { return _countStdDev; } 00064 00065 ProfilePathEdgeVector* getPathEdges() const; 00066 ProfilePathBlockVector* getPathBlocks() const; 00067 00068 BasicBlock* getFirstBlockInPath() const; 00069 00070 private: 00071 unsigned int _number; 00072 unsigned int _count; 00073 double _countStdDev; 00074 00075 // double pointer back to the profiling info 00076 PathProfileInfo* _ppi; 00077 }; 00078 00079 // TODO: overload [] operator for getting path 00080 // Add: getFunctionCallCount() 00081 class PathProfileInfo { 00082 public: 00083 PathProfileInfo(); 00084 ~PathProfileInfo(); 00085 00086 void setCurrentFunction(Function* F); 00087 Function* getCurrentFunction() const; 00088 BasicBlock* getCurrentFunctionEntry(); 00089 00090 ProfilePath* getPath(unsigned int number); 00091 unsigned int getPotentialPathCount(); 00092 00093 ProfilePathIterator pathBegin(); 00094 ProfilePathIterator pathEnd(); 00095 unsigned int pathsRun(); 00096 00097 static char ID; // Pass identification 00098 std::string argList; 00099 00100 protected: 00101 FunctionPathMap _functionPaths; 00102 FunctionPathCountMap _functionPathCounts; 00103 00104 private: 00105 BallLarusDag* _currentDag; 00106 Function* _currentFunction; 00107 00108 friend class ProfilePath; 00109 }; 00110 } // end namespace llvm 00111 00112 #endif