llvm.org GIT mirror llvm / cc76a0c
Add missing new file for r266637 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266639 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 4 years ago
1 changed file(s) with 204 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- Transforms/InstrProfiling.h - Instrumentation passes ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file provides the interface for LLVM's PGO Instrumentation lowering
10 /// pass.
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TRANSFORMS_INSTRPROFILING_H
14 #define LLVM_TRANSFORMS_INSTRPROFILING_H
15
16 #include "llvm/IR/IntrinsicInst.h"
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/ProfileData/InstrProf.h"
19 #include "llvm/Transforms/Instrumentation.h"
20
21 namespace llvm {
22
23 /// Instrumenation based profiling lowering pass. This pass lowers
24 /// the profile instrumented code generated by FE or the IR based
25 /// instrumentation pass.
26 class InstrProfiling : public PassInfoMixin {
27 public:
28 InstrProfiling() {}
29 InstrProfiling(const InstrProfOptions &Options) : Options(Options) {}
30
31 PreservedAnalyses run(Module &M, AnalysisManager &AM);
32 bool run(Module &M);
33
34 private:
35 InstrProfOptions Options;
36 Module *M;
37 struct PerFunctionProfileData {
38 uint32_t NumValueSites[IPVK_Last + 1];
39 GlobalVariable *RegionCounters;
40 GlobalVariable *DataVar;
41 PerFunctionProfileData() : RegionCounters(nullptr), DataVar(nullptr) {
42 memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
43 }
44 };
45 DenseMap ProfileDataMap;
46 std::vector UsedVars;
47 std::vector ReferencedNames;
48 GlobalVariable *NamesVar;
49 size_t NamesSize;
50
51 bool isMachO() const;
52
53 /// Get the section name for the counter variables.
54 StringRef getCountersSection() const;
55
56 /// Get the section name for the name variables.
57 StringRef getNameSection() const;
58
59 /// Get the section name for the profile data variables.
60 StringRef getDataSection() const;
61
62 /// Get the section name for the coverage mapping data.
63 StringRef getCoverageSection() const;
64
65 /// Count the number of instrumented value sites for the function.
66 void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
67
68 /// Replace instrprof_value_profile with a call to runtime library.
69 void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
70
71 /// Replace instrprof_increment with an increment of the appropriate value.
72 void lowerIncrement(InstrProfIncrementInst *Inc);
73
74 /// Force emitting of name vars for unused functions.
75 void lowerCoverageData(GlobalVariable *CoverageNamesVar);
76
77 /// Get the region counters for an increment, creating them if necessary.
78 ///
79 /// If the counter array doesn't yet exist, the profile data variables
80 /// referring to them will also be created.
81 GlobalVariable *getOrCreateRegionCounters(InstrProfIncrementInst *Inc);
82
83 /// Emit the section with compressed function names.
84 void emitNameData();
85
86 /// Emit runtime registration functions for each profile data variable.
87 void emitRegistration();
88
89 /// Emit the necessary plumbing to pull in the runtime initialization.
90 void emitRuntimeHook();
91
92 /// Add uses of our data variables and runtime hook.
93 void emitUses();
94
95 /// Create a static initializer for our data, on platforms that need it,
96 /// and for any profile output file that was specified.
97 void emitInitialization();
98 };
99
100 } // End llvm namespace
101 #endif
102 //===- Transforms/InstrProfiling.h - Instrumentation passes ---*- C++ -*-===//
103 //
104 // The LLVM Compiler Infrastructure
105 //
106 // This file is distributed under the University of Illinois Open Source
107 // License. See LICENSE.TXT for details.
108 //
109 //===----------------------------------------------------------------------===//
110 /// \file
111 /// This file provides the interface for LLVM's PGO Instrumentation lowering
112 /// pass.
113 //===----------------------------------------------------------------------===//
114
115 #ifndef LLVM_TRANSFORMS_INSTRPROFILING_H
116 #define LLVM_TRANSFORMS_INSTRPROFILING_H
117
118 #include "llvm/IR/IntrinsicInst.h"
119 #include "llvm/IR/PassManager.h"
120 #include "llvm/ProfileData/InstrProf.h"
121 #include "llvm/Transforms/Instrumentation.h"
122
123 namespace llvm {
124
125 /// Instrumenation based profiling lowering pass. This pass lowers
126 /// the profile instrumented code generated by FE or the IR based
127 /// instrumentation pass.
128 struct InstrProfiling : PassInfoMixin {
129 public:
130 InstrProfiling() {}
131 InstrProfiling(const InstrProfOptions &Options) : Options(Options) {}
132
133 PreservedAnalyses run(Module &M, AnalysisManager &AM);
134 bool run(Module &M);
135
136 private:
137 InstrProfOptions Options;
138 Module *M;
139 typedef struct PerFunctionProfileData {
140 uint32_t NumValueSites[IPVK_Last + 1];
141 GlobalVariable *RegionCounters;
142 GlobalVariable *DataVar;
143 PerFunctionProfileData() : RegionCounters(nullptr), DataVar(nullptr) {
144 memset(NumValueSites, 0, sizeof(uint32_t) * (IPVK_Last + 1));
145 }
146 } PerFunctionProfileData;
147 DenseMap ProfileDataMap;
148 std::vector UsedVars;
149 std::vector ReferencedNames;
150 GlobalVariable *NamesVar;
151 size_t NamesSize;
152
153 bool isMachO() const;
154
155 /// Get the section name for the counter variables.
156 StringRef getCountersSection() const;
157
158 /// Get the section name for the name variables.
159 StringRef getNameSection() const;
160
161 /// Get the section name for the profile data variables.
162 StringRef getDataSection() const;
163
164 /// Get the section name for the coverage mapping data.
165 StringRef getCoverageSection() const;
166
167 /// Count the number of instrumented value sites for the function.
168 void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
169
170 /// Replace instrprof_value_profile with a call to runtime library.
171 void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
172
173 /// Replace instrprof_increment with an increment of the appropriate value.
174 void lowerIncrement(InstrProfIncrementInst *Inc);
175
176 /// Force emitting of name vars for unused functions.
177 void lowerCoverageData(GlobalVariable *CoverageNamesVar);
178
179 /// Get the region counters for an increment, creating them if necessary.
180 ///
181 /// If the counter array doesn't yet exist, the profile data variables
182 /// referring to them will also be created.
183 GlobalVariable *getOrCreateRegionCounters(InstrProfIncrementInst *Inc);
184
185 /// Emit the section with compressed function names.
186 void emitNameData();
187
188 /// Emit runtime registration functions for each profile data variable.
189 void emitRegistration();
190
191 /// Emit the necessary plumbing to pull in the runtime initialization.
192 void emitRuntimeHook();
193
194 /// Add uses of our data variables and runtime hook.
195 void emitUses();
196
197 /// Create a static initializer for our data, on platforms that need it,
198 /// and for any profile output file that was specified.
199 void emitInitialization();
200 };
201
202 } // End llvm namespace
203 #endif