71#define DEBUG_TYPE "instrprof"
79 cl::desc(
"Use debug info or binary file to correlate profiles."),
82 "No profile correlation"),
84 "Use debug info to correlate"),
86 "Use binary to correlate")));
92 "hash-based-counter-split",
93 cl::desc(
"Rename counter variable of a comdat function based on cfg hash"),
97 RuntimeCounterRelocation(
"runtime-counter-relocation",
98 cl::desc(
"Enable relocating counters at runtime."),
103 cl::desc(
"Do static counter allocation for value profiler"),
107 "vp-counters-per-site",
108 cl::desc(
"The average number of profile counters allocated "
109 "per value profiling site."),
117 "instrprof-atomic-counter-update-all",
118 cl::desc(
"Make all profile counter updates atomic (for testing only)"),
122 "verify-atomic-counter-promoted",
123 cl::desc(
"Check that all profile counter updates were made atomic; no-op "
124 "if atomic updates are not requested (-fprofile-update=atomic)"),
128 "atomic-counter-update-promoted",
129 cl::desc(
"Do counter update using atomic fetch add "
130 " for promoted counters only"),
134 "atomic-first-counter",
135 cl::desc(
"Use atomic fetch add for first counter in a function (usually "
136 "the entry counter)"),
140 "conditional-counter-update",
141 cl::desc(
"Do conditional counter updates in single byte counters mode)"),
150 cl::desc(
"Do counter register promotion"),
153 "max-counter-promotions-per-loop",
cl::init(20),
154 cl::desc(
"Max number counter promotions per loop to avoid"
155 " increasing register pressure too much"));
159 MaxNumOfPromotions(
"max-counter-promotions",
cl::init(-1),
160 cl::desc(
"Max number of allowed counter promotions"));
163 "speculative-counter-promotion-max-exiting",
cl::init(3),
164 cl::desc(
"The max number of exiting blocks of a loop to allow "
165 " speculative counter promotion"));
168 "speculative-counter-promotion-to-loop",
169 cl::desc(
"When the option is false, if the target block is in a loop, "
170 "the promotion will be disallowed unless the promoted counter "
171 " update can be further/iteratively promoted into an acyclic "
175 "offload-pgo-sampling",
176 cl::desc(
"Log2 of the sampling period for offload PGO instrumentation. "
177 "Only 1 in every 2^N blocks is instrumented. "
178 "0 = all blocks, 1 = 50%, 2 = 25%, 3 = 12.5% (default). "
179 "Higher values reduce overhead at the cost of sparser profiles."),
183 "iterative-counter-promotion",
cl::init(
true),
184 cl::desc(
"Allow counter promotion across the whole loop nest."));
187 "skip-ret-exit-block",
cl::init(
true),
188 cl::desc(
"Suppress counter promotion if exit blocks contain ret."));
191 cl::desc(
"Do PGO instrumentation sampling"));
194 "sampled-instr-period",
195 cl::desc(
"Set the profile instrumentation sample period. A sample period "
196 "of 0 is invalid. For each sample period, a fixed number of "
197 "consecutive samples will be recorded. The number is controlled "
198 "by 'sampled-instr-burst-duration' flag. The default sample "
199 "period of 65536 is optimized for generating efficient code that "
200 "leverages unsigned short integer wrapping in overflow, but this "
201 "is disabled under simple sampling (burst duration = 1)."),
205 "sampled-instr-burst-duration",
206 cl::desc(
"Set the profile instrumentation burst duration, which can range "
207 "from 1 to the value of 'sampled-instr-period' (0 is invalid). "
208 "This number of samples will be recorded for each "
209 "'sampled-instr-period' count update. Setting to 1 enables simple "
210 "sampling, in which case it is recommended to set "
211 "'sampled-instr-period' to a prime number."),
214struct SampledInstrumentationConfig {
215 unsigned BurstDuration;
218 bool IsSimpleSampling;
222static SampledInstrumentationConfig getSampledInstrumentationConfig() {
223 SampledInstrumentationConfig config;
224 config.BurstDuration = SampledInstrBurstDuration.getValue();
225 config.Period = SampledInstrPeriod.getValue();
226 if (config.BurstDuration > config.Period)
228 "SampledBurstDuration must be less than or equal to SampledPeriod");
229 if (config.Period == 0 || config.BurstDuration == 0)
231 "SampledPeriod and SampledBurstDuration must be greater than 0");
232 config.IsSimpleSampling = (config.BurstDuration == 1);
235 config.IsFastSampling =
236 (!config.IsSimpleSampling && config.Period == USHRT_MAX + 1);
237 config.UseShort = (config.Period <= USHRT_MAX) || config.IsFastSampling;
241using LoadStorePair = std::pair<Instruction *, Instruction *>;
245 assert(Addition && Addition->getOpcode() == Instruction::BinaryOps::Add);
246 auto *Addend = Addition->getOperand(1);
251 Store->eraseFromParent();
252 Addition->eraseFromParent();
253 Load->eraseFromParent();
266static bool enablesValueProfiling(
const Module &M) {
268 getIntModuleFlagOrZero(M,
"EnableValueProfiling") != 0;
272static bool profDataReferencedByCode(
const Module &M) {
273 return enablesValueProfiling(M);
276class InstrLowerer final {
278 InstrLowerer(
Module &M,
const InstrProfOptions &Options,
279 std::function<
const TargetLibraryInfo &(Function &
F)> GetTLI,
281 : M(M), Options(Options), TT(M.getTargetTriple()), IsCS(IsCS),
282 GetTLI(GetTLI), DataReferencedByCode(profDataReferencedByCode(M)) {}
288 const InstrProfOptions Options;
293 std::function<
const TargetLibraryInfo &(
Function &
F)> GetTLI;
295 const bool DataReferencedByCode;
297 struct PerFunctionProfileData {
298 uint32_t NumValueSites[IPVK_Last + 1] = {};
299 GlobalVariable *RegionCounters =
nullptr;
300 GlobalVariable *UniformCounters =
302 GlobalVariable *DataVar =
nullptr;
303 GlobalVariable *RegionBitmaps =
nullptr;
304 uint32_t NumBitmapBytes = 0;
306 PerFunctionProfileData() =
default;
308 DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
311 DenseMap<GlobalVariable *, GlobalVariable *> VTableDataMap;
314 DenseMap<const Function *, LoadInst *> FunctionToProfileBiasMap;
315 std::vector<GlobalValue *> CompilerUsedVars;
316 std::vector<GlobalValue *> UsedVars;
317 std::vector<GlobalVariable *> ReferencedNames;
320 std::vector<GlobalVariable *> ReferencedVTables;
321 GlobalVariable *NamesVar =
nullptr;
322 size_t NamesSize = 0;
324 StructType *ProfileDataTy =
nullptr;
327 std::vector<LoadStorePair> PromotionCandidates;
329 int64_t TotalCountersPromoted = 0;
334 struct GPUPGOInvariants {
335 Value *Matched =
nullptr;
336 bool WaveSizeStored =
false;
338 DenseMap<Function *, GPUPGOInvariants> GPUInvariantsCache;
341 GPUPGOInvariants &getOrCreateGPUInvariants(Function *
F);
345 bool lowerIntrinsics(Function *
F);
348 void promoteCounterLoadStores(Function *
F);
351 bool isRuntimeCounterRelocationEnabled()
const;
354 bool isCounterPromotionEnabled()
const;
360 bool isSamplingEnabled()
const;
363 void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
366 void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
369 void lowerCover(InstrProfCoverInst *Inc);
373 void lowerTimestamp(InstrProfTimestampInst *TimestampInstruction);
376 void lowerIncrement(InstrProfIncrementInst *Inc);
379 void lowerCoverageData(GlobalVariable *CoverageNamesVar);
383 void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
387 GlobalVariable *getOrCreateBiasVar(StringRef VarName);
391 Value *getCounterAddress(InstrProfCntrInstBase *
I);
394 void doSampling(Instruction *
I);
400 GlobalVariable *getOrCreateRegionCounters(InstrProfCntrInstBase *Inc);
404 GlobalVariable *getOrCreateUniformCounters(InstrProfCntrInstBase *Inc);
407 GlobalVariable *createRegionCounters(InstrProfCntrInstBase *Inc,
413 Value *getBitmapAddress(InstrProfMCDCTVBitmapUpdate *
I);
419 GlobalVariable *getOrCreateRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc);
426 GlobalVariable *createRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc,
431 void maybeSetComdat(GlobalVariable *GV, GlobalObject *GO, StringRef VarName);
434 GlobalVariable *setupProfileSection(InstrProfInstBase *Inc,
438 void createDataVariable(InstrProfCntrInstBase *Inc);
441 void getOrCreateVTableProfData(GlobalVariable *GV);
447 void emitVTableNames();
453 void emitRegistration();
457 bool emitRuntimeHook();
464 void emitInitialization();
467 StructType *getProfileDataTy();
479 PGOCounterPromoterHelper(
480 Instruction *L, Instruction *S, SSAUpdater &
SSA,
Value *Init,
484 LoopInfo &LI,
bool IsAtomic)
485 : LoadAndStorePromoter({
L, S},
SSA),
Store(S), ExitBlocks(ExitBlocks),
486 InsertPts(InsertPts), LoopToCandidates(LoopToCands), LI(LI),
490 SSA.AddAvailableValue(PH, Init);
493 void doExtraRewritesBeforeFinalDeletion()
override {
494 for (
unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
500 Value *LiveInValue =
SSA.GetValueInMiddleOfBlock(ExitBlock);
512 assert(OrigBiasInst->getOpcode() == Instruction::BinaryOps::Add);
513 Value *BiasInst = Builder.Insert(OrigBiasInst->clone());
514 Addr = Builder.CreateIntToPtr(BiasInst,
518 IterativeCounterPromotion ? LI.getLoopFor(ExitBlock) :
nullptr;
521 if ((IsAtomic && !TargetLoop) || AtomicCounterUpdatePromoted)
523 MaybeAlign(), AtomicOrdering::Monotonic);
525 LoadInst *OldVal = Builder.CreateLoad(Ty, Addr,
"pgocount.promoted");
526 auto *NewVal = Builder.CreateAdd(OldVal, LiveInValue);
527 auto *NewStore = Builder.CreateStore(NewVal, Addr);
531 LoopToCandidates[TargetLoop].emplace_back(OldVal, NewStore);
540 DenseMap<Loop *, SmallVector<LoadStorePair, 8>> &LoopToCandidates;
548class PGOCounterPromoter {
552 Loop &CurLoop, LoopInfo &LI, BlockFrequencyInfo *BFI,
bool IsAtomic)
553 : LoopToCandidates(LoopToCands), L(CurLoop), LI(LI), BFI(BFI),
558 SmallVector<BasicBlock *, 8> LoopExitBlocks;
559 SmallPtrSet<BasicBlock *, 8>
BlockSet;
561 L.getExitBlocks(LoopExitBlocks);
562 if (!isPromotionPossible(&L, LoopExitBlocks))
565 for (BasicBlock *ExitBlock : LoopExitBlocks) {
570 ExitBlocks.push_back(ExitBlock);
576 bool run(int64_t *NumPromoted) {
577 bool RC = promoteCandidates(NumPromoted);
588 for (
auto &Cand : LoopToCandidates[&L])
589 if (Cand.first !=
nullptr && Cand.second !=
nullptr)
590 makeAtomic(Cand.first, Cand.second);
595 bool promoteCandidates(int64_t *NumPromoted) {
597 if (ExitBlocks.size() == 0)
605 if (SkipRetExitBlock) {
606 for (
auto *BB : ExitBlocks)
611 unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
615 [[maybe_unused]]
auto *Ptr = LoopToCandidates.getPointerIntoBucketsArray();
616 unsigned Promoted = 0;
617 for (
auto &Cand : LoopToCandidates[&L]) {
619 SSAUpdater
SSA(&NewPHIs);
620 Value *InitVal = ConstantInt::get(Cand.first->getType(), 0);
624 auto *BB = Cand.first->getParent();
625 auto InstrCount = BFI->getBlockProfileCount(BB);
628 auto PreheaderCount = BFI->getBlockProfileCount(L.getLoopPreheader());
631 if (PreheaderCount && (*PreheaderCount * 3) >= (*
InstrCount * 2))
635 PGOCounterPromoterHelper Promoter(
636 Cand.first, Cand.second,
SSA, InitVal, L.getLoopPreheader(),
637 ExitBlocks, InsertPts, LoopToCandidates, LI, IsAtomic);
638 Promoter.run(SmallVector<Instruction *, 2>({Cand.first, Cand.second}));
640 assert(LoopToCandidates.isPointerIntoBucketsArray(Ptr) &&
641 "References into LoopToCandidates might be invalid");
642 Cand = {
nullptr,
nullptr};
645 if (Promoted >= MaxProm)
649 if (MaxNumOfPromotions != -1 && *NumPromoted >= MaxNumOfPromotions)
653 LLVM_DEBUG(
dbgs() << Promoted <<
" counters promoted for loop (depth="
654 << L.getLoopDepth() <<
")\n");
655 return Promoted != 0;
659 bool allowSpeculativeCounterPromotion(Loop *LP) {
660 SmallVector<BasicBlock *, 8> ExitingBlocks;
661 L.getExitingBlocks(ExitingBlocks);
663 if (ExitingBlocks.
size() == 1)
665 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
673 isPromotionPossible(Loop *LP,
674 const SmallVectorImpl<BasicBlock *> &LoopExitBlocks) {
692 unsigned getMaxNumOfPromotionsInLoop(Loop *LP) {
693 SmallVector<BasicBlock *, 8> LoopExitBlocks;
695 if (!isPromotionPossible(LP, LoopExitBlocks))
698 SmallVector<BasicBlock *, 8> ExitingBlocks;
706 if (ExitingBlocks.
size() == 1)
707 return MaxNumOfPromotionsPerLoop;
709 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
713 if (SpeculativeCounterPromotionToLoop)
714 return MaxNumOfPromotionsPerLoop;
717 unsigned MaxProm = MaxNumOfPromotionsPerLoop;
718 for (
auto *TargetBlock : LoopExitBlocks) {
719 auto *TargetLoop = LI.getLoopFor(TargetBlock);
722 unsigned MaxPromForTarget = getMaxNumOfPromotionsInLoop(TargetLoop);
723 unsigned PendingCandsInTarget = LoopToCandidates[TargetLoop].size();
725 std::min(MaxProm, std::max(MaxPromForTarget, PendingCandsInTarget) -
726 PendingCandsInTarget);
731 DenseMap<Loop *, SmallVector<LoadStorePair, 8>> &LoopToCandidates;
732 SmallVector<BasicBlock *, 8> ExitBlocks;
733 SmallVector<Instruction *, 8> InsertPts;
736 BlockFrequencyInfo *BFI;
740enum class ValueProfilingCallType {
758 InstrLowerer Lowerer(M, Options, GetTLI, IsCS);
759 if (!Lowerer.lower())
810 if (!isSamplingEnabled())
813 SampledInstrumentationConfig config = getSampledInstrumentationConfig();
816 return Builder.getInt16(
C);
818 return Builder.getInt32(
C);
828 assert(SamplingVar &&
"SamplingVar not set properly");
832 Value *NewSamplingVarVal;
836 auto *LoadSamplingVar = CondBuilder.CreateLoad(SamplingVarTy, SamplingVar);
837 if (config.IsSimpleSampling) {
841 IncBuilder.CreateAdd(LoadSamplingVar, GetConstant(IncBuilder, 1));
842 SamplingVarIncr = IncBuilder.CreateStore(NewSamplingVarVal, SamplingVar);
845 auto *DurationCond = CondBuilder.CreateICmpULE(
846 LoadSamplingVar, GetConstant(CondBuilder, config.BurstDuration - 1));
847 BranchWeight = MDB.createBranchWeights(
848 config.BurstDuration, config.Period - config.BurstDuration);
850 DurationCond,
I,
false, BranchWeight);
853 IncBuilder.CreateAdd(LoadSamplingVar, GetConstant(IncBuilder, 1));
854 SamplingVarIncr = IncBuilder.CreateStore(NewSamplingVarVal, SamplingVar);
858 if (config.IsFastSampling)
864 auto *PeriodCond = PeriodCondBuilder.CreateICmpUGE(
865 NewSamplingVarVal, GetConstant(PeriodCondBuilder, config.Period));
866 BranchWeight = MDB.createBranchWeights(1, config.Period - 1);
868 &ElseTerm, BranchWeight);
871 if (config.IsSimpleSampling)
875 ResetBuilder.CreateStore(GetConstant(ResetBuilder, 0), SamplingVar);
879bool InstrLowerer::lowerIntrinsics(
Function *
F) {
880 bool MadeChange =
false;
881 PromotionCandidates.clear();
894 for (
auto *Instr : InstrProfInsts) {
897 lowerIncrement(IPIS);
909 lowerValueProfileInst(IPVP);
912 IPMP->eraseFromParent();
915 lowerMCDCTestVectorBitmapUpdate(IPBU);
923 promoteCounterLoadStores(
F);
927bool InstrLowerer::isRuntimeCounterRelocationEnabled()
const {
929 if (
TT.isOSBinFormatMachO())
932 if (RuntimeCounterRelocation.getNumOccurrences() > 0)
933 return RuntimeCounterRelocation;
936 return TT.isOSFuchsia();
939bool InstrLowerer::isSamplingEnabled()
const {
940 if (SampledInstr.getNumOccurrences() > 0)
945bool InstrLowerer::isCounterPromotionEnabled()
const {
946 if (DoCounterPromotion.getNumOccurrences() > 0)
947 return DoCounterPromotion;
948 return Options.DoCounterPromotion;
951bool InstrLowerer::isAtomic()
const {
952 return Options.Atomic || AtomicCounterUpdateAll;
957 const Value *Addr =
nullptr;
959 Addr = LI->getOperand(0);
961 Addr = LI->getOperand(1);
971void InstrLowerer::promoteCounterLoadStores(
Function *
F) {
972 if (!isCounterPromotionEnabled())
981 std::unique_ptr<BlockFrequencyInfo> BFI;
982 if (
Options.UseBFIInPromotion) {
983 std::unique_ptr<BranchProbabilityInfo> BPI;
988 for (
const auto &LoadStore : PromotionCandidates) {
995 makeAtomic(CounterLoad, CounterStore);
998 LoopPromotionCandidates[ParentLoop].emplace_back(CounterLoad, CounterStore);
1006 PGOCounterPromoter Promoter(LoopPromotionCandidates, *
Loop, LI, BFI.get(),
1008 Promoter.run(&TotalCountersPromoted);
1011 if (
isAtomic() && VerifyAtomicPromotion)
1017 if (TT.isOSFuchsia())
1025 auto containsIntrinsic = [&](
int ID) {
1027 return !
F->use_empty();
1030 return containsIntrinsic(Intrinsic::instrprof_cover) ||
1031 containsIntrinsic(Intrinsic::instrprof_increment) ||
1032 containsIntrinsic(Intrinsic::instrprof_increment_step) ||
1033 containsIntrinsic(Intrinsic::instrprof_timestamp) ||
1034 containsIntrinsic(Intrinsic::instrprof_value_profile);
1037bool InstrLowerer::lower() {
1038 bool MadeChange =
false;
1040 if (NeedsRuntimeHook)
1041 MadeChange = emitRuntimeHook();
1043 if (!IsCS && isSamplingEnabled())
1050 if (!ContainsProfiling && !CoverageNamesVar)
1061 computeNumValueSiteCounts(Ind);
1063 if (FirstProfInst ==
nullptr &&
1068 static_cast<void>(getOrCreateRegionBitmaps(Params));
1075 if (FirstProfInst !=
nullptr) {
1076 static_cast<void>(getOrCreateRegionCounters(FirstProfInst));
1083 if (GV.hasMetadata(LLVMContext::MD_type))
1084 getOrCreateVTableProfData(&GV);
1087 MadeChange |= lowerIntrinsics(&
F);
1089 if (CoverageNamesVar) {
1090 lowerCoverageData(CoverageNamesVar);
1105 if (!NeedsRuntimeHook && ContainsProfiling)
1110 emitInitialization();
1116 ValueProfilingCallType CallType = ValueProfilingCallType::Default) {
1121 if (
auto AK = TLI.getExtAttrForI32Param(
false))
1122 AL = AL.addParamAttribute(M.getContext(), 2, AK);
1124 assert((CallType == ValueProfilingCallType::Default ||
1125 CallType == ValueProfilingCallType::MemOp) &&
1126 "Must be Default or MemOp");
1127 Type *ParamTypes[] = {
1128#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
1131 auto *ValueProfilingCallTy =
1133 StringRef FuncName = CallType == ValueProfilingCallType::Default
1136 return M.getOrInsertFunction(FuncName, ValueProfilingCallTy, AL);
1143 auto &
PD = ProfileDataMap[
Name];
1145 std::max(
PD.NumValueSites[ValueKind], (uint32_t)(Index + 1));
1154 "Value profiling is not yet supported with lightweight instrumentation");
1156 auto It = ProfileDataMap.find(Name);
1157 assert(It != ProfileDataMap.end() && It->second.DataVar &&
1158 "value profiling detected in function with no counter increment");
1164 Index += It->second.NumValueSites[Kind];
1167 bool IsMemOpSize = (Ind->
getValueKind()->getZExtValue() ==
1168 llvm::InstrProfValueKind::IPVK_MemOPSize);
1192 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1215 if (
TT.supportsCOMDAT())
1216 Bias->
setComdat(
M.getOrInsertComdat(VarName));
1222 auto *
Counters = getOrCreateRegionCounters(
I);
1231 if (!isRuntimeCounterRelocationEnabled())
1236 LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
1240 BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias,
"profc_bias");
1242 BiasLI->
setMetadata(LLVMContext::MD_invariant_load,
1250 auto *Bitmaps = getOrCreateRegionBitmaps(
I);
1251 if (!isRuntimeCounterRelocationEnabled())
1259 auto *BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias,
"profbm_bias");
1261 BiasLI->
setMetadata(LLVMContext::MD_invariant_load,
1266 return Builder.
CreatePtrAdd(Bitmaps, BiasLI,
"profbm_addr");
1270 auto *Addr = getCounterAddress(CoverInstruction);
1272 if (ConditionalCounterUpdate) {
1274 auto &Ctx = CoverInstruction->
getParent()->getContext();
1288void InstrLowerer::lowerTimestamp(
1291 "timestamp probes are always the first probe for a function");
1292 auto &Ctx =
M.getContext();
1293 auto *TimestampAddr = getCounterAddress(TimestampInstruction);
1297 auto Callee =
M.getOrInsertFunction(
1303InstrLowerer::GPUPGOInvariants &
1304InstrLowerer::getOrCreateGPUInvariants(
Function *
F) {
1305 auto It = GPUInvariantsCache.find(
F);
1306 if (It != GPUInvariantsCache.end())
1316 if (OffloadPGOSampling > 0) {
1319 RTLIB::impl___llvm_profile_sampling_gpu),
1322 IsSampledFn, {ConstantInt::get(Int32Ty, OffloadPGOSampling)},
1324 Matched = Builder.
CreateICmpNE(SampledInt, ConstantInt::get(Int32Ty, 0),
1328 auto &Inv = GPUInvariantsCache[
F];
1329 Inv.Matched = Matched;
1337 auto &Inv = getOrCreateGPUInvariants(
F);
1343 auto *Addr = getCounterAddress(Inc);
1348 if (!Inv.WaveSizeStored) {
1349 Inv.WaveSizeStored =
true;
1351 auto &
PD = ProfileDataMap[NamePtr];
1353 IRBuilder<> EntryBuilder(&*
F->getEntryBlock().getFirstInsertionPt());
1354 Value *WaveSize16 =
nullptr;
1358 if (
TT.isAMDGPU()) {
1364 Value *WaveSize = EntryBuilder.CreateCall(WaveSizeFn);
1365 WaveSize16 = EntryBuilder.CreateTrunc(
1371 Value *WaveSizeAddr = EntryBuilder.CreateStructGEP(
1372 PD.DataVar->getValueType(),
PD.DataVar, 9,
"profd.wavesize");
1373 EntryBuilder.CreateStore(WaveSize16, WaveSizeAddr);
1377 GlobalVariable *UniformCounters = getOrCreateUniformCounters(Inc);
1379 if (UniformCounters) {
1382 UniformCounters->
getValueType(), UniformCounters, UniformIndices,
1392 {PtrTy, PtrTy, Int64Ty},
false);
1395 RTLIB::impl___llvm_profile_instrument_gpu),
1398 if (OffloadPGOSampling > 0) {
1406 HeadBuilder.CreateCondBr(Inv.Matched, ThenBB, ContBB);
1409 ThenBuilder.CreateCall(Callee, {CastAddr, UniformAddrArg, StepI64});
1410 ThenBuilder.CreateBr(ContBB);
1412 Builder.
CreateCall(Callee, {CastAddr, UniformAddrArg, StepI64});
1418 auto *Addr = getCounterAddress(Inc);
1421 if ((!isCounterPromotionEnabled() &&
isAtomic()) ||
1430 if (isCounterPromotionEnabled())
1436void InstrLowerer::lowerCoverageData(
GlobalVariable *CoverageNamesVar) {
1441 Value *
V =
NC->stripPointerCasts();
1446 ReferencedNames.push_back(Name);
1448 NC->dropAllReferences();
1453void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
1455 auto &Ctx =
M.getContext();
1460 auto *BitmapAddr = getBitmapAddress(Update);
1465 Builder.
CreateLoad(Int32Ty, MCDCCondBitmapAddr,
"mcdc.temp"),
1470 auto *BitmapByteOffset = Builder.
CreateLShr(Temp, 0x3);
1474 auto *BitmapByteAddr =
1488 auto *Bitmap = Builder.
CreateLoad(Int8Ty, BitmapByteAddr,
"mcdc.bits");
1529 return (Prefix + Name).str();
1535 return (Prefix + Name).str();
1544 if (!profDataReferencedByCode(*
F->getParent()))
1548 bool HasAvailableExternallyLinkage =
F->hasAvailableExternallyLinkage();
1549 if (!
F->hasLinkOnceLinkage() && !
F->hasLocalLinkage() &&
1550 !HasAvailableExternallyLinkage)
1556 if (HasAvailableExternallyLinkage &&
1557 F->hasFnAttribute(Attribute::AlwaysInline))
1563 if (
F->hasLocalLinkage() &&
F->hasComdat())
1573 return F->hasAddressTaken() ||
F->hasLinkOnceLinkage();
1626 Fn->
getName() +
".local", Fn);
1655 if (TT.isOSBinFormatELF() || TT.isOSBinFormatCOFF() ||
1656 TT.isOSBinFormatMachO() || TT.isOSBinFormatXCOFF() ||
1657 TT.isOSBinFormatWasm())
1670 bool UseComdat = (NeedComdat ||
TT.isOSBinFormatELF());
1685 StringRef GroupName =
TT.isOSBinFormatCOFF() && DataReferencedByCode
1688 Comdat *
C =
M.getOrInsertComdat(GroupName);
1708 if (!profDataReferencedByCode(*GV->
getParent()))
1733void InstrLowerer::getOrCreateVTableProfData(
GlobalVariable *GV) {
1735 "Value profiling is not supported with lightweight instrumentation");
1746 auto It = VTableDataMap.find(GV);
1747 if (It != VTableDataMap.end() && It->second)
1755 if (
TT.isOSBinFormatXCOFF()) {
1761 Type *DataTypes[] = {
1762#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) LLVMType,
1764#undef INSTR_PROF_VTABLE_DATA
1771 const std::string PGOVTableName =
getPGOName(*GV);
1777#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) Init,
1779#undef INSTR_PROF_VTABLE_DATA
1787 Data->setVisibility(Visibility);
1791 maybeSetComdat(
Data, GV,
Data->getName());
1793 VTableDataMap[GV] =
Data;
1795 ReferencedVTables.push_back(GV);
1799 UsedVars.push_back(
Data);
1822 if (
TT.isOSBinFormatXCOFF()) {
1831 if (IPSK == IPSK_cnts) {
1835 Ptr = createRegionCounters(CntrIncrement, VarName,
Linkage);
1836 }
else if (IPSK == IPSK_bitmap) {
1841 Ptr = createRegionBitmaps(BitmapUpdate, VarName,
Linkage);
1850 Ptr->
setComdat(
M.getOrInsertComdat(VarName));
1854 maybeSetComdat(Ptr, Fn, VarName);
1874 auto &
PD = ProfileDataMap[NamePtr];
1875 if (
PD.RegionBitmaps)
1876 return PD.RegionBitmaps;
1880 auto *BitmapPtr = setupProfileSection(Inc, IPSK_bitmap);
1881 PD.RegionBitmaps = BitmapPtr;
1884 if (
PD.NumBitmapBytes &&
1890 Metadata *FunctionNameAnnotation[] = {
1894 Metadata *NumBitmapBitsAnnotation[] = {
1902 auto *DICounter =
DB.createGlobalVariableExpression(
1903 SP, BitmapPtr->getName(),
StringRef(),
SP->getFile(),
1904 0,
DB.createUnspecifiedType(
"Profile Bitmap Type"),
1905 BitmapPtr->hasLocalLinkage(),
true,
nullptr,
1906 nullptr,
nullptr, 0,
1908 BitmapPtr->addDebugInfo(DICounter);
1909 DB.finalizeSubprogram(SP);
1914 CompilerUsedVars.push_back(
PD.RegionBitmaps);
1917 return PD.RegionBitmaps;
1924 auto &Ctx =
M.getContext();
1930 std::vector<Constant *> InitialValues(NumCounters,
1948 auto &
PD = ProfileDataMap[NamePtr];
1949 if (
PD.RegionCounters)
1950 return PD.RegionCounters;
1954 auto *CounterPtr = setupProfileSection(Inc, IPSK_cnts);
1955 PD.RegionCounters = CounterPtr;
1962 Metadata *FunctionNameAnnotation[] = {
1970 Metadata *NumCountersAnnotation[] = {
1979 auto *DICounter =
DB.createGlobalVariableExpression(
1980 SP, CounterPtr->getName(),
StringRef(),
SP->getFile(),
1981 0,
DB.createUnspecifiedType(
"Profile Data Type"),
1982 CounterPtr->hasLocalLinkage(),
true,
nullptr,
1983 nullptr,
nullptr, 0,
1985 CounterPtr->addDebugInfo(DICounter);
1986 DB.finalizeSubprogram(SP);
1991 CompilerUsedVars.push_back(
PD.RegionCounters);
1996 getOrCreateUniformCounters(Inc);
1999 createDataVariable(Inc);
2001 return PD.RegionCounters;
2011 auto &
PD = ProfileDataMap[NamePtr];
2012 if (
PD.UniformCounters)
2013 return PD.UniformCounters;
2015 assert(
PD.RegionCounters &&
"region counters must be created first");
2035 PD.UniformCounters = GV;
2036 CompilerUsedVars.push_back(GV);
2038 return PD.UniformCounters;
2048 auto &
PD = ProfileDataMap[NamePtr];
2065 if (
TT.isOSBinFormatXCOFF()) {
2074 std::string CntsVarName =
2076 std::string DataVarName =
2084 for (uint32_t Kind = IPVK_First;
Kind <= IPVK_Last; ++
Kind)
2085 NS +=
PD.NumValueSites[Kind];
2086 if (NS > 0 && ValueProfileStaticAlloc &&
2092 ValuesVar->setVisibility(Visibility);
2094 ValuesVar->setSection(
2096 ValuesVar->setAlignment(
Align(8));
2097 maybeSetComdat(ValuesVar, Fn, CntsVarName);
2110 auto *
IntPtrTy =
M.getDataLayout().getIntPtrType(
M.getContext());
2113 auto *DataTy = getProfileDataTy();
2117 Constant *Int16ArrayVals[IPVK_Last + 1];
2118 for (uint32_t Kind = IPVK_First;
Kind <= IPVK_Last; ++
Kind)
2119 Int16ArrayVals[Kind] = ConstantInt::get(Int16Ty,
PD.NumValueSites[Kind]);
2121 uint16_t OffloadDeviceWaveSizeVal = 0;
2144 !(DataReferencedByCode && NeedComdat && !Renamed) &&
2145 (
TT.isOSBinFormatELF() ||
2146 (!DataReferencedByCode &&
TT.isOSBinFormatCOFF()))) {
2153 if (
TT.isGPU() &&
TT.isOSBinFormatELF() &&
2167 DataSectionKind = IPSK_covdata;
2169 if (BitmapPtr !=
nullptr)
2172 RelativeUniformCounterPtr =
2174 }
else if (
TT.isNVPTX()) {
2178 DataSectionKind = IPSK_data;
2183 DataSectionKind = IPSK_data;
2184 RelativeCounterPtr =
2187 if (BitmapPtr !=
nullptr)
2198#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
2203 Data->setVisibility(Visibility);
2208 Data->setComdat(
M.getOrInsertComdat(CntsVarName));
2211 maybeSetComdat(
Data, Fn, CntsVarName);
2217 CompilerUsedVars.push_back(
Data);
2223 ReferencedNames.push_back(NamePtr);
2226void InstrLowerer::emitVNodes() {
2227 if (!ValueProfileStaticAlloc)
2237 for (
auto &PD : ProfileDataMap) {
2238 for (uint32_t Kind = IPVK_First;
Kind <= IPVK_Last; ++
Kind)
2239 TotalNS +=
PD.second.NumValueSites[Kind];
2245 uint64_t NumCounters = TotalNS * NumCountersPerValueSite;
2253#define INSTR_PROF_MIN_VAL_COUNTS 10
2257 auto &Ctx =
M.getContext();
2258 Type *VNodeTypes[] = {
2259#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init) LLVMType,
2269 VNodesVar->setSection(
2271 VNodesVar->setAlignment(
M.getDataLayout().getABITypeAlign(VNodesTy));
2274 UsedVars.push_back(VNodesVar);
2282 std::string Name = (
"__llvm_profile_sections" + CUIDPostfix).str();
2283 if (M.getNamedValue(Name))
2287 unsigned AS = M.getDataLayout().getDefaultGlobalsAddressSpace();
2293 nullptr, Sym,
nullptr,
2302 Constant *Fields[] = {
Extern(
"__start___llvm_prf_names", I8,
false, Hidden),
2303 Extern(
"__stop___llvm_prf_names", I8,
false, Hidden),
2304 Extern(
"__start___llvm_prf_cnts", I8,
false, Hidden),
2305 Extern(
"__stop___llvm_prf_cnts", I8,
false, Hidden),
2306 Extern(
"__start___llvm_prf_data", I8,
false, Hidden),
2307 Extern(
"__stop___llvm_prf_data", I8,
false, Hidden),
2308 Extern(
"__start___llvm_prf_ucnts", I8,
false, Hidden),
2309 Extern(
"__stop___llvm_prf_ucnts", I8,
false, Hidden),
2310 Extern(
"__llvm_profile_raw_version",
2315 Ctx, {PtrTy, PtrTy, PtrTy, PtrTy, PtrTy, PtrTy, PtrTy, PtrTy, PtrTy});
2324void InstrLowerer::emitNameData() {
2325 if (ReferencedNames.empty())
2328 std::string CompressedNameStr;
2334 auto &Ctx =
M.getContext();
2340 std::string GPUCUIDPostfix;
2345 if (
Init->isCString()) {
2346 GPUCUIDPostfix =
Init->getAsCString().str();
2347 NamesVarName += GPUCUIDPostfix;
2351 M, [GV](
Constant *
C) {
return C->stripPointerCasts() == GV; });
2357 NamesVar =
new GlobalVariable(M, NamesVal->getType(),
true, NamesLinkage,
2358 NamesVal, NamesVarName);
2359 NamesVar->setVisibility(NamesVisibility);
2361 NamesSize = CompressedNameStr.size();
2363 std::string NamesSectionName =
2367 NamesVar->setSection(NamesSectionName);
2371 NamesVar->setAlignment(
Align(1));
2374 UsedVars.push_back(NamesVar);
2376 for (
auto *NamePtr : ReferencedNames)
2382 [](
const auto &KV) { return KV.second.DataVar; });
2383 if (!GPUCUIDPostfix.empty() && HasData)
2385 CompilerUsedVars.push_back(GV);
2388void InstrLowerer::emitVTableNames() {
2393 std::string CompressedVTableNames;
2399 auto &Ctx =
M.getContext();
2401 Ctx,
StringRef(CompressedVTableNames),
false );
2410 UsedVars.push_back(VTableNamesVar);
2413void InstrLowerer::emitRegistration() {
2426 RegisterF->addFnAttr(Attribute::NoRedZone);
2429 auto *RuntimeRegisterF =
2437 IRB.CreateCall(RuntimeRegisterF,
2438 IRB.CreatePointerBitCastOrAddrSpaceCast(
Data, VoidPtrTy));
2441 IRB.CreateCall(RuntimeRegisterF,
2442 IRB.CreatePointerBitCastOrAddrSpaceCast(
Data, VoidPtrTy));
2445 Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
2446 auto *NamesRegisterTy =
2448 auto *NamesRegisterF =
2451 IRB.CreateCall(NamesRegisterF, {IRB.CreatePointerBitCastOrAddrSpaceCast(
2452 NamesVar, VoidPtrTy),
2453 IRB.getInt64(NamesSize)});
2456 IRB.CreateRetVoid();
2459bool InstrLowerer::emitRuntimeHook() {
2467 if (
TT.isOSLinux() ||
TT.isOSAIX())
2481 if (
TT.isOSBinFormatELF() && !
TT.isPS()) {
2483 CompilerUsedVars.push_back(Var);
2489 User->addFnAttr(Attribute::NoInline);
2491 User->addFnAttr(Attribute::NoRedZone);
2493 if (
TT.supportsCOMDAT())
2496 User->setEntryCount(0);
2499 auto *
Load = IRB.CreateLoad(Int32Ty, Var);
2500 IRB.CreateRet(
Load);
2503 CompilerUsedVars.push_back(
User);
2508void InstrLowerer::emitUses() {
2518 if (
TT.isOSBinFormatELF() ||
TT.isOSBinFormatMachO() ||
2519 (
TT.isOSBinFormatCOFF() && !DataReferencedByCode))
2530void InstrLowerer::emitInitialization() {
2547 F->addFnAttr(Attribute::NoInline);
2549 F->addFnAttr(Attribute::NoRedZone);
2553 IRB.CreateCall(RegisterF, {});
2554 IRB.CreateRetVoid();
2565 if (getSampledInstrumentationConfig().UseShort) {
2575 SamplingVar->setThreadLocal(
true);
2576 Triple TT(M.getTargetTriple());
2577 if (TT.supportsCOMDAT()) {
2579 SamplingVar->setComdat(M.getOrInsertComdat(VarName));
2588StructType *InstrLowerer::getProfileDataTy() {
2590 return ProfileDataTy;
2592 auto &Ctx =
M.getContext();
2593 auto *
IntPtrTy =
M.getDataLayout().getIntPtrType(
M.getContext());
2596 Type *DataTypes[] = {
2597#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) LLVMType,
2601 return ProfileDataTy;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file declares the LLVM IR specialization of the GenericCycle templates.
static unsigned InstrCount
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
#define INSTR_PROF_QUOTE(x)
#define INSTR_PROF_DATA_ALIGNMENT
#define INSTR_PROF_PROFILE_SET_TIMESTAMP
#define INSTR_PROF_PROFILE_SAMPLING_VAR
static bool shouldRecordVTableAddr(GlobalVariable *GV)
static bool shouldRecordFunctionAddr(Function *F)
static bool needsRuntimeHookUnconditionally(const Triple &TT)
static bool containsProfilingIntrinsics(Module &M)
Check if the module contains uses of any profiling intrinsics.
static std::string getVarName(InstrProfInstBase *Inc, StringRef Prefix, bool &Renamed)
Get the name of a profiling variable for a particular function.
#define INSTR_PROF_MIN_VAL_COUNTS
static Constant * getFuncAddrForProfData(Function *Fn)
static bool shouldUsePublicSymbol(Function *Fn)
static FunctionCallee getOrInsertValueProfilingCall(Module &M, const TargetLibraryInfo &TLI, ValueProfilingCallType CallType=ValueProfilingCallType::Default)
static Constant * getVTableAddrForProfData(GlobalVariable *GV)
static void doAtomicCheck(Function *F)
static GlobalVariable * emitGPUOffloadSectionsStruct(Module &M, StringRef CUIDPostfix)
static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT)
This file provides the interface for LLVM's PGO Instrumentation lowering pass.
Machine Check Debug Module
This file provides the interface for IR based instrumentation passes ( (profile-gen,...
FunctionAnalysisManager FAM
SmallPtrSet< BasicBlock *, 0 > BlockSet
This file defines the SmallVector class.
Class for arbitrary precision integers.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Annotations lets you mark points and ranges inside source code, for tests:
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Instruction & front() const
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
LLVM_ABI void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
This class represents a function call, abstracting a target machine's calling convention.
@ NoDeduplicate
No deduplication is performed.
ConstantArray - Constant Array Declarations.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true, bool ByteString=false)
This method constructs a CDS and initializes it with a text string.
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
static LLVM_ABI Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Lightweight error class with error context and mandatory checking.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
const BasicBlock & getEntryBlock() const
DISubprogram * getSubprogram() const
Get the attached subprogram.
const Function & getFunction() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
void compute(FunctionT &F)
Compute the cycle info for a function.
static LLVM_ABI GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
bool hasMetadata() const
Return true if this GlobalObject has any metadata attached to it.
LLVM_ABI void setComdat(Comdat *C)
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
bool hasLinkOnceLinkage() const
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
LinkageTypes getLinkage() const
bool hasLocalLinkage() const
bool hasPrivateLinkage() const
void setLinkage(LinkageTypes LT)
bool isDeclarationForLinker() const
Module * getParent()
Get the module that this global value is contained inside of...
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
void setVisibility(VisibilityTypes V)
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
bool hasAvailableExternallyLinkage() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Value * CreatePtrAdd(Value *Ptr, Value *Offset, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
BasicBlock * GetInsertBlock() const
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Value * CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Value * CreateInBoundsPtrAdd(Value *Ptr, Value *Offset, const Twine &Name="")
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System, bool Elementwise=false)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
A base class for all instrprof counter intrinsics.
LLVM_ABI ConstantInt * getIndex() const
LLVM_ABI ConstantInt * getNumCounters() const
static LLVM_ABI const char * FunctionNameAttributeName
static LLVM_ABI const char * CFGHashAttributeName
static LLVM_ABI const char * NumCountersAttributeName
static LLVM_ABI const char * NumBitmapBitsAttributeName
This represents the llvm.instrprof.cover intrinsic.
This represents the llvm.instrprof.increment intrinsic.
LLVM_ABI Value * getStep() const
A base class for all instrprof intrinsics.
GlobalVariable * getName() const
ConstantInt * getHash() const
A base class for instrprof mcdc intrinsics that require global bitmap bytes.
ConstantInt * getNumBitmapBits() const
auto getNumBitmapBytes() const
This represents the llvm.instrprof.mcdc.tvbitmap.update intrinsic.
Value * getMCDCCondBitmapAddr() const
ConstantInt * getBitmapIndex() const
This represents the llvm.instrprof.timestamp intrinsic.
This represents the llvm.instrprof.value.profile intrinsic.
ConstantInt * getIndex() const
Value * getTargetValue() const
ConstantInt * getValueKind() const
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI void moveBefore(InstListType::iterator InsertPos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
Return all of the successor blocks of this loop.
void getExitingBlocks(SmallVectorImpl< BlockT * > &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
bool hasDedicatedExits() const
Return true if no exit block for the loop has a predecessor that is outside the loop.
SmallVector< LoopT *, 4 > getLoopsInPreorder() const
Return all of the loops in the function in preorder across the loop nests, with siblings in forward p...
void analyze(ParentT F)
Create the loop forest for a function.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
LLVM_ABI MDNode * createUnlikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards false destination.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
A Module instance is used to store all the information related to an LLVM module.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr size_t size() const
Get the string size.
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
const ParentTy * getParent() const
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ BasicBlock
Various leaf nodes.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
constexpr bool isAtomic(const T &...O)
@ PD
PD - Prefix code for packed double precision vector floating point operations performed in the SSE re...
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
DXILDebugInfoMap run(Module &M)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
StringRef getInstrProfNameVarPrefix()
Return the name prefix of variables containing instrumented function names.
RelativeUniformCounterPtr ValuesPtrExpr NumBitmapBytes
StringRef getInstrProfRuntimeHookVarName()
Return the name of the hook variable defined in profile runtime library.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI void createProfileSamplingVar(Module &M)
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
StringRef getInstrProfBitmapVarPrefix()
Return the name prefix of profile bitmap variables.
LLVM_ABI cl::opt< bool > DoInstrProfNameCompression
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
StringRef getInstrProfVTableNamesVarName()
StringRef getInstrProfDataVarPrefix()
Return the name prefix of variables containing per-function control data.
RelativeUniformCounterPtr ValuesPtrExpr Int16ArrayTy
StringRef getCoverageUnusedNamesVarName()
Return the name of the internal variable recording the array of PGO name vars referenced by the cover...
LLVM_ABI std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI bool needsComdatForCounter(const GlobalObject &GV, const Module &M)
Check if we can use Comdat for profile variables.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI std::string getPGOName(const GlobalVariable &V, bool InLTO=false)
StringRef getInstrProfInitFuncName()
Return the name of the runtime initialization method that is generated by the compiler.
StringRef getInstrProfValuesVarPrefix()
Return the name prefix of value profile variables.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
StringRef getInstrProfCounterBiasVarName()
auto reverse(ContainerTy &&C)
StringRef getInstrProfRuntimeHookVarUseFuncName()
Return the name of the compiler generated function that references the runtime hook variable.
StringRef getInstrProfRegFuncsName()
Return the name of function that registers all the per-function control data at program startup time ...
LLVM_ABI Error collectPGOFuncNameStrings(ArrayRef< GlobalVariable * > NameVars, std::string &Result, bool doCompression=true)
Produce Result string with the same format described above.
LLVM_ABI void SplitBlockAndInsertIfThenElse(Value *Cond, BasicBlock::iterator SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
StringRef getInstrProfCountersVarPrefix()
Return the name prefix of profile counter variables.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
inst_range instructions(Function *F)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
StringRef getInstrProfBitmapBiasVarName()
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
StringRef getInstrProfValueProfMemOpFuncName()
Return the name profile runtime entry point to do memop size value profiling.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void removeFromUsedLists(Module &M, function_ref< bool(Constant *)> ShouldRemove)
Removes global values from the llvm.used and llvm.compiler.used arrays.
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
StringRef getInstrProfNamesRegFuncName()
Return the name of the runtime interface that registers the PGO name strings.
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
LLVM_ABI Error collectVTableStrings(ArrayRef< GlobalVariable * > VTables, std::string &Result, bool doCompression)
LLVM_ABI void setGlobalVariableLargeSection(const Triple &TargetTriple, GlobalVariable &GV)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
LLVM_ABI void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
StringRef getInstrProfNamesVarPostfixVarName()
LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
LLVM_ABI bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src, const BasicBlock &Dest)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
StringRef getInstrProfValueProfFuncName()
Return the name profile runtime entry point to do value profiling for a given site.
llvm::cl::opt< llvm::InstrProfCorrelator::ProfCorrelatorKind > ProfileCorrelate
StringRef getInstrProfRegFuncName()
Return the name of the runtime interface that registers per-function control data for one instrumente...
LLVM_ABI Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
StringRef getInstrProfNamesVarName()
Return the name of the variable holding the strings (possibly compressed) of all function's PGO names...
LLVM_ABI bool isGPUProfTarget(const Module &M)
Determines whether module targets a GPU eligable for PGO instrumentation.
LLVM_ABI bool isIRPGOFlagSet(const Module *M)
Check if INSTR_PROF_RAW_VERSION_VAR is defined.
StringRef getInstrProfVNodesVarName()
Return the name of value profile node array variables:
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
cl::opt< bool > EnableVTableValueProfiling("enable-vtable-value-profiling", cl::init(false), cl::desc("If true, the virtual table address will be instrumented to know " "the types of a C++ pointer. The information is used in indirect " "call promotion to do selective vtable-based comparison."))
@ Extern
Replace returns with jump to thunk, don't emit thunk.
StringRef getInstrProfVTableVarPrefix()
Return the name prefix of variables containing virtual table profile data.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl)
Get the libcall routine name for the specified libcall implementation.