Don't attribute in file headers anymore. See llvmdev for the
[oota-llvm.git] / include / llvm / Analysis / ProfileInfo.h
1 //===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- 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 defines the generic ProfileInfo interface, which is used as the
11 // common interface used by all clients of profiling information, and
12 // implemented either by making static guestimations, or by actually reading in
13 // profiling information gathered by running the program.
14 //
15 // Note that to be useful, all profile-based optimizations should preserve
16 // ProfileInfo, which requires that they notify it when changes to the CFG are
17 // made.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_ANALYSIS_PROFILEINFO_H
22 #define LLVM_ANALYSIS_PROFILEINFO_H
23
24 #include <string>
25 #include <map>
26
27 namespace llvm {
28   class BasicBlock;
29   class Pass;
30
31   /// ProfileInfo Class - This class holds and maintains edge profiling
32   /// information for some unit of code.
33   class ProfileInfo {
34   protected:
35     // EdgeCounts - Count the number of times a transition between two blocks is
36     // executed.  As a special case, we also hold an edge from the null
37     // BasicBlock to the entry block to indicate how many times the function was
38     // entered.
39     std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned> EdgeCounts;
40   public:
41     static char ID; // Class identification, replacement for typeinfo
42     virtual ~ProfileInfo();  // We want to be subclassed
43
44     //===------------------------------------------------------------------===//
45     /// Profile Information Queries
46     ///
47     unsigned getExecutionCount(BasicBlock *BB) const;
48
49     unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dest) const {
50       std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned>::const_iterator I=
51         EdgeCounts.find(std::make_pair(Src, Dest));
52       return I != EdgeCounts.end() ? I->second : 0;
53     }
54
55     //===------------------------------------------------------------------===//
56     /// Analysis Update Methods
57     ///
58
59   };
60
61   /// createProfileLoaderPass - This function returns a Pass that loads the
62   /// profiling information for the module from the specified filename, making
63   /// it available to the optimizers.
64   Pass *createProfileLoaderPass(const std::string &Filename);
65 } // End llvm namespace
66
67 #endif