Skip to content

Commit 6ed1daa

Browse files
authored
[NFC][InstrProf] Move InstrProfiling to the .cpp file (#75018)
1 parent 072cea6 commit 6ed1daa

File tree

2 files changed

+149
-157
lines changed

2 files changed

+149
-157
lines changed

llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@
1313
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H
1414
#define LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H
1515

16-
#include "llvm/ADT/DenseMap.h"
17-
#include "llvm/ADT/StringRef.h"
18-
#include "llvm/IR/IntrinsicInst.h"
1916
#include "llvm/IR/PassManager.h"
20-
#include "llvm/ProfileData/InstrProf.h"
2117
#include "llvm/Transforms/Instrumentation.h"
22-
#include <cstdint>
23-
#include <cstring>
24-
#include <vector>
2518

2619
namespace llvm {
2720

2821
class TargetLibraryInfo;
29-
using LoadStorePair = std::pair<Instruction *, Instruction *>;
30-
3122
/// Instrumentation based profiling lowering pass. This pass lowers
3223
/// the profile instrumented code generated by FE or the IR based
3324
/// instrumentation pass.
@@ -44,154 +35,6 @@ class InstrProfilingLoweringPass
4435

4536
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
4637
};
47-
48-
class InstrProfiling final {
49-
public:
50-
InstrProfiling(Module &M, const InstrProfOptions &Options,
51-
std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
52-
bool IsCS)
53-
: M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
54-
GetTLI(GetTLI) {}
55-
56-
bool lower();
57-
58-
private:
59-
Module &M;
60-
const InstrProfOptions Options;
61-
const Triple TT;
62-
// Is this lowering for the context-sensitive instrumentation.
63-
const bool IsCS;
64-
65-
std::function<const TargetLibraryInfo &(Function &F)> GetTLI;
66-
struct PerFunctionProfileData {
67-
uint32_t NumValueSites[IPVK_Last + 1] = {};
68-
GlobalVariable *RegionCounters = nullptr;
69-
GlobalVariable *DataVar = nullptr;
70-
GlobalVariable *RegionBitmaps = nullptr;
71-
uint32_t NumBitmapBytes = 0;
72-
73-
PerFunctionProfileData() = default;
74-
};
75-
DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
76-
/// If runtime relocation is enabled, this maps functions to the load
77-
/// instruction that produces the profile relocation bias.
78-
DenseMap<const Function *, LoadInst *> FunctionToProfileBiasMap;
79-
std::vector<GlobalValue *> CompilerUsedVars;
80-
std::vector<GlobalValue *> UsedVars;
81-
std::vector<GlobalVariable *> ReferencedNames;
82-
GlobalVariable *NamesVar = nullptr;
83-
size_t NamesSize = 0;
84-
85-
// vector of counter load/store pairs to be register promoted.
86-
std::vector<LoadStorePair> PromotionCandidates;
87-
88-
int64_t TotalCountersPromoted = 0;
89-
90-
/// Lower instrumentation intrinsics in the function. Returns true if there
91-
/// any lowering.
92-
bool lowerIntrinsics(Function *F);
93-
94-
/// Register-promote counter loads and stores in loops.
95-
void promoteCounterLoadStores(Function *F);
96-
97-
/// Returns true if relocating counters at runtime is enabled.
98-
bool isRuntimeCounterRelocationEnabled() const;
99-
100-
/// Returns true if profile counter update register promotion is enabled.
101-
bool isCounterPromotionEnabled() const;
102-
103-
/// Count the number of instrumented value sites for the function.
104-
void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
105-
106-
/// Replace instrprof.value.profile with a call to runtime library.
107-
void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
108-
109-
/// Replace instrprof.cover with a store instruction to the coverage byte.
110-
void lowerCover(InstrProfCoverInst *Inc);
111-
112-
/// Replace instrprof.timestamp with a call to
113-
/// INSTR_PROF_PROFILE_SET_TIMESTAMP.
114-
void lowerTimestamp(InstrProfTimestampInst *TimestampInstruction);
115-
116-
/// Replace instrprof.increment with an increment of the appropriate value.
117-
void lowerIncrement(InstrProfIncrementInst *Inc);
118-
119-
/// Force emitting of name vars for unused functions.
120-
void lowerCoverageData(GlobalVariable *CoverageNamesVar);
121-
122-
/// Replace instrprof.mcdc.tvbitmask.update with a shift and or instruction
123-
/// using the index represented by the a temp value into a bitmap.
124-
void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
125-
126-
/// Replace instrprof.mcdc.temp.update with a shift and or instruction using
127-
/// the corresponding condition ID.
128-
void lowerMCDCCondBitmapUpdate(InstrProfMCDCCondBitmapUpdate *Ins);
129-
130-
/// Compute the address of the counter value that this profiling instruction
131-
/// acts on.
132-
Value *getCounterAddress(InstrProfCntrInstBase *I);
133-
134-
/// Get the region counters for an increment, creating them if necessary.
135-
///
136-
/// If the counter array doesn't yet exist, the profile data variables
137-
/// referring to them will also be created.
138-
GlobalVariable *getOrCreateRegionCounters(InstrProfCntrInstBase *Inc);
139-
140-
/// Create the region counters.
141-
GlobalVariable *createRegionCounters(InstrProfCntrInstBase *Inc,
142-
StringRef Name,
143-
GlobalValue::LinkageTypes Linkage);
144-
145-
/// Compute the address of the test vector bitmap that this profiling
146-
/// instruction acts on.
147-
Value *getBitmapAddress(InstrProfMCDCTVBitmapUpdate *I);
148-
149-
/// Get the region bitmaps for an increment, creating them if necessary.
150-
///
151-
/// If the bitmap array doesn't yet exist, the profile data variables
152-
/// referring to them will also be created.
153-
GlobalVariable *getOrCreateRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc);
154-
155-
/// Create the MC/DC bitmap as a byte-aligned array of bytes associated with
156-
/// an MC/DC Decision region. The number of bytes required is indicated by
157-
/// the intrinsic used (type InstrProfMCDCBitmapInstBase). This is called
158-
/// as part of setupProfileSection() and is conceptually very similar to
159-
/// what is done for profile data counters in createRegionCounters().
160-
GlobalVariable *createRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc,
161-
StringRef Name,
162-
GlobalValue::LinkageTypes Linkage);
163-
164-
/// Set Comdat property of GV, if required.
165-
void maybeSetComdat(GlobalVariable *GV, Function *Fn, StringRef VarName);
166-
167-
/// Setup the sections into which counters and bitmaps are allocated.
168-
GlobalVariable *setupProfileSection(InstrProfInstBase *Inc,
169-
InstrProfSectKind IPSK);
170-
171-
/// Create INSTR_PROF_DATA variable for counters and bitmaps.
172-
void createDataVariable(InstrProfCntrInstBase *Inc);
173-
174-
/// Emit the section with compressed function names.
175-
void emitNameData();
176-
177-
/// Emit value nodes section for value profiling.
178-
void emitVNodes();
179-
180-
/// Emit runtime registration functions for each profile data variable.
181-
void emitRegistration();
182-
183-
/// Emit the necessary plumbing to pull in the runtime initialization.
184-
/// Returns true if a change was made.
185-
bool emitRuntimeHook();
186-
187-
/// Add uses of our data variables and runtime hook.
188-
void emitUses();
189-
190-
/// Create a static initializer for our data, on platforms that need it,
191-
/// and for any profile output file that was specified.
192-
void emitInitialization();
193-
};
194-
19538
} // end namespace llvm
19639

19740
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,155 @@ cl::opt<bool> SkipRetExitBlock(
152152
"skip-ret-exit-block", cl::init(true),
153153
cl::desc("Suppress counter promotion if exit blocks contain ret."));
154154

155+
using LoadStorePair = std::pair<Instruction *, Instruction *>;
156+
157+
class InstrProfiling final {
158+
public:
159+
InstrProfiling(Module &M, const InstrProfOptions &Options,
160+
std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
161+
bool IsCS)
162+
: M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
163+
GetTLI(GetTLI) {}
164+
165+
bool lower();
166+
167+
private:
168+
Module &M;
169+
const InstrProfOptions Options;
170+
const Triple TT;
171+
// Is this lowering for the context-sensitive instrumentation.
172+
const bool IsCS;
173+
174+
std::function<const TargetLibraryInfo &(Function &F)> GetTLI;
175+
struct PerFunctionProfileData {
176+
uint32_t NumValueSites[IPVK_Last + 1] = {};
177+
GlobalVariable *RegionCounters = nullptr;
178+
GlobalVariable *DataVar = nullptr;
179+
GlobalVariable *RegionBitmaps = nullptr;
180+
uint32_t NumBitmapBytes = 0;
181+
182+
PerFunctionProfileData() = default;
183+
};
184+
DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
185+
/// If runtime relocation is enabled, this maps functions to the load
186+
/// instruction that produces the profile relocation bias.
187+
DenseMap<const Function *, LoadInst *> FunctionToProfileBiasMap;
188+
std::vector<GlobalValue *> CompilerUsedVars;
189+
std::vector<GlobalValue *> UsedVars;
190+
std::vector<GlobalVariable *> ReferencedNames;
191+
GlobalVariable *NamesVar = nullptr;
192+
size_t NamesSize = 0;
193+
194+
// vector of counter load/store pairs to be register promoted.
195+
std::vector<LoadStorePair> PromotionCandidates;
196+
197+
int64_t TotalCountersPromoted = 0;
198+
199+
/// Lower instrumentation intrinsics in the function. Returns true if there
200+
/// any lowering.
201+
bool lowerIntrinsics(Function *F);
202+
203+
/// Register-promote counter loads and stores in loops.
204+
void promoteCounterLoadStores(Function *F);
205+
206+
/// Returns true if relocating counters at runtime is enabled.
207+
bool isRuntimeCounterRelocationEnabled() const;
208+
209+
/// Returns true if profile counter update register promotion is enabled.
210+
bool isCounterPromotionEnabled() const;
211+
212+
/// Count the number of instrumented value sites for the function.
213+
void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
214+
215+
/// Replace instrprof.value.profile with a call to runtime library.
216+
void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
217+
218+
/// Replace instrprof.cover with a store instruction to the coverage byte.
219+
void lowerCover(InstrProfCoverInst *Inc);
220+
221+
/// Replace instrprof.timestamp with a call to
222+
/// INSTR_PROF_PROFILE_SET_TIMESTAMP.
223+
void lowerTimestamp(InstrProfTimestampInst *TimestampInstruction);
224+
225+
/// Replace instrprof.increment with an increment of the appropriate value.
226+
void lowerIncrement(InstrProfIncrementInst *Inc);
227+
228+
/// Force emitting of name vars for unused functions.
229+
void lowerCoverageData(GlobalVariable *CoverageNamesVar);
230+
231+
/// Replace instrprof.mcdc.tvbitmask.update with a shift and or instruction
232+
/// using the index represented by the a temp value into a bitmap.
233+
void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
234+
235+
/// Replace instrprof.mcdc.temp.update with a shift and or instruction using
236+
/// the corresponding condition ID.
237+
void lowerMCDCCondBitmapUpdate(InstrProfMCDCCondBitmapUpdate *Ins);
238+
239+
/// Compute the address of the counter value that this profiling instruction
240+
/// acts on.
241+
Value *getCounterAddress(InstrProfCntrInstBase *I);
242+
243+
/// Get the region counters for an increment, creating them if necessary.
244+
///
245+
/// If the counter array doesn't yet exist, the profile data variables
246+
/// referring to them will also be created.
247+
GlobalVariable *getOrCreateRegionCounters(InstrProfCntrInstBase *Inc);
248+
249+
/// Create the region counters.
250+
GlobalVariable *createRegionCounters(InstrProfCntrInstBase *Inc,
251+
StringRef Name,
252+
GlobalValue::LinkageTypes Linkage);
253+
254+
/// Compute the address of the test vector bitmap that this profiling
255+
/// instruction acts on.
256+
Value *getBitmapAddress(InstrProfMCDCTVBitmapUpdate *I);
257+
258+
/// Get the region bitmaps for an increment, creating them if necessary.
259+
///
260+
/// If the bitmap array doesn't yet exist, the profile data variables
261+
/// referring to them will also be created.
262+
GlobalVariable *getOrCreateRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc);
263+
264+
/// Create the MC/DC bitmap as a byte-aligned array of bytes associated with
265+
/// an MC/DC Decision region. The number of bytes required is indicated by
266+
/// the intrinsic used (type InstrProfMCDCBitmapInstBase). This is called
267+
/// as part of setupProfileSection() and is conceptually very similar to
268+
/// what is done for profile data counters in createRegionCounters().
269+
GlobalVariable *createRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc,
270+
StringRef Name,
271+
GlobalValue::LinkageTypes Linkage);
272+
273+
/// Set Comdat property of GV, if required.
274+
void maybeSetComdat(GlobalVariable *GV, Function *Fn, StringRef VarName);
275+
276+
/// Setup the sections into which counters and bitmaps are allocated.
277+
GlobalVariable *setupProfileSection(InstrProfInstBase *Inc,
278+
InstrProfSectKind IPSK);
279+
280+
/// Create INSTR_PROF_DATA variable for counters and bitmaps.
281+
void createDataVariable(InstrProfCntrInstBase *Inc);
282+
283+
/// Emit the section with compressed function names.
284+
void emitNameData();
285+
286+
/// Emit value nodes section for value profiling.
287+
void emitVNodes();
288+
289+
/// Emit runtime registration functions for each profile data variable.
290+
void emitRegistration();
291+
292+
/// Emit the necessary plumbing to pull in the runtime initialization.
293+
/// Returns true if a change was made.
294+
bool emitRuntimeHook();
295+
296+
/// Add uses of our data variables and runtime hook.
297+
void emitUses();
298+
299+
/// Create a static initializer for our data, on platforms that need it,
300+
/// and for any profile output file that was specified.
301+
void emitInitialization();
302+
};
303+
155304
///
156305
/// A helper class to promote one counter RMW operation in the loop
157306
/// into register update.

0 commit comments

Comments
 (0)