LLVM  4.0.0
ProfileCommon.h
Go to the documentation of this file.
1 //===-- ProfileCommon.h - Common profiling APIs. ----------------*- 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 contains data structures and functions common to both instrumented
11 // and sample profiling.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_PROFILEDATA_PROFILE_COMMON_H
16 #define LLVM_PROFILEDATA_PROFILE_COMMON_H
17 
18 #include <cstdint>
19 #include <functional>
20 #include <map>
21 #include <utility>
22 #include <vector>
23 
24 #include "llvm/IR/ProfileSummary.h"
25 #include "llvm/Support/Error.h"
26 #include "llvm/ADT/ArrayRef.h"
27 
28 namespace llvm {
29 class Function;
30 namespace IndexedInstrProf {
31 struct Summary;
32 }
33 namespace sampleprof {
34 class FunctionSamples;
35 }
36 struct InstrProfRecord;
37 class LLVMContext;
38 class Metadata;
39 class MDTuple;
40 class MDNode;
41 
42 inline const char *getHotSectionPrefix() { return ".hot"; }
43 inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }
44 
46 
47 private:
48  /// We keep track of the number of times a count (block count or samples)
49  /// appears in the profile. The map is kept sorted in the descending order of
50  /// counts.
51  std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
52  std::vector<uint32_t> DetailedSummaryCutoffs;
53 
54 protected:
56  ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
57  : DetailedSummaryCutoffs(std::move(Cutoffs)) {}
58  inline void addCount(uint64_t Count);
59  ~ProfileSummaryBuilder() = default;
61  uint64_t TotalCount = 0, MaxCount = 0, MaxFunctionCount = 0;
63 
64 public:
65  /// \brief A vector of useful cutoff values for detailed summary.
67 };
68 
70  uint64_t MaxInternalBlockCount = 0;
71  inline void addEntryCount(uint64_t Count);
72  inline void addInternalCount(uint64_t Count);
73 
74 public:
75  InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
76  : ProfileSummaryBuilder(std::move(Cutoffs)) {}
77  void addRecord(const InstrProfRecord &);
78  std::unique_ptr<ProfileSummary> getSummary();
79 };
80 
82 
83 public:
84  void addRecord(const sampleprof::FunctionSamples &FS);
85  SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
86  : ProfileSummaryBuilder(std::move(Cutoffs)) {}
87  std::unique_ptr<ProfileSummary> getSummary();
88 };
89 
90 /// This is called when a count is seen in the profile.
91 void ProfileSummaryBuilder::addCount(uint64_t Count) {
92  TotalCount += Count;
93  if (Count > MaxCount)
94  MaxCount = Count;
95  NumCounts++;
96  CountFrequencies[Count]++;
97 }
98 
99 
100 } // end namespace llvm
101 #endif
ProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:56
const char * getUnlikelySectionPrefix()
Definition: ProfileCommon.h:43
const char * getHotSectionPrefix()
Definition: ProfileCommon.h:42
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
Definition: ProfileCommon.h:66
Metadata node.
Definition: Metadata.h:830
void addCount(uint64_t Count)
This is called when a count is seen in the profile.
Definition: ProfileCommon.h:91
void addRecord(const InstrProfRecord &)
Tuple of metadata.
Definition: Metadata.h:1072
SampleProfileSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:85
Representation of the samples collected for a function.
Definition: SampleProf.h:181
InstrProfSummaryBuilder(std::vector< uint32_t > Cutoffs)
Definition: ProfileCommon.h:75
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
std::unique_ptr< ProfileSummary > getSummary()
void addRecord(const sampleprof::FunctionSamples &FS)
SummaryEntryVector DetailedSummary
Definition: ProfileCommon.h:55
std::unique_ptr< ProfileSummary > getSummary()
Profiling information for a single function.
Definition: InstrProf.h:581
Root of the metadata hierarchy.
Definition: Metadata.h:55
std::vector< ProfileSummaryEntry > SummaryEntryVector