summaryrefslogtreecommitdiff
path: root/include/llvm/Analysis/PathProfileInfo.h
blob: 53880694f0632906ac86f1bdaeda1be9bbce5a02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//===- PathProfileInfo.h --------------------------------------*- C++ -*---===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file outlines the interface used by optimizers to load path profiles.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_PATHPROFILEINFO_H
#define LLVM_PATHPROFILEINFO_H

#include "llvm/Analysis/PathNumbering.h"
#include "llvm/BasicBlock.h"

namespace llvm {

class ProfilePath;
class ProfilePathEdge;
class PathProfileInfo;

typedef std::vector<ProfilePathEdge> ProfilePathEdgeVector;
typedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator;

typedef std::vector<BasicBlock*> ProfilePathBlockVector;
typedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator;

typedef std::map<unsigned int,ProfilePath*> ProfilePathMap;
typedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator;

typedef std::map<Function*,unsigned int> FunctionPathCountMap;
typedef std::map<Function*,ProfilePathMap> FunctionPathMap;
typedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator;

class ProfilePathEdge {
public:
  ProfilePathEdge(BasicBlock* source, BasicBlock* target,
                  unsigned duplicateNumber);

  inline unsigned getDuplicateNumber() { return _duplicateNumber; }
  inline BasicBlock* getSource() { return _source; }
  inline BasicBlock* getTarget() { return _target; }

protected:
  BasicBlock* _source;
  BasicBlock* _target;
  unsigned _duplicateNumber;
};

class ProfilePath {
public:
  ProfilePath(unsigned int number, unsigned int count,
              double countStdDev, PathProfileInfo* ppi);

  double getFrequency() const;

  inline unsigned int getNumber() const { return _number; }
  inline unsigned int getCount() const { return _count; }
  inline double getCountStdDev() const { return _countStdDev; }

  ProfilePathEdgeVector* getPathEdges() const;
  ProfilePathBlockVector* getPathBlocks() const;

  BasicBlock* getFirstBlockInPath() const;

private:
  unsigned int _number;
  unsigned int _count;
  double _countStdDev;

  // double pointer back to the profiling info
  PathProfileInfo* _ppi;
};

// TODO: overload [] operator for getting path
// Add: getFunctionCallCount()
class PathProfileInfo {
  public:
  PathProfileInfo();
  ~PathProfileInfo();

  void setCurrentFunction(Function* F);
  Function* getCurrentFunction() const;
  BasicBlock* getCurrentFunctionEntry();

  ProfilePath* getPath(unsigned int number);
  unsigned int getPotentialPathCount();

  ProfilePathIterator pathBegin();
  ProfilePathIterator pathEnd();
  unsigned int pathsRun();

  static char ID; // Pass identification
  std::string argList;

protected:
  FunctionPathMap _functionPaths;
  FunctionPathCountMap _functionPathCounts;

private:
  BallLarusDag* _currentDag;
  Function* _currentFunction;

  friend class ProfilePath;
};
} // end namespace llvm

#endif