1 //===- PathProfileInfo.h --------------------------------------*- C++ -*---===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file outlines the interface used by optimizers to load path profiles. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_PATHPROFILEINFO_H 15 #define LLVM_PATHPROFILEINFO_H 16 17 #include "llvm/BasicBlock.h" 18 #include "llvm/Analysis/PathNumbering.h" 19 20 namespace llvm { 21 22 class ProfilePath; 23 class ProfilePathEdge; 24 class PathProfileInfo; 25 26 typedef std::vector<ProfilePathEdge> ProfilePathEdgeVector; 27 typedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator; 28 29 typedef std::vector<BasicBlock*> ProfilePathBlockVector; 30 typedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator; 31 32 typedef std::map<unsigned int,ProfilePath*> ProfilePathMap; 33 typedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator; 34 35 typedef std::map<Function*,unsigned int> FunctionPathCountMap; 36 typedef std::map<Function*,ProfilePathMap> FunctionPathMap; 37 typedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator; 38 39 class ProfilePathEdge { 40 public: 41 ProfilePathEdge(BasicBlock* source, BasicBlock* target, 42 unsigned duplicateNumber); 43 getDuplicateNumber()44 inline unsigned getDuplicateNumber() { return _duplicateNumber; } getSource()45 inline BasicBlock* getSource() { return _source; } getTarget()46 inline BasicBlock* getTarget() { return _target; } 47 48 protected: 49 BasicBlock* _source; 50 BasicBlock* _target; 51 unsigned _duplicateNumber; 52 }; 53 54 class ProfilePath { 55 public: 56 ProfilePath(unsigned int number, unsigned int count, 57 double countStdDev, PathProfileInfo* ppi); 58 59 double getFrequency() const; 60 getNumber()61 inline unsigned int getNumber() const { return _number; } getCount()62 inline unsigned int getCount() const { return _count; } getCountStdDev()63 inline double getCountStdDev() const { return _countStdDev; } 64 65 ProfilePathEdgeVector* getPathEdges() const; 66 ProfilePathBlockVector* getPathBlocks() const; 67 68 BasicBlock* getFirstBlockInPath() const; 69 70 private: 71 unsigned int _number; 72 unsigned int _count; 73 double _countStdDev; 74 75 // double pointer back to the profiling info 76 PathProfileInfo* _ppi; 77 }; 78 79 // TODO: overload [] operator for getting path 80 // Add: getFunctionCallCount() 81 class PathProfileInfo { 82 public: 83 PathProfileInfo(); 84 ~PathProfileInfo(); 85 86 void setCurrentFunction(Function* F); 87 Function* getCurrentFunction() const; 88 BasicBlock* getCurrentFunctionEntry(); 89 90 ProfilePath* getPath(unsigned int number); 91 unsigned int getPotentialPathCount(); 92 93 ProfilePathIterator pathBegin(); 94 ProfilePathIterator pathEnd(); 95 unsigned int pathsRun(); 96 97 static char ID; // Pass identification 98 std::string argList; 99 100 protected: 101 FunctionPathMap _functionPaths; 102 FunctionPathCountMap _functionPathCounts; 103 104 private: 105 BallLarusDag* _currentDag; 106 Function* _currentFunction; 107 108 friend class ProfilePath; 109 }; 110 } // end namespace llvm 111 112 #endif 113