66#define DEBUG_TYPE "instrprof"
74 cl::desc(
"Use debug info or binary file to correlate profiles."),
77 "No profile correlation"),
79 "Use debug info to correlate"),
81 "Use binary to correlate")));
87 "hash-based-counter-split",
88 cl::desc(
"Rename counter variable of a comdat function based on cfg hash"),
92 RuntimeCounterRelocation(
"runtime-counter-relocation",
93 cl::desc(
"Enable relocating counters at runtime."),
98 cl::desc(
"Do static counter allocation for value profiler"),
102 "vp-counters-per-site",
103 cl::desc(
"The average number of profile counters allocated "
104 "per value profiling site."),
112 "instrprof-atomic-counter-update-all",
113 cl::desc(
"Make all profile counter updates atomic (for testing only)"),
117 "atomic-counter-update-promoted",
118 cl::desc(
"Do counter update using atomic fetch add "
119 " for promoted counters only"),
123 "atomic-first-counter",
124 cl::desc(
"Use atomic fetch add for first counter in a function (usually "
125 "the entry counter)"),
129 "conditional-counter-update",
130 cl::desc(
"Do conditional counter updates in single byte counters mode)"),
139 cl::desc(
"Do counter register promotion"),
142 "max-counter-promotions-per-loop",
cl::init(20),
143 cl::desc(
"Max number counter promotions per loop to avoid"
144 " increasing register pressure too much"));
148 MaxNumOfPromotions(
"max-counter-promotions",
cl::init(-1),
149 cl::desc(
"Max number of allowed counter promotions"));
152 "speculative-counter-promotion-max-exiting",
cl::init(3),
153 cl::desc(
"The max number of exiting blocks of a loop to allow "
154 " speculative counter promotion"));
157 "speculative-counter-promotion-to-loop",
158 cl::desc(
"When the option is false, if the target block is in a loop, "
159 "the promotion will be disallowed unless the promoted counter "
160 " update can be further/iteratively promoted into an acyclic "
164 "iterative-counter-promotion",
cl::init(
true),
165 cl::desc(
"Allow counter promotion across the whole loop nest."));
168 "skip-ret-exit-block",
cl::init(
true),
169 cl::desc(
"Suppress counter promotion if exit blocks contain ret."));
172 cl::desc(
"Do PGO instrumentation sampling"));
175 "sampled-instr-period",
176 cl::desc(
"Set the profile instrumentation sample period. A sample period "
177 "of 0 is invalid. For each sample period, a fixed number of "
178 "consecutive samples will be recorded. The number is controlled "
179 "by 'sampled-instr-burst-duration' flag. The default sample "
180 "period of 65536 is optimized for generating efficient code that "
181 "leverages unsigned short integer wrapping in overflow, but this "
182 "is disabled under simple sampling (burst duration = 1)."),
186 "sampled-instr-burst-duration",
187 cl::desc(
"Set the profile instrumentation burst duration, which can range "
188 "from 1 to the value of 'sampled-instr-period' (0 is invalid). "
189 "This number of samples will be recorded for each "
190 "'sampled-instr-period' count update. Setting to 1 enables simple "
191 "sampling, in which case it is recommended to set "
192 "'sampled-instr-period' to a prime number."),
195struct SampledInstrumentationConfig {
196 unsigned BurstDuration;
199 bool IsSimpleSampling;
203static SampledInstrumentationConfig getSampledInstrumentationConfig() {
204 SampledInstrumentationConfig config;
205 config.BurstDuration = SampledInstrBurstDuration.getValue();
206 config.Period = SampledInstrPeriod.getValue();
207 if (config.BurstDuration > config.Period)
209 "SampledBurstDuration must be less than or equal to SampledPeriod");
210 if (config.Period == 0 || config.BurstDuration == 0)
212 "SampledPeriod and SampledBurstDuration must be greater than 0");
213 config.IsSimpleSampling = (config.BurstDuration == 1);
216 config.IsFastSampling =
217 (!config.IsSimpleSampling && config.Period == USHRT_MAX + 1);
218 config.UseShort = (config.Period <= USHRT_MAX) || config.IsFastSampling;
222using LoadStorePair = std::pair<Instruction *, Instruction *>;
234static bool enablesValueProfiling(
const Module &M) {
236 getIntModuleFlagOrZero(M,
"EnableValueProfiling") != 0;
240static bool profDataReferencedByCode(
const Module &M) {
241 return enablesValueProfiling(M);
244class InstrLowerer final {
246 InstrLowerer(
Module &M,
const InstrProfOptions &Options,
247 std::function<
const TargetLibraryInfo &(Function &
F)> GetTLI,
249 : M(M), Options(Options), TT(M.getTargetTriple()), IsCS(IsCS),
250 GetTLI(GetTLI), DataReferencedByCode(profDataReferencedByCode(M)) {}
256 const InstrProfOptions Options;
261 std::function<
const TargetLibraryInfo &(
Function &
F)> GetTLI;
263 const bool DataReferencedByCode;
265 struct PerFunctionProfileData {
266 uint32_t NumValueSites[IPVK_Last + 1] = {};
267 GlobalVariable *RegionCounters =
nullptr;
268 GlobalVariable *DataVar =
nullptr;
269 GlobalVariable *RegionBitmaps =
nullptr;
270 uint32_t NumBitmapBytes = 0;
272 PerFunctionProfileData() =
default;
274 DenseMap<GlobalVariable *, PerFunctionProfileData> ProfileDataMap;
277 DenseMap<GlobalVariable *, GlobalVariable *> VTableDataMap;
280 DenseMap<const Function *, LoadInst *> FunctionToProfileBiasMap;
281 std::vector<GlobalValue *> CompilerUsedVars;
282 std::vector<GlobalValue *> UsedVars;
283 std::vector<GlobalVariable *> ReferencedNames;
286 std::vector<GlobalVariable *> ReferencedVTables;
287 GlobalVariable *NamesVar =
nullptr;
288 size_t NamesSize = 0;
291 std::vector<LoadStorePair> PromotionCandidates;
293 int64_t TotalCountersPromoted = 0;
297 bool lowerIntrinsics(Function *
F);
300 void promoteCounterLoadStores(Function *
F);
303 bool isRuntimeCounterRelocationEnabled()
const;
306 bool isCounterPromotionEnabled()
const;
309 bool isSamplingEnabled()
const;
312 void computeNumValueSiteCounts(InstrProfValueProfileInst *Ins);
315 void lowerValueProfileInst(InstrProfValueProfileInst *Ins);
318 void lowerCover(InstrProfCoverInst *Inc);
322 void lowerTimestamp(InstrProfTimestampInst *TimestampInstruction);
325 void lowerIncrement(InstrProfIncrementInst *Inc);
328 void lowerCoverageData(GlobalVariable *CoverageNamesVar);
332 void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
336 GlobalVariable *getOrCreateBiasVar(StringRef VarName);
340 Value *getCounterAddress(InstrProfCntrInstBase *
I);
343 void doSampling(Instruction *
I);
349 GlobalVariable *getOrCreateRegionCounters(InstrProfCntrInstBase *Inc);
352 GlobalVariable *createRegionCounters(InstrProfCntrInstBase *Inc,
358 Value *getBitmapAddress(InstrProfMCDCTVBitmapUpdate *
I);
364 GlobalVariable *getOrCreateRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc);
371 GlobalVariable *createRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc,
376 void maybeSetComdat(GlobalVariable *GV, GlobalObject *GO, StringRef VarName);
379 GlobalVariable *setupProfileSection(InstrProfInstBase *Inc,
383 void createDataVariable(InstrProfCntrInstBase *Inc);
386 void getOrCreateVTableProfData(GlobalVariable *GV);
392 void emitVTableNames();
398 void emitRegistration();
402 bool emitRuntimeHook();
409 void emitInitialization();
421 PGOCounterPromoterHelper(
422 Instruction *L, Instruction *S, SSAUpdater &
SSA,
Value *Init,
427 : LoadAndStorePromoter({
L, S},
SSA), Store(S), ExitBlocks(ExitBlocks),
428 InsertPts(InsertPts), LoopToCandidates(LoopToCands), LI(LI) {
431 SSA.AddAvailableValue(PH, Init);
434 void doExtraRewritesBeforeFinalDeletion()
override {
435 for (
unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
441 Value *LiveInValue =
SSA.GetValueInMiddleOfBlock(ExitBlock);
453 assert(OrigBiasInst->getOpcode() == Instruction::BinaryOps::Add);
454 Value *BiasInst = Builder.Insert(OrigBiasInst->clone());
455 Addr = Builder.CreateIntToPtr(BiasInst,
458 if (AtomicCounterUpdatePromoted)
463 AtomicOrdering::SequentiallyConsistent);
465 LoadInst *OldVal = Builder.CreateLoad(Ty, Addr,
"pgocount.promoted");
466 auto *NewVal = Builder.CreateAdd(OldVal, LiveInValue);
467 auto *NewStore = Builder.CreateStore(NewVal, Addr);
470 if (IterativeCounterPromotion) {
471 auto *TargetLoop = LI.getLoopFor(ExitBlock);
473 LoopToCandidates[TargetLoop].emplace_back(OldVal, NewStore);
483 DenseMap<Loop *, SmallVector<LoadStorePair, 8>> &LoopToCandidates;
490class PGOCounterPromoter {
494 Loop &CurLoop, LoopInfo &LI, BlockFrequencyInfo *BFI)
495 : LoopToCandidates(LoopToCands), L(CurLoop), LI(LI), BFI(BFI) {
499 SmallVector<BasicBlock *, 8> LoopExitBlocks;
500 SmallPtrSet<BasicBlock *, 8>
BlockSet;
502 L.getExitBlocks(LoopExitBlocks);
503 if (!isPromotionPossible(&L, LoopExitBlocks))
506 for (BasicBlock *ExitBlock : LoopExitBlocks) {
507 if (
BlockSet.insert(ExitBlock).second &&
511 ExitBlocks.push_back(ExitBlock);
517 bool run(int64_t *NumPromoted) {
519 if (ExitBlocks.size() == 0)
527 if (SkipRetExitBlock) {
528 for (
auto *BB : ExitBlocks)
533 unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
537 unsigned Promoted = 0;
538 for (
auto &Cand : LoopToCandidates[&L]) {
541 SSAUpdater
SSA(&NewPHIs);
542 Value *InitVal = ConstantInt::get(Cand.first->getType(), 0);
546 auto *BB = Cand.first->getParent();
547 auto InstrCount = BFI->getBlockProfileCount(BB);
550 auto PreheaderCount = BFI->getBlockProfileCount(L.getLoopPreheader());
553 if (PreheaderCount && (*PreheaderCount * 3) >= (*
InstrCount * 2))
557 PGOCounterPromoterHelper Promoter(Cand.first, Cand.second,
SSA, InitVal,
558 L.getLoopPreheader(), ExitBlocks,
559 InsertPts, LoopToCandidates, LI);
560 Promoter.run(SmallVector<Instruction *, 2>({Cand.first, Cand.second}));
562 if (Promoted >= MaxProm)
566 if (MaxNumOfPromotions != -1 && *NumPromoted >= MaxNumOfPromotions)
570 LLVM_DEBUG(
dbgs() << Promoted <<
" counters promoted for loop (depth="
571 << L.getLoopDepth() <<
")\n");
572 return Promoted != 0;
576 bool allowSpeculativeCounterPromotion(Loop *LP) {
577 SmallVector<BasicBlock *, 8> ExitingBlocks;
578 L.getExitingBlocks(ExitingBlocks);
580 if (ExitingBlocks.
size() == 1)
582 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
590 isPromotionPossible(Loop *LP,
591 const SmallVectorImpl<BasicBlock *> &LoopExitBlocks) {
609 unsigned getMaxNumOfPromotionsInLoop(Loop *LP) {
610 SmallVector<BasicBlock *, 8> LoopExitBlocks;
612 if (!isPromotionPossible(LP, LoopExitBlocks))
615 SmallVector<BasicBlock *, 8> ExitingBlocks;
623 if (ExitingBlocks.
size() == 1)
624 return MaxNumOfPromotionsPerLoop;
626 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
630 if (SpeculativeCounterPromotionToLoop)
631 return MaxNumOfPromotionsPerLoop;
634 unsigned MaxProm = MaxNumOfPromotionsPerLoop;
635 for (
auto *TargetBlock : LoopExitBlocks) {
636 auto *TargetLoop = LI.getLoopFor(TargetBlock);
639 unsigned MaxPromForTarget = getMaxNumOfPromotionsInLoop(TargetLoop);
640 unsigned PendingCandsInTarget = LoopToCandidates[TargetLoop].size();
642 std::min(MaxProm, std::max(MaxPromForTarget, PendingCandsInTarget) -
643 PendingCandsInTarget);
648 DenseMap<Loop *, SmallVector<LoadStorePair, 8>> &LoopToCandidates;
649 SmallVector<BasicBlock *, 8> ExitBlocks;
650 SmallVector<Instruction *, 8> InsertPts;
653 BlockFrequencyInfo *BFI;
656enum class ValueProfilingCallType {
674 InstrLowerer Lowerer(M, Options, GetTLI, IsCS);
675 if (!Lowerer.lower())
726 if (!isSamplingEnabled())
729 SampledInstrumentationConfig config = getSampledInstrumentationConfig();
732 return Builder.getInt16(
C);
734 return Builder.getInt32(
C);
744 assert(SamplingVar &&
"SamplingVar not set properly");
748 Value *NewSamplingVarVal;
752 auto *LoadSamplingVar = CondBuilder.CreateLoad(SamplingVarTy, SamplingVar);
753 if (config.IsSimpleSampling) {
757 IncBuilder.CreateAdd(LoadSamplingVar, GetConstant(IncBuilder, 1));
758 SamplingVarIncr = IncBuilder.CreateStore(NewSamplingVarVal, SamplingVar);
761 auto *DurationCond = CondBuilder.CreateICmpULE(
762 LoadSamplingVar, GetConstant(CondBuilder, config.BurstDuration - 1));
763 BranchWeight = MDB.createBranchWeights(
764 config.BurstDuration, config.Period - config.BurstDuration);
766 DurationCond,
I,
false, BranchWeight);
769 IncBuilder.CreateAdd(LoadSamplingVar, GetConstant(IncBuilder, 1));
770 SamplingVarIncr = IncBuilder.CreateStore(NewSamplingVarVal, SamplingVar);
774 if (config.IsFastSampling)
780 auto *PeriodCond = PeriodCondBuilder.CreateICmpUGE(
781 NewSamplingVarVal, GetConstant(PeriodCondBuilder, config.Period));
782 BranchWeight = MDB.createBranchWeights(1, config.Period - 1);
784 &ElseTerm, BranchWeight);
787 if (config.IsSimpleSampling)
791 ResetBuilder.CreateStore(GetConstant(ResetBuilder, 0), SamplingVar);
795bool InstrLowerer::lowerIntrinsics(
Function *
F) {
796 bool MadeChange =
false;
797 PromotionCandidates.clear();
810 for (
auto *Instr : InstrProfInsts) {
813 lowerIncrement(IPIS);
825 lowerValueProfileInst(IPVP);
828 IPMP->eraseFromParent();
831 lowerMCDCTestVectorBitmapUpdate(IPBU);
839 promoteCounterLoadStores(
F);
843bool InstrLowerer::isRuntimeCounterRelocationEnabled()
const {
845 if (
TT.isOSBinFormatMachO())
848 if (RuntimeCounterRelocation.getNumOccurrences() > 0)
849 return RuntimeCounterRelocation;
852 return TT.isOSFuchsia();
855bool InstrLowerer::isSamplingEnabled()
const {
856 if (SampledInstr.getNumOccurrences() > 0)
861bool InstrLowerer::isCounterPromotionEnabled()
const {
862 if (DoCounterPromotion.getNumOccurrences() > 0)
863 return DoCounterPromotion;
865 return Options.DoCounterPromotion;
868void InstrLowerer::promoteCounterLoadStores(
Function *
F) {
869 if (!isCounterPromotionEnabled())
876 std::unique_ptr<BlockFrequencyInfo> BFI;
877 if (
Options.UseBFIInPromotion) {
878 std::unique_ptr<BranchProbabilityInfo> BPI;
883 for (
const auto &LoadStore : PromotionCandidates) {
890 LoopPromotionCandidates[ParentLoop].emplace_back(CounterLoad, CounterStore);
898 PGOCounterPromoter Promoter(LoopPromotionCandidates, *
Loop, LI, BFI.get());
899 Promoter.run(&TotalCountersPromoted);
905 if (TT.isOSFuchsia())
913 auto containsIntrinsic = [&](
int ID) {
915 return !
F->use_empty();
918 return containsIntrinsic(Intrinsic::instrprof_cover) ||
919 containsIntrinsic(Intrinsic::instrprof_increment) ||
920 containsIntrinsic(Intrinsic::instrprof_increment_step) ||
921 containsIntrinsic(Intrinsic::instrprof_timestamp) ||
922 containsIntrinsic(Intrinsic::instrprof_value_profile);
925bool InstrLowerer::lower() {
926 bool MadeChange =
false;
928 if (NeedsRuntimeHook)
929 MadeChange = emitRuntimeHook();
931 if (!IsCS && isSamplingEnabled())
938 if (!ContainsProfiling && !CoverageNamesVar)
949 computeNumValueSiteCounts(Ind);
951 if (FirstProfInst ==
nullptr &&
956 static_cast<void>(getOrCreateRegionBitmaps(Params));
963 if (FirstProfInst !=
nullptr) {
964 static_cast<void>(getOrCreateRegionCounters(FirstProfInst));
971 if (GV.hasMetadata(LLVMContext::MD_type))
972 getOrCreateVTableProfData(&GV);
975 MadeChange |= lowerIntrinsics(&
F);
977 if (CoverageNamesVar) {
978 lowerCoverageData(CoverageNamesVar);
993 if (!NeedsRuntimeHook && ContainsProfiling)
998 emitInitialization();
1004 ValueProfilingCallType CallType = ValueProfilingCallType::Default) {
1009 if (
auto AK = TLI.getExtAttrForI32Param(
false))
1010 AL = AL.addParamAttribute(M.getContext(), 2, AK);
1012 assert((CallType == ValueProfilingCallType::Default ||
1013 CallType == ValueProfilingCallType::MemOp) &&
1014 "Must be Default or MemOp");
1015 Type *ParamTypes[] = {
1016#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
1019 auto *ValueProfilingCallTy =
1021 StringRef FuncName = CallType == ValueProfilingCallType::Default
1024 return M.getOrInsertFunction(FuncName, ValueProfilingCallTy, AL);
1031 auto &
PD = ProfileDataMap[
Name];
1033 std::max(
PD.NumValueSites[ValueKind], (uint32_t)(Index + 1));
1042 "Value profiling is not yet supported with lightweight instrumentation");
1044 auto It = ProfileDataMap.find(Name);
1045 assert(It != ProfileDataMap.end() && It->second.DataVar &&
1046 "value profiling detected in function with no counter increment");
1052 Index += It->second.NumValueSites[Kind];
1055 bool IsMemOpSize = (Ind->
getValueKind()->getZExtValue() ==
1056 llvm::InstrProfValueKind::IPVK_MemOPSize);
1080 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1103 if (
TT.supportsCOMDAT())
1104 Bias->
setComdat(
M.getOrInsertComdat(VarName));
1110 auto *
Counters = getOrCreateRegionCounters(
I);
1119 if (!isRuntimeCounterRelocationEnabled())
1124 LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
1128 BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias,
"profc_bias");
1130 BiasLI->
setMetadata(LLVMContext::MD_invariant_load,
1138 auto *Bitmaps = getOrCreateRegionBitmaps(
I);
1139 if (!isRuntimeCounterRelocationEnabled())
1147 auto *BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias,
"profbm_bias");
1149 BiasLI->
setMetadata(LLVMContext::MD_invariant_load,
1154 return Builder.
CreatePtrAdd(Bitmaps, BiasLI,
"profbm_addr");
1158 auto *Addr = getCounterAddress(CoverInstruction);
1160 if (ConditionalCounterUpdate) {
1162 auto &Ctx = CoverInstruction->
getParent()->getContext();
1176void InstrLowerer::lowerTimestamp(
1179 "timestamp probes are always the first probe for a function");
1180 auto &Ctx =
M.getContext();
1181 auto *TimestampAddr = getCounterAddress(TimestampInstruction);
1185 auto Callee =
M.getOrInsertFunction(
1192 auto *Addr = getCounterAddress(Inc);
1199 {PtrTy, PtrTy, I64Ty},
false);
1201 M.getOrInsertFunction(
"__llvm_profile_instrument_gpu", CalleeTy);
1206 }
else if (
Options.Atomic || AtomicCounterUpdateAll ||
1215 if (isCounterPromotionEnabled())
1221void InstrLowerer::lowerCoverageData(
GlobalVariable *CoverageNamesVar) {
1226 Value *
V =
NC->stripPointerCasts();
1231 ReferencedNames.push_back(Name);
1233 NC->dropAllReferences();
1238void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
1240 auto &Ctx =
M.getContext();
1245 auto *BitmapAddr = getBitmapAddress(Update);
1255 auto *BitmapByteOffset = Builder.
CreateLShr(Temp, 0x3);
1259 auto *BitmapByteAddr =
1273 auto *Bitmap = Builder.
CreateLoad(Int8Ty, BitmapByteAddr,
"mcdc.bits");
1275 if (
Options.Atomic || AtomicCounterUpdateAll) {
1314 return (Prefix + Name).str();
1320 return (Prefix + Name).str();
1329 if (!profDataReferencedByCode(*
F->getParent()))
1333 bool HasAvailableExternallyLinkage =
F->hasAvailableExternallyLinkage();
1334 if (!
F->hasLinkOnceLinkage() && !
F->hasLocalLinkage() &&
1335 !HasAvailableExternallyLinkage)
1341 if (HasAvailableExternallyLinkage &&
1342 F->hasFnAttribute(Attribute::AlwaysInline))
1348 if (
F->hasLocalLinkage() &&
F->hasComdat())
1358 return F->hasAddressTaken() ||
F->hasLinkOnceLinkage();
1405 Fn->
getName() +
".local", Fn);
1430 if (TT.isOSBinFormatELF() || TT.isOSBinFormatCOFF() ||
1431 TT.isOSBinFormatMachO() || TT.isOSBinFormatXCOFF() ||
1432 TT.isOSBinFormatWasm())
1445 bool UseComdat = (NeedComdat ||
TT.isOSBinFormatELF());
1460 StringRef GroupName =
TT.isOSBinFormatCOFF() && DataReferencedByCode
1463 Comdat *
C =
M.getOrInsertComdat(GroupName);
1483 if (!profDataReferencedByCode(*GV->
getParent()))
1508void InstrLowerer::getOrCreateVTableProfData(
GlobalVariable *GV) {
1510 "Value profiling is not supported with lightweight instrumentation");
1521 auto It = VTableDataMap.find(GV);
1522 if (It != VTableDataMap.end() && It->second)
1530 if (
TT.isOSBinFormatXCOFF()) {
1536 Type *DataTypes[] = {
1537#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) LLVMType,
1539#undef INSTR_PROF_VTABLE_DATA
1546 const std::string PGOVTableName =
getPGOName(*GV);
1552#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Init) Init,
1554#undef INSTR_PROF_VTABLE_DATA
1562 Data->setVisibility(Visibility);
1566 maybeSetComdat(
Data, GV,
Data->getName());
1568 VTableDataMap[GV] =
Data;
1570 ReferencedVTables.push_back(GV);
1574 UsedVars.push_back(
Data);
1597 if (
TT.isOSBinFormatXCOFF()) {
1606 if (IPSK == IPSK_cnts) {
1610 Ptr = createRegionCounters(CntrIncrement, VarName,
Linkage);
1611 }
else if (IPSK == IPSK_bitmap) {
1616 Ptr = createRegionBitmaps(BitmapUpdate, VarName,
Linkage);
1626 maybeSetComdat(Ptr, Fn, VarName);
1645 auto &
PD = ProfileDataMap[NamePtr];
1646 if (
PD.RegionBitmaps)
1647 return PD.RegionBitmaps;
1651 auto *BitmapPtr = setupProfileSection(Inc, IPSK_bitmap);
1652 PD.RegionBitmaps = BitmapPtr;
1654 return PD.RegionBitmaps;
1661 auto &Ctx =
M.getContext();
1667 std::vector<Constant *> InitialValues(
NumCounters,
1685 auto &
PD = ProfileDataMap[NamePtr];
1686 if (
PD.RegionCounters)
1687 return PD.RegionCounters;
1691 auto *CounterPtr = setupProfileSection(Inc, IPSK_cnts);
1692 PD.RegionCounters = CounterPtr;
1699 Metadata *FunctionNameAnnotation[] = {
1707 Metadata *NumCountersAnnotation[] = {
1716 auto *DICounter =
DB.createGlobalVariableExpression(
1717 SP, CounterPtr->getName(),
StringRef(),
SP->getFile(),
1718 0,
DB.createUnspecifiedType(
"Profile Data Type"),
1719 CounterPtr->hasLocalLinkage(),
true,
nullptr,
1720 nullptr,
nullptr, 0,
1722 CounterPtr->addDebugInfo(DICounter);
1727 CompilerUsedVars.push_back(
PD.RegionCounters);
1731 createDataVariable(Inc);
1733 return PD.RegionCounters;
1743 auto &
PD = ProfileDataMap[NamePtr];
1760 if (
TT.isOSBinFormatXCOFF()) {
1769 std::string CntsVarName =
1771 std::string DataVarName =
1779 for (uint32_t Kind = IPVK_First;
Kind <= IPVK_Last; ++
Kind)
1780 NS +=
PD.NumValueSites[Kind];
1781 if (NS > 0 && ValueProfileStaticAlloc &&
1787 ValuesVar->setVisibility(Visibility);
1789 ValuesVar->setSection(
1791 ValuesVar->setAlignment(
Align(8));
1792 maybeSetComdat(ValuesVar, Fn, CntsVarName);
1798 auto *CounterPtr =
PD.RegionCounters;
1803 auto *IntPtrTy =
M.getDataLayout().getIntPtrType(
M.getContext());
1806 Type *DataTypes[] = {
1807#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) LLVMType,
1814 Constant *Int16ArrayVals[IPVK_Last + 1];
1815 for (uint32_t Kind = IPVK_First;
Kind <= IPVK_Last; ++
Kind)
1816 Int16ArrayVals[Kind] = ConstantInt::get(Int16Ty,
PD.NumValueSites[Kind]);
1833 else if (NS == 0 && !(DataReferencedByCode && NeedComdat && !Renamed) &&
1834 (
TT.isOSBinFormatELF() ||
1835 (!DataReferencedByCode &&
TT.isOSBinFormatCOFF()))) {
1843 Constant *RelativeBitmapPtr = ConstantInt::get(IntPtrTy, 0);
1848 DataSectionKind = IPSK_covdata;
1850 if (BitmapPtr !=
nullptr)
1855 DataSectionKind = IPSK_data;
1856 RelativeCounterPtr =
1859 if (BitmapPtr !=
nullptr)
1866#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
1871 Data->setVisibility(Visibility);
1875 maybeSetComdat(
Data, Fn, CntsVarName);
1880 CompilerUsedVars.push_back(
Data);
1886 ReferencedNames.push_back(NamePtr);
1889void InstrLowerer::emitVNodes() {
1890 if (!ValueProfileStaticAlloc)
1900 for (
auto &PD : ProfileDataMap) {
1901 for (uint32_t Kind = IPVK_First;
Kind <= IPVK_Last; ++
Kind)
1902 TotalNS +=
PD.second.NumValueSites[Kind];
1908 uint64_t
NumCounters = TotalNS * NumCountersPerValueSite;
1916#define INSTR_PROF_MIN_VAL_COUNTS 10
1920 auto &Ctx =
M.getContext();
1921 Type *VNodeTypes[] = {
1922#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init) LLVMType,
1932 VNodesVar->setSection(
1934 VNodesVar->setAlignment(
M.getDataLayout().getABITypeAlign(VNodesTy));
1937 UsedVars.push_back(VNodesVar);
1940void InstrLowerer::emitNameData() {
1941 if (ReferencedNames.empty())
1944 std::string CompressedNameStr;
1950 auto &Ctx =
M.getContext();
1961 NamesSize = CompressedNameStr.size();
1963 NamesVar->setSection(
1970 NamesVar->setAlignment(
Align(1));
1973 UsedVars.push_back(NamesVar);
1975 for (
auto *NamePtr : ReferencedNames)
1979void InstrLowerer::emitVTableNames() {
1984 std::string CompressedVTableNames;
1990 auto &Ctx =
M.getContext();
1992 Ctx,
StringRef(CompressedVTableNames),
false );
2001 UsedVars.push_back(VTableNamesVar);
2004void InstrLowerer::emitRegistration() {
2017 RegisterF->addFnAttr(Attribute::NoRedZone);
2020 auto *RuntimeRegisterF =
2028 IRB.CreateCall(RuntimeRegisterF,
2029 IRB.CreatePointerBitCastOrAddrSpaceCast(
Data, VoidPtrTy));
2032 IRB.CreateCall(RuntimeRegisterF,
2033 IRB.CreatePointerBitCastOrAddrSpaceCast(
Data, VoidPtrTy));
2036 Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
2037 auto *NamesRegisterTy =
2039 auto *NamesRegisterF =
2042 IRB.CreateCall(NamesRegisterF, {IRB.CreatePointerBitCastOrAddrSpaceCast(
2043 NamesVar, VoidPtrTy),
2044 IRB.getInt64(NamesSize)});
2047 IRB.CreateRetVoid();
2050bool InstrLowerer::emitRuntimeHook() {
2053 if (
TT.isOSLinux() ||
TT.isOSAIX())
2070 if (
TT.isOSBinFormatELF() && !
TT.isPS()) {
2072 CompilerUsedVars.push_back(Var);
2078 User->addFnAttr(Attribute::NoInline);
2080 User->addFnAttr(Attribute::NoRedZone);
2082 if (
TT.supportsCOMDAT())
2085 User->setEntryCount(0);
2089 IRB.CreateRet(Load);
2092 CompilerUsedVars.push_back(
User);
2097void InstrLowerer::emitUses() {
2107 if (
TT.isOSBinFormatELF() ||
TT.isOSBinFormatMachO() ||
2108 (
TT.isOSBinFormatCOFF() && !DataReferencedByCode))
2119void InstrLowerer::emitInitialization() {
2136 F->addFnAttr(Attribute::NoInline);
2138 F->addFnAttr(Attribute::NoRedZone);
2142 IRB.CreateCall(RegisterF, {});
2143 IRB.CreateRetVoid();
2154 if (getSampledInstrumentationConfig().UseShort) {
2164 SamplingVar->setThreadLocal(
true);
2165 Triple TT(M.getTargetTriple());
2166 if (TT.supportsCOMDAT()) {
2168 SamplingVar->setComdat(M.getOrInsertComdat(VarName));
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< 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...
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 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
std::unordered_set< BasicBlock * > 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...
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
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)
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...
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
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.
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 value 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
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)
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.
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 * 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())
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
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)
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
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)
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
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.
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...
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(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type 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.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - 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
size - Get the string size.
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 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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
@ 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.
@ 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)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
FunctionAddr NumBitmapBytes
StringRef getInstrProfNameVarPrefix()
Return the name prefix of variables containing instrumented function names.
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Int32Ty
LLVM_ABI void createProfileSamplingVar(Module &M)
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.
FunctionAddr Int16ArrayTy
StringRef getInstrProfVTableNamesVarName()
StringRef getInstrProfDataVarPrefix()
Return the name prefix of variables containing per-function control data.
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.
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
FunctionAddr VTableAddr Count
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...
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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)
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)
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."))
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.