]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Transforms/InstrProfiling.h
Merge ^/head r317281 through r317502.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Transforms / InstrProfiling.h
1 //===- Transforms/InstrProfiling.h - Instrumentation passes -----*- 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 /// \file
10 /// This file provides the interface for LLVM's PGO Instrumentation lowering
11 /// pass.
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TRANSFORMS_INSTRPROFILING_H
15 #define LLVM_TRANSFORMS_INSTRPROFILING_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/IR/IntrinsicInst.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/ProfileData/InstrProf.h"
22 #include "llvm/Transforms/Instrumentation.h"
23 #include <cstddef>
24 #include <cstdint>
25 #include <cstring>
26 #include <vector>
27
28 namespace llvm {
29
30 class TargetLibraryInfo;
31
32 /// Instrumentation based profiling lowering pass. This pass lowers
33 /// the profile instrumented code generated by FE or the IR based
34 /// instrumentation pass.
35 class InstrProfiling : public PassInfoMixin<InstrProfiling> {
36 public:
37   InstrProfiling() = default;
38   InstrProfiling(const InstrProfOptions &Options) : Options(Options) {}
39
40   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
41   bool run(Module &M, const TargetLibraryInfo &TLI);
42
43 private:
44   InstrProfOptions Options;
45   Module *M;
46   Triple TT;
47   const TargetLibraryInfo *TLI;
48   struct PerFunctionProfileData {
49     uint32_t NumValueSites[IPVK_Last + 1];
50     GlobalVariable *RegionCounters = nullptr;
51     GlobalVariable *DataVar = nullptr;
52
53     PerFunctionProfileData() {
54       memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
55     }
56   };
57   DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
58   std::vector<GlobalValue *> UsedVars;
59   std::vector<GlobalVariable *> ReferencedNames;
60   GlobalVariable *NamesVar;
61   size_t NamesSize;
62
63   // The start value of precise value profile range for memory intrinsic sizes.
64   int64_t MemOPSizeRangeStart;
65   // The end value of precise value profile range for memory intrinsic sizes.
66   int64_t MemOPSizeRangeLast;
67
68   /// Count the number of instrumented value sites for the function.
69   void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
70
71   /// Replace instrprof_value_profile with a call to runtime library.
72   void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
73
74   /// Replace instrprof_increment with an increment of the appropriate value.
75   void lowerIncrement(InstrProfIncrementInst *Inc);
76
77   /// Force emitting of name vars for unused functions.
78   void lowerCoverageData(GlobalVariable *CoverageNamesVar);
79
80   /// Get the region counters for an increment, creating them if necessary.
81   ///
82   /// If the counter array doesn't yet exist, the profile data variables
83   /// referring to them will also be created.
84   GlobalVariable *getOrCreateRegionCounters(InstrProfIncrementInst *Inc);
85
86   /// Emit the section with compressed function names.
87   void emitNameData();
88
89   /// Emit value nodes section for value profiling.
90   void emitVNodes();
91
92   /// Emit runtime registration functions for each profile data variable.
93   void emitRegistration();
94
95   /// Emit the necessary plumbing to pull in the runtime initialization.
96   void emitRuntimeHook();
97
98   /// Add uses of our data variables and runtime hook.
99   void emitUses();
100
101   /// Create a static initializer for our data, on platforms that need it,
102   /// and for any profile output file that was specified.
103   void emitInitialization();
104 };
105
106 } // end namespace llvm
107
108 #endif // LLVM_TRANSFORMS_INSTRPROFILING_H