59#define DEBUG_TYPE "instrprof"
64 cl::desc(
"Use debug info to correlate profiles."),
71 "hash-based-counter-split",
72 cl::desc(
"Rename counter variable of a comdat function based on cfg hash"),
76 RuntimeCounterRelocation(
"runtime-counter-relocation",
77 cl::desc(
"Enable relocating counters at runtime."),
82 cl::desc(
"Do static counter allocation for value profiler"),
86 "vp-counters-per-site",
87 cl::desc(
"The average number of profile counters allocated "
88 "per value profiling site."),
96 "instrprof-atomic-counter-update-all",
97 cl::desc(
"Make all profile counter updates atomic (for testing only)"),
101 "atomic-counter-update-promoted",
102 cl::desc(
"Do counter update using atomic fetch add "
103 " for promoted counters only"),
107 "atomic-first-counter",
108 cl::desc(
"Use atomic fetch add for first counter in a function (usually "
109 "the entry counter)"),
118 cl::desc(
"Do counter register promotion"),
121 "max-counter-promotions-per-loop",
cl::init(20),
122 cl::desc(
"Max number counter promotions per loop to avoid"
123 " increasing register pressure too much"));
127 MaxNumOfPromotions(
"max-counter-promotions",
cl::init(-1),
128 cl::desc(
"Max number of allowed counter promotions"));
131 "speculative-counter-promotion-max-exiting",
cl::init(3),
132 cl::desc(
"The max number of exiting blocks of a loop to allow "
133 " speculative counter promotion"));
136 "speculative-counter-promotion-to-loop",
137 cl::desc(
"When the option is false, if the target block is in a loop, "
138 "the promotion will be disallowed unless the promoted counter "
139 " update can be further/iteratively promoted into an acyclic "
143 "iterative-counter-promotion",
cl::init(
true),
144 cl::desc(
"Allow counter promotion across the whole loop nest."));
147 "skip-ret-exit-block",
cl::init(
true),
148 cl::desc(
"Suppress counter promotion if exit blocks contain ret."));
159 PGOCounterPromoterHelper(
166 InsertPts(InsertPts), LoopToCandidates(LoopToCands), LI(LI) {
168 assert(isa<StoreInst>(S));
169 SSA.AddAvailableValue(PH,
Init);
173 for (
unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
179 Value *LiveInValue =
SSA.GetValueInMiddleOfBlock(ExitBlock);
180 Value *
Addr = cast<StoreInst>(Store)->getPointerOperand();
183 if (
auto *AddrInst = dyn_cast_or_null<IntToPtrInst>(
Addr)) {
190 auto *OrigBiasInst = dyn_cast<BinaryOperator>(AddrInst->getOperand(0));
191 assert(OrigBiasInst->getOpcode() == Instruction::BinaryOps::Add);
192 Value *BiasInst =
Builder.Insert(OrigBiasInst->clone());
195 if (AtomicCounterUpdatePromoted)
200 AtomicOrdering::SequentiallyConsistent);
203 auto *NewVal =
Builder.CreateAdd(OldVal, LiveInValue);
204 auto *NewStore =
Builder.CreateStore(NewVal,
Addr);
207 if (IterativeCounterPromotion) {
208 auto *TargetLoop = LI.getLoopFor(ExitBlock);
210 LoopToCandidates[TargetLoop].emplace_back(OldVal, NewStore);
227class PGOCounterPromoter {
232 : LoopToCandidates(LoopToCands),
L(CurLoop), LI(LI),
BFI(
BFI) {
239 L.getExitBlocks(LoopExitBlocks);
240 if (!isPromotionPossible(&L, LoopExitBlocks))
243 for (
BasicBlock *ExitBlock : LoopExitBlocks) {
244 if (BlockSet.
insert(ExitBlock).second) {
245 ExitBlocks.push_back(ExitBlock);
251 bool run(int64_t *NumPromoted) {
253 if (ExitBlocks.size() == 0)
261 if (SkipRetExitBlock) {
262 for (
auto *BB : ExitBlocks)
263 if (isa<ReturnInst>(BB->getTerminator()))
267 unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
271 unsigned Promoted = 0;
272 for (
auto &Cand : LoopToCandidates[&L]) {
280 auto *BB = Cand.first->getParent();
284 auto PreheaderCount =
BFI->getBlockProfileCount(
L.getLoopPreheader());
287 if (PreheaderCount && (*PreheaderCount * 3) >= (*
InstrCount * 2))
291 PGOCounterPromoterHelper Promoter(Cand.first, Cand.second,
SSA, InitVal,
292 L.getLoopPreheader(), ExitBlocks,
293 InsertPts, LoopToCandidates, LI);
296 if (Promoted >= MaxProm)
300 if (MaxNumOfPromotions != -1 && *NumPromoted >= MaxNumOfPromotions)
304 LLVM_DEBUG(
dbgs() << Promoted <<
" counters promoted for loop (depth="
305 <<
L.getLoopDepth() <<
")\n");
306 return Promoted != 0;
310 bool allowSpeculativeCounterPromotion(
Loop *LP) {
312 L.getExitingBlocks(ExitingBlocks);
314 if (ExitingBlocks.
size() == 1)
316 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
324 isPromotionPossible(
Loop *LP,
343 unsigned getMaxNumOfPromotionsInLoop(
Loop *LP) {
346 if (!isPromotionPossible(LP, LoopExitBlocks))
357 if (ExitingBlocks.
size() == 1)
358 return MaxNumOfPromotionsPerLoop;
360 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
364 if (SpeculativeCounterPromotionToLoop)
365 return MaxNumOfPromotionsPerLoop;
368 unsigned MaxProm = MaxNumOfPromotionsPerLoop;
369 for (
auto *TargetBlock : LoopExitBlocks) {
370 auto *TargetLoop = LI.
getLoopFor(TargetBlock);
373 unsigned MaxPromForTarget = getMaxNumOfPromotionsInLoop(TargetLoop);
374 unsigned PendingCandsInTarget = LoopToCandidates[TargetLoop].size();
376 std::min(MaxProm, std::max(MaxPromForTarget, PendingCandsInTarget) -
377 PendingCandsInTarget);
390enum class ValueProfilingCallType {
413bool InstrProfiling::lowerIntrinsics(
Function *
F) {
414 bool MadeChange =
false;
415 PromotionCandidates.clear();
418 if (
auto *IPIS = dyn_cast<InstrProfIncrementInstStep>(&Instr)) {
419 lowerIncrement(IPIS);
421 }
else if (
auto *IPI = dyn_cast<InstrProfIncrementInst>(&Instr)) {
424 }
else if (
auto *IPC = dyn_cast<InstrProfCoverInst>(&Instr)) {
427 }
else if (
auto *IPVP = dyn_cast<InstrProfValueProfileInst>(&Instr)) {
428 lowerValueProfileInst(IPVP);
437 promoteCounterLoadStores(
F);
441bool InstrProfiling::isRuntimeCounterRelocationEnabled()
const {
446 if (RuntimeCounterRelocation.getNumOccurrences() > 0)
447 return RuntimeCounterRelocation;
453bool InstrProfiling::isCounterPromotionEnabled()
const {
454 if (DoCounterPromotion.getNumOccurrences() > 0)
455 return DoCounterPromotion;
460void InstrProfiling::promoteCounterLoadStores(
Function *
F) {
461 if (!isCounterPromotionEnabled())
468 std::unique_ptr<BlockFrequencyInfo>
BFI;
470 std::unique_ptr<BranchProbabilityInfo> BPI;
475 for (
const auto &LoadStore : PromotionCandidates) {
482 LoopPromotionCandidates[ParentLoop].emplace_back(CounterLoad, CounterStore);
490 PGOCounterPromoter Promoter(LoopPromotionCandidates, *
Loop, LI,
BFI.get());
491 Promoter.run(&TotalCountersPromoted);
497 if (TT.isOSFuchsia())
505 auto containsIntrinsic = [&](
int ID) {
507 return !
F->use_empty();
510 return containsIntrinsic(llvm::Intrinsic::instrprof_cover) ||
511 containsIntrinsic(llvm::Intrinsic::instrprof_increment) ||
512 containsIntrinsic(llvm::Intrinsic::instrprof_increment_step) ||
513 containsIntrinsic(llvm::Intrinsic::instrprof_value_profile);
519 this->GetTLI = std::move(GetTLI);
522 ProfileDataMap.clear();
523 CompilerUsedVars.clear();
525 TT =
Triple(M.getTargetTriple());
527 bool MadeChange =
false;
529 if (NeedsRuntimeHook)
530 MadeChange = emitRuntimeHook();
536 if (!ContainsProfiling && !CoverageNamesVar)
546 if (
auto *Ind = dyn_cast<InstrProfValueProfileInst>(
I))
547 computeNumValueSiteCounts(Ind);
548 else if (FirstProfIncInst ==
nullptr)
549 FirstProfIncInst = dyn_cast<InstrProfIncrementInst>(
I);
553 if (FirstProfIncInst !=
nullptr)
554 static_cast<void>(getOrCreateRegionCounters(FirstProfIncInst));
558 MadeChange |= lowerIntrinsics(&
F);
560 if (CoverageNamesVar) {
561 lowerCoverageData(CoverageNamesVar);
575 if (!NeedsRuntimeHook && ContainsProfiling)
580 emitInitialization();
586 ValueProfilingCallType CallType = ValueProfilingCallType::Default) {
591 if (
auto AK = TLI.getExtAttrForI32Param(
false))
592 AL = AL.addParamAttribute(M.getContext(), 2, AK);
594 assert((CallType == ValueProfilingCallType::Default ||
595 CallType == ValueProfilingCallType::MemOp) &&
596 "Must be Default or MemOp");
597 Type *ParamTypes[] = {
598#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
601 auto *ValueProfilingCallTy =
603 StringRef FuncName = CallType == ValueProfilingCallType::Default
606 return M.getOrInsertFunction(FuncName, ValueProfilingCallTy, AL);
613 auto &
PD = ProfileDataMap[
Name];
624 "Value profiling is not yet supported with lightweight instrumentation");
626 auto It = ProfileDataMap.find(
Name);
627 assert(It != ProfileDataMap.end() && It->second.DataVar &&
628 "value profiling detected in function with no counter incerement");
634 Index += It->second.NumValueSites[Kind];
638 llvm::InstrProfValueKind::IPVK_MemOPSize);
662 if (
auto AK = TLI->getExtAttrForI32Param(
false))
663 Call->addParamAttr(2, AK);
669 auto *Counters = getOrCreateRegionCounters(
I);
673 Counters->getValueType(), Counters, 0,
I->getIndex()->getZExtValue());
675 if (!isRuntimeCounterRelocationEnabled())
679 Function *Fn =
I->getParent()->getParent();
680 LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
697 Bias->setComdat(
M->getOrInsertComdat(Bias->getName()));
699 BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias);
706 auto *
Addr = getCounterAddress(CoverInstruction);
714 auto *
Addr = getCounterAddress(Inc);
717 if (Options.
Atomic || AtomicCounterUpdateAll ||
726 if (isCounterPromotionEnabled())
727 PromotionCandidates.emplace_back(cast<Instruction>(Load), Store);
732void InstrProfiling::lowerCoverageData(
GlobalVariable *CoverageNamesVar) {
735 for (
unsigned I = 0,
E =
Names->getNumOperands();
I <
E; ++
I) {
738 assert(isa<GlobalVariable>(V) &&
"Missing reference to function name");
742 ReferencedNames.push_back(
Name);
743 if (isa<ConstantExpr>(
NC))
744 NC->dropAllReferences();
759 return (Prefix +
Name).str();
765 return (Prefix +
Name).str();
766 return (Prefix +
Name +
"." +
Twine(FuncHash)).str();
770 auto *MD = dyn_cast_or_null<ConstantAsMetadata>(M.getModuleFlag(Flag));
776 return cast<ConstantInt>(MD->getValue())->getZExtValue();
798 bool HasAvailableExternallyLinkage =
F->hasAvailableExternallyLinkage();
799 if (!
F->hasLinkOnceLinkage() && !
F->hasLocalLinkage() &&
800 !HasAvailableExternallyLinkage)
806 if (HasAvailableExternallyLinkage &&
807 F->hasFnAttribute(Attribute::AlwaysInline))
813 if (
F->hasLocalLinkage() &&
F->hasComdat())
823 return F->hasAddressTaken() ||
F->hasLinkOnceLinkage();
897 if (TT.isOSAIX() || TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
898 TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS() || TT.isOSWindows())
908 auto &Ctx =
M->getContext();
910 if (isa<InstrProfCoverInst>(Inc)) {
914 std::vector<Constant *> InitialValues(NumCounters,
932 auto &
PD = ProfileDataMap[NamePtr];
933 if (
PD.RegionCounters)
934 return PD.RegionCounters;
976 std::string CntsVarName =
978 std::string DataVarName =
986 Comdat *
C =
M->getOrInsertComdat(GroupName);
1001 auto *CounterPtr = createRegionCounters(Inc, CntsVarName, Linkage);
1002 CounterPtr->setVisibility(Visibility);
1003 CounterPtr->setSection(
1005 CounterPtr->setLinkage(Linkage);
1006 MaybeSetComdat(CounterPtr);
1007 PD.RegionCounters = CounterPtr;
1011 Metadata *FunctionNameAnnotation[] = {
1019 Metadata *NumCountersAnnotation[] = {
1028 auto *DICounter =
DB.createGlobalVariableExpression(
1029 SP, CounterPtr->getName(),
StringRef(), SP->getFile(),
1030 0,
DB.createUnspecifiedType(
"Profile Data Type"),
1031 CounterPtr->hasLocalLinkage(),
true,
nullptr,
1032 nullptr,
nullptr, 0,
1034 CounterPtr->addDebugInfo(DICounter);
1037 std::string
Msg = (
"Missing debug info for function " + Fn->
getName() +
1038 "; required for profile correlation.")
1051 NS +=
PD.NumValueSites[Kind];
1052 if (NS > 0 && ValueProfileStaticAlloc &&
1058 ValuesVar->setVisibility(Visibility);
1059 ValuesVar->setSection(
1061 ValuesVar->setAlignment(
Align(8));
1062 MaybeSetComdat(ValuesVar);
1069 CompilerUsedVars.push_back(
PD.RegionCounters);
1070 return PD.RegionCounters;
1074 auto *IntPtrTy =
M->getDataLayout().getIntPtrType(
M->getContext());
1077 Type *DataTypes[] = {
1078#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) LLVMType,
1085 Constant *Int16ArrayVals[IPVK_Last + 1];
1100 if (NS == 0 && !(DataReferencedByCode && NeedComdat && !Renamed) &&
1107 new GlobalVariable(*M, DataTy,
false, Linkage,
nullptr, DataVarName);
1110 auto *RelativeCounterPtr =
1115#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
1120 Data->setVisibility(Visibility);
1122 Data->setAlignment(
Align(INSTR_PROF_DATA_ALIGNMENT));
1123 MaybeSetComdat(
Data);
1128 CompilerUsedVars.push_back(
Data);
1134 ReferencedNames.push_back(NamePtr);
1136 return PD.RegionCounters;
1139void InstrProfiling::emitVNodes() {
1140 if (!ValueProfileStaticAlloc)
1150 for (
auto &PD : ProfileDataMap) {
1152 TotalNS +=
PD.second.NumValueSites[Kind];
1158 uint64_t NumCounters = TotalNS * NumCountersPerValueSite;
1166#define INSTR_PROF_MIN_VAL_COUNTS 10
1170 auto &Ctx =
M->getContext();
1171 Type *VNodeTypes[] = {
1172#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init) LLVMType,
1181 VNodesVar->setSection(
1183 VNodesVar->setAlignment(
M->getDataLayout().getABITypeAlign(VNodesTy));
1186 UsedVars.push_back(VNodesVar);
1189void InstrProfiling::emitNameData() {
1190 std::string UncompressedData;
1192 if (ReferencedNames.empty())
1195 std::string CompressedNameStr;
1201 auto &Ctx =
M->getContext();
1207 NamesSize = CompressedNameStr.size();
1216 UsedVars.push_back(NamesVar);
1218 for (
auto *NamePtr : ReferencedNames)
1222void InstrProfiling::emitRegistration() {
1235 RegisterF->addFnAttr(Attribute::NoRedZone);
1238 auto *RuntimeRegisterF =
1244 if (!isa<Function>(
Data))
1245 IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(
Data, VoidPtrTy));
1247 if (
Data != NamesVar && !isa<Function>(
Data))
1248 IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(
Data, VoidPtrTy));
1251 Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
1252 auto *NamesRegisterTy =
1254 auto *NamesRegisterF =
1257 IRB.CreateCall(NamesRegisterF, {IRB.CreateBitCast(NamesVar, VoidPtrTy),
1258 IRB.getInt64(NamesSize)});
1261 IRB.CreateRetVoid();
1264bool InstrProfiling::emitRuntimeHook() {
1283 CompilerUsedVars.push_back(Var);
1289 User->addFnAttr(Attribute::NoInline);
1291 User->addFnAttr(Attribute::NoRedZone);
1298 IRB.CreateRet(Load);
1301 CompilerUsedVars.push_back(
User);
1306void InstrProfiling::emitUses() {
1328void InstrProfiling::emitInitialization() {
1345 F->addFnAttr(Attribute::NoInline);
1347 F->addFnAttr(Attribute::NoRedZone);
1351 IRB.CreateCall(RegisterF, {});
1352 IRB.CreateRetVoid();
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static unsigned InstrCount
static bool enablesValueProfiling(const Module &M)
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 uint64_t getIntModuleFlagOrZero(const Module &M, StringRef Flag)
static bool profDataReferencedByCode(const Module &M)
static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT)
This file provides the interface for LLVM's PGO Instrumentation lowering pass.
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
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:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static 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.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Instruction & front() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
This class represents a function call, abstracting a target machine's calling convention.
@ NoDeduplicate
No deduplication is performed.
ConstantArray - Constant Array Declarations.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getAllOnesValue(Type *Ty)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool isZeroValue() const
Return true if the value is negative zero or null value.
Diagnostic information for the PGO profiler.
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 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.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
static 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.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setComdat(Comdat *C)
void setSection(StringRef S)
Change the section for this global.
VisibilityTypes getVisibility() const
LinkageTypes getLinkage() const
bool hasLocalLinkage() const
bool hasPrivateLinkage() const
void setLinkage(LinkageTypes LT)
bool isDeclarationForLinker() const
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
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.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
static const char * FunctionNameAttributeName
static const char * CFGHashAttributeName
static const char * NumCountersAttributeName
This represents the llvm.instrprof.cover intrinsic.
This represents the llvm.instrprof.increment intrinsic.
A base class for all instrprof intrinsics.
ConstantInt * getNumCounters() const
GlobalVariable * getName() const
ConstantInt * getHash() const
ConstantInt * getIndex() const
This represents the llvm.instrprof.value.profile intrinsic.
ConstantInt * getIndex() const
Value * getTargetValue() const
ConstantInt * getValueKind() const
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const BasicBlock * getParent() const
const Function * getFunction() const
Return the function this instruction belongs to.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
This is an important class for using LLVM in a threaded context.
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
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.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDString * get(LLVMContext &Context, StringRef Str)
A Module instance is used to store all the information related to an LLVM module.
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.
Helper class for SSA formation on a set of values defined in multiple blocks.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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).
constexpr size_t size() const
size - Get the string size.
static 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.
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
bool supportsCOMDAT() const
Tests whether the target supports comdat.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
bool isOSLinux() const
Tests whether the OS is Linux.
bool isOSAIX() const
Tests whether the OS is AIX.
bool isPS() const
Tests whether the target is the PS4 or PS5 platform.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
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.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt16Ty(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
const CustomOperand< const MCSubtargetInfo & > Msg[]
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
initializer< Ty > init(const Ty &Val)
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
This is an optimization pass for GlobalISel generic memory operations.
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.
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...
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...
std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
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 ...
StringRef getInstrProfCountersVarPrefix()
Return the name prefix of profile counter variables.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar)
Return the initializer in string of the PGO name var NameVar.
StringRef getInstrProfValueProfMemOpFuncName()
Return the name profile runtime entry point to do memop size value profiling.
StringRef getInstrProfNamesRegFuncName()
Return the name of the runtime interface that registers the PGO name strings.
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
bool needsComdatForCounter(const Function &F, const Module &M)
Check if we can use Comdat for profile variables.
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
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.
Error collectPGOFuncNameStrings(ArrayRef< std::string > NameStrs, bool doCompression, std::string &Result)
Given a vector of strings (function PGO names) NameStrs, the method generates a combined string Resul...
StringRef getInstrProfValueProfFuncName()
Return the name profile runtime entry point to do value profiling for a given site.
StringRef getInstrProfRegFuncName()
Return the name of the runtime interface that registers per-function control data for one instrumente...
cl::opt< bool > DebugInfoCorrelate("debug-info-correlate", cl::desc("Use debug info to correlate profiles."), cl::init(false))
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...
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:
This struct is a compact representation of a valid (non-zero power of two) alignment.
std::string InstrProfileOutput
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.