LLVM  13.0.0git
ValueProfileCollector.h
Go to the documentation of this file.
1 //===- ValueProfileCollector.h - determine what to value profile ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a utility class, ValueProfileCollector, that is used to
10 // determine what kind of llvm::Value's are worth value-profiling, at which
11 // point in the program, and which instruction holds the Value Profile metadata.
12 // Currently, the only users of this utility is the PGOInstrumentation[Gen|Use]
13 // passes.
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_ANALYSIS_PROFILE_GEN_ANALYSIS_H
17 #define LLVM_ANALYSIS_PROFILE_GEN_ANALYSIS_H
18 
21 #include <memory>
22 #include <vector>
23 
24 namespace llvm {
25 
26 class Function;
27 class Instruction;
28 class Value;
29 
30 /// Utility analysis that determines what values are worth profiling.
31 /// The actual logic is inside the ValueProfileCollectorImpl, whose job is to
32 /// populate the Candidates vector.
33 ///
34 /// Value profiling an expression means to track the values that this expression
35 /// takes at runtime and the frequency of each value.
36 /// It is important to distinguish between two sets of value profiles for a
37 /// particular expression:
38 /// 1) The set of values at the point of evaluation.
39 /// 2) The set of values at the point of use.
40 /// In some cases, the two sets are identical, but it's not unusual for the two
41 /// to differ.
42 ///
43 /// To elaborate more, consider this C code, and focus on the expression `nn`:
44 /// void foo(int nn, bool b) {
45 /// if (b) memcpy(x, y, nn);
46 /// }
47 /// The point of evaluation can be as early as the start of the function, and
48 /// let's say the value profile for `nn` is:
49 /// total=100; (value,freq) set = {(8,10), (32,50)}
50 /// The point of use is right before we call memcpy, and since we execute the
51 /// memcpy conditionally, the value profile of `nn` can be:
52 /// total=15; (value,freq) set = {(8,10), (4,5)}
53 ///
54 /// For this reason, a plugin is responsible for computing the insertion point
55 /// for each value to be profiled. The `CandidateInfo` structure encapsulates
56 /// all the information needed for each value profile site.
58 public:
59  struct CandidateInfo {
60  Value *V; // The value to profile.
61  Instruction *InsertPt; // Insert the VP lib call before this instr.
62  Instruction *AnnotatedInst; // Where metadata is attached.
63  };
64 
68 
72 
73  /// returns a list of value profiling candidates of the given kind
74  std::vector<CandidateInfo> get(InstrProfValueKind Kind) const;
75 
76 private:
78  std::unique_ptr<ValueProfileCollectorImpl> PImpl;
79 };
80 
81 } // namespace llvm
82 
83 #endif
llvm
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:61
llvm::ValueProfileCollector::ValueProfileCollectorImpl
ValueProfileCollectorImpl inherits the API of PluginChainFinal.
Definition: ValueProfileCollector.cpp:64
llvm::ValueProfileCollector::~ValueProfileCollector
~ValueProfileCollector()
llvm::ValueProfileCollector::operator=
ValueProfileCollector & operator=(ValueProfileCollector &&)=delete
llvm::ValueProfileCollector::CandidateInfo::V
Value * V
Definition: ValueProfileCollector.h:60
llvm::ValueProfileCollector::CandidateInfo::AnnotatedInst
Instruction * AnnotatedInst
Definition: ValueProfileCollector.h:62
TargetLibraryInfo.h
llvm::ValueProfileCollector::ValueProfileCollector
ValueProfileCollector(Function &Fn, TargetLibraryInfo &TLI)
Definition: ValueProfileCollector.cpp:69
llvm::Instruction
Definition: Instruction.h:45
InstrProf.h
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::ValueProfileCollector::CandidateInfo::InsertPt
Instruction * InsertPt
Definition: ValueProfileCollector.h:61
llvm::InstrProfValueKind
InstrProfValueKind
Definition: InstrProf.h:238
llvm::ValueProfileCollector
Utility analysis that determines what values are worth profiling.
Definition: ValueProfileCollector.h:57
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::ValueProfileCollector::CandidateInfo
Definition: ValueProfileCollector.h:59
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:208
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::ValueProfileCollector::get
std::vector< CandidateInfo > get(InstrProfValueKind Kind) const
returns a list of value profiling candidates of the given kind
Definition: ValueProfileCollector.cpp:76
llvm::codeview::PublicSymFlags::Function
@ Function