1218885Sdim//===- PathProfileInfo.h --------------------------------------*- C++ -*---===//
2218885Sdim//
3218885Sdim//                     The LLVM Compiler Infrastructure
4218885Sdim//
5218885Sdim// This file is distributed under the University of Illinois Open Source
6218885Sdim// License. See LICENSE.TXT for details.
7218885Sdim//
8218885Sdim//===----------------------------------------------------------------------===//
9218885Sdim//
10218885Sdim// This file outlines the interface used by optimizers to load path profiles.
11218885Sdim//
12218885Sdim//===----------------------------------------------------------------------===//
13218885Sdim
14249423Sdim#ifndef LLVM_ANALYSIS_PATHPROFILEINFO_H
15249423Sdim#define LLVM_ANALYSIS_PATHPROFILEINFO_H
16218885Sdim
17218885Sdim#include "llvm/Analysis/PathNumbering.h"
18249423Sdim#include "llvm/IR/BasicBlock.h"
19218885Sdim
20218885Sdimnamespace llvm {
21218885Sdim
22218885Sdimclass ProfilePath;
23218885Sdimclass ProfilePathEdge;
24218885Sdimclass PathProfileInfo;
25218885Sdim
26218885Sdimtypedef std::vector<ProfilePathEdge> ProfilePathEdgeVector;
27218885Sdimtypedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator;
28218885Sdim
29218885Sdimtypedef std::vector<BasicBlock*> ProfilePathBlockVector;
30218885Sdimtypedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator;
31218885Sdim
32218885Sdimtypedef std::map<unsigned int,ProfilePath*> ProfilePathMap;
33218885Sdimtypedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator;
34218885Sdim
35218885Sdimtypedef std::map<Function*,unsigned int> FunctionPathCountMap;
36218885Sdimtypedef std::map<Function*,ProfilePathMap> FunctionPathMap;
37218885Sdimtypedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator;
38218885Sdim
39218885Sdimclass ProfilePathEdge {
40218885Sdimpublic:
41218885Sdim  ProfilePathEdge(BasicBlock* source, BasicBlock* target,
42218885Sdim                  unsigned duplicateNumber);
43218885Sdim
44218885Sdim  inline unsigned getDuplicateNumber() { return _duplicateNumber; }
45218885Sdim  inline BasicBlock* getSource() { return _source; }
46218885Sdim  inline BasicBlock* getTarget() { return _target; }
47218885Sdim
48218885Sdimprotected:
49218885Sdim  BasicBlock* _source;
50218885Sdim  BasicBlock* _target;
51218885Sdim  unsigned _duplicateNumber;
52218885Sdim};
53218885Sdim
54218885Sdimclass ProfilePath {
55218885Sdimpublic:
56218885Sdim  ProfilePath(unsigned int number, unsigned int count,
57218885Sdim              double countStdDev, PathProfileInfo* ppi);
58218885Sdim
59218885Sdim  double getFrequency() const;
60218885Sdim
61218885Sdim  inline unsigned int getNumber() const { return _number; }
62218885Sdim  inline unsigned int getCount() const { return _count; }
63218885Sdim  inline double getCountStdDev() const { return _countStdDev; }
64218885Sdim
65218885Sdim  ProfilePathEdgeVector* getPathEdges() const;
66218885Sdim  ProfilePathBlockVector* getPathBlocks() const;
67218885Sdim
68218885Sdim  BasicBlock* getFirstBlockInPath() const;
69218885Sdim
70218885Sdimprivate:
71218885Sdim  unsigned int _number;
72218885Sdim  unsigned int _count;
73218885Sdim  double _countStdDev;
74218885Sdim
75218885Sdim  // double pointer back to the profiling info
76218885Sdim  PathProfileInfo* _ppi;
77218885Sdim};
78218885Sdim
79218885Sdim// TODO: overload [] operator for getting path
80218885Sdim// Add: getFunctionCallCount()
81218885Sdimclass PathProfileInfo {
82218885Sdim  public:
83218885Sdim  PathProfileInfo();
84218885Sdim  ~PathProfileInfo();
85218885Sdim
86218885Sdim  void setCurrentFunction(Function* F);
87218885Sdim  Function* getCurrentFunction() const;
88218885Sdim  BasicBlock* getCurrentFunctionEntry();
89218885Sdim
90218885Sdim  ProfilePath* getPath(unsigned int number);
91218885Sdim  unsigned int getPotentialPathCount();
92218885Sdim
93218885Sdim  ProfilePathIterator pathBegin();
94218885Sdim  ProfilePathIterator pathEnd();
95218885Sdim  unsigned int pathsRun();
96218885Sdim
97218885Sdim  static char ID; // Pass identification
98218885Sdim  std::string argList;
99218885Sdim
100218885Sdimprotected:
101218885Sdim  FunctionPathMap _functionPaths;
102218885Sdim  FunctionPathCountMap _functionPathCounts;
103218885Sdim
104218885Sdimprivate:
105218885Sdim  BallLarusDag* _currentDag;
106218885Sdim  Function* _currentFunction;
107218885Sdim
108218885Sdim  friend class ProfilePath;
109218885Sdim};
110218885Sdim} // end namespace llvm
111218885Sdim
112218885Sdim#endif
113