13
13
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H
14
14
#define LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H
15
15
16
- #include " llvm/ADT/DenseMap.h"
17
- #include " llvm/ADT/StringRef.h"
18
- #include " llvm/IR/IntrinsicInst.h"
19
16
#include " llvm/IR/PassManager.h"
20
- #include " llvm/ProfileData/InstrProf.h"
21
17
#include " llvm/Transforms/Instrumentation.h"
22
- #include < cstdint>
23
- #include < cstring>
24
- #include < vector>
25
18
26
19
namespace llvm {
27
20
28
21
class TargetLibraryInfo ;
29
- using LoadStorePair = std::pair<Instruction *, Instruction *>;
30
-
31
22
// / Instrumentation based profiling lowering pass. This pass lowers
32
23
// / the profile instrumented code generated by FE or the IR based
33
24
// / instrumentation pass.
@@ -44,154 +35,6 @@ class InstrProfilingLoweringPass
44
35
45
36
PreservedAnalyses run (Module &M, ModuleAnalysisManager &AM);
46
37
};
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
-
195
38
} // end namespace llvm
196
39
197
40
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_INSTRPROFILING_H
0 commit comments