LLVM  10.0.0svn
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 
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/Pass.h"
23 
24 namespace llvm {
25 
26 /// Utility analysis that determines what values are worth profiling.
27 /// The actual logic is inside the ValueProfileCollectorImpl, whose job is to
28 /// populate the Candidates vector.
29 ///
30 /// Value profiling an expression means to track the values that this expression
31 /// takes at runtime and the frequency of each value.
32 /// It is important to distinguish between two sets of value profiles for a
33 /// particular expression:
34 /// 1) The set of values at the point of evaluation.
35 /// 2) The set of values at the point of use.
36 /// In some cases, the two sets are identical, but it's not unusual for the two
37 /// to differ.
38 ///
39 /// To elaborate more, consider this C code, and focus on the expression `nn`:
40 /// void foo(int nn, bool b) {
41 /// if (b) memcpy(x, y, nn);
42 /// }
43 /// The point of evaluation can be as early as the start of the function, and
44 /// let's say the value profile for `nn` is:
45 /// total=100; (value,freq) set = {(8,10), (32,50)}
46 /// The point of use is right before we call memcpy, and since we execute the
47 /// memcpy conditionally, the value profile of `nn` can be:
48 /// total=15; (value,freq) set = {(8,10), (4,5)}
49 ///
50 /// For this reason, a plugin is responsible for computing the insertion point
51 /// for each value to be profiled. The `CandidateInfo` structure encapsulates
52 /// all the information needed for each value profile site.
54 public:
55  struct CandidateInfo {
56  Value *V; // The value to profile.
57  Instruction *InsertPt; // Insert the VP lib call before this instr.
58  Instruction *AnnotatedInst; // Where metadata is attached.
59  };
60 
64 
68 
69  /// returns a list of value profiling candidates of the given kind
70  std::vector<CandidateInfo> get(InstrProfValueKind Kind) const;
71 
72 private:
74  std::unique_ptr<ValueProfileCollectorImpl> PImpl;
75 };
76 
77 } // namespace llvm
78 
79 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:23
InstrProfValueKind
Definition: InstrProf.h:232
ValueProfileCollectorImpl inherits the API of PluginChainFinal.
Utility analysis that determines what values are worth profiling.
ValueProfileCollector & operator=(ValueProfileCollector &&)=delete
LLVM Value Representation.
Definition: Value.h:74
This header defines various interfaces for pass management in LLVM.