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());
196 if (AtomicCounterUpdatePromoted)
201 AtomicOrdering::SequentiallyConsistent);
204 auto *NewVal =
Builder.CreateAdd(OldVal, LiveInValue);
205 auto *NewStore =
Builder.CreateStore(NewVal,
Addr);
208 if (IterativeCounterPromotion) {
209 auto *TargetLoop = LI.getLoopFor(ExitBlock);
211 LoopToCandidates[TargetLoop].emplace_back(OldVal, NewStore);
228class PGOCounterPromoter {
233 : LoopToCandidates(LoopToCands),
L(CurLoop), LI(LI),
BFI(
BFI) {
240 L.getExitBlocks(LoopExitBlocks);
241 if (!isPromotionPossible(&L, LoopExitBlocks))
244 for (
BasicBlock *ExitBlock : LoopExitBlocks) {
245 if (BlockSet.
insert(ExitBlock).second) {
246 ExitBlocks.push_back(ExitBlock);
252 bool run(int64_t *NumPromoted) {
254 if (ExitBlocks.size() == 0)
262 if (SkipRetExitBlock) {
263 for (
auto *BB : ExitBlocks)
264 if (isa<ReturnInst>(BB->getTerminator()))
268 unsigned MaxProm = getMaxNumOfPromotionsInLoop(&L);
272 unsigned Promoted = 0;
273 for (
auto &Cand : LoopToCandidates[&L]) {
281 auto *BB = Cand.first->getParent();
285 auto PreheaderCount =
BFI->getBlockProfileCount(
L.getLoopPreheader());
288 if (PreheaderCount && (*PreheaderCount * 3) >= (*
InstrCount * 2))
292 PGOCounterPromoterHelper Promoter(Cand.first, Cand.second,
SSA, InitVal,
293 L.getLoopPreheader(), ExitBlocks,
294 InsertPts, LoopToCandidates, LI);
297 if (Promoted >= MaxProm)
301 if (MaxNumOfPromotions != -1 && *NumPromoted >= MaxNumOfPromotions)
305 LLVM_DEBUG(
dbgs() << Promoted <<
" counters promoted for loop (depth="
306 <<
L.getLoopDepth() <<
")\n");
307 return Promoted != 0;
311 bool allowSpeculativeCounterPromotion(
Loop *LP) {
313 L.getExitingBlocks(ExitingBlocks);
315 if (ExitingBlocks.
size() == 1)
317 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
325 isPromotionPossible(
Loop *LP,
344 unsigned getMaxNumOfPromotionsInLoop(
Loop *LP) {
347 if (!isPromotionPossible(LP, LoopExitBlocks))
358 if (ExitingBlocks.
size() == 1)
359 return MaxNumOfPromotionsPerLoop;
361 if (ExitingBlocks.
size() > SpeculativeCounterPromotionMaxExiting)
365 if (SpeculativeCounterPromotionToLoop)
366 return MaxNumOfPromotionsPerLoop;
369 unsigned MaxProm = MaxNumOfPromotionsPerLoop;
370 for (
auto *TargetBlock : LoopExitBlocks) {
371 auto *TargetLoop = LI.
getLoopFor(TargetBlock);
374 unsigned MaxPromForTarget = getMaxNumOfPromotionsInLoop(TargetLoop);
375 unsigned PendingCandsInTarget = LoopToCandidates[TargetLoop].size();
377 std::min(MaxProm, std::max(MaxPromForTarget, PendingCandsInTarget) -
378 PendingCandsInTarget);
391enum class ValueProfilingCallType {
414bool InstrProfiling::lowerIntrinsics(
Function *
F) {
415 bool MadeChange =
false;
416 PromotionCandidates.clear();
419 if (
auto *IPIS = dyn_cast<InstrProfIncrementInstStep>(&Instr)) {
420 lowerIncrement(IPIS);
422 }
else if (
auto *IPI = dyn_cast<InstrProfIncrementInst>(&Instr)) {
425 }
else if (
auto *IPC = dyn_cast<InstrProfTimestampInst>(&Instr)) {
428 }
else if (
auto *IPC = dyn_cast<InstrProfCoverInst>(&Instr)) {
431 }
else if (
auto *IPVP = dyn_cast<InstrProfValueProfileInst>(&Instr)) {
432 lowerValueProfileInst(IPVP);
441 promoteCounterLoadStores(
F);
445bool InstrProfiling::isRuntimeCounterRelocationEnabled()
const {
450 if (RuntimeCounterRelocation.getNumOccurrences() > 0)
451 return RuntimeCounterRelocation;
457bool InstrProfiling::isCounterPromotionEnabled()
const {
458 if (DoCounterPromotion.getNumOccurrences() > 0)
459 return DoCounterPromotion;
464void InstrProfiling::promoteCounterLoadStores(
Function *
F) {
465 if (!isCounterPromotionEnabled())
472 std::unique_ptr<BlockFrequencyInfo>
BFI;
474 std::unique_ptr<BranchProbabilityInfo> BPI;
479 for (
const auto &LoadStore : PromotionCandidates) {
486 LoopPromotionCandidates[ParentLoop].emplace_back(CounterLoad, CounterStore);
494 PGOCounterPromoter Promoter(LoopPromotionCandidates, *
Loop, LI,
BFI.get());
495 Promoter.run(&TotalCountersPromoted);
501 if (TT.isOSFuchsia())
509 auto containsIntrinsic = [&](
int ID) {
511 return !
F->use_empty();
514 return containsIntrinsic(llvm::Intrinsic::instrprof_cover) ||
515 containsIntrinsic(llvm::Intrinsic::instrprof_increment) ||
516 containsIntrinsic(llvm::Intrinsic::instrprof_increment_step) ||
517 containsIntrinsic(llvm::Intrinsic::instrprof_timestamp) ||
518 containsIntrinsic(llvm::Intrinsic::instrprof_value_profile);
524 this->GetTLI = std::move(GetTLI);
527 ProfileDataMap.clear();
528 CompilerUsedVars.clear();
530 TT =
Triple(M.getTargetTriple());
532 bool MadeChange =
false;
534 if (NeedsRuntimeHook)
535 MadeChange = emitRuntimeHook();
541 if (!ContainsProfiling && !CoverageNamesVar)
551 if (
auto *Ind = dyn_cast<InstrProfValueProfileInst>(
I))
552 computeNumValueSiteCounts(Ind);
553 else if (FirstProfInst ==
nullptr &&
554 (isa<InstrProfIncrementInst>(
I) || isa<InstrProfCoverInst>(
I)))
555 FirstProfInst = dyn_cast<InstrProfInstBase>(
I);
559 if (FirstProfInst !=
nullptr)
560 static_cast<void>(getOrCreateRegionCounters(FirstProfInst));
564 MadeChange |= lowerIntrinsics(&
F);
566 if (CoverageNamesVar) {
567 lowerCoverageData(CoverageNamesVar);
581 if (!NeedsRuntimeHook && ContainsProfiling)
586 emitInitialization();
592 ValueProfilingCallType CallType = ValueProfilingCallType::Default) {
597 if (
auto AK = TLI.getExtAttrForI32Param(
false))
598 AL = AL.addParamAttribute(M.getContext(), 2, AK);
600 assert((CallType == ValueProfilingCallType::Default ||
601 CallType == ValueProfilingCallType::MemOp) &&
602 "Must be Default or MemOp");
603 Type *ParamTypes[] = {
604#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
607 auto *ValueProfilingCallTy =
609 StringRef FuncName = CallType == ValueProfilingCallType::Default
612 return M.getOrInsertFunction(FuncName, ValueProfilingCallTy, AL);
619 auto &
PD = ProfileDataMap[
Name];
630 "Value profiling is not yet supported with lightweight instrumentation");
632 auto It = ProfileDataMap.find(
Name);
633 assert(It != ProfileDataMap.end() && It->second.DataVar &&
634 "value profiling detected in function with no counter incerement");
640 Index += It->second.NumValueSites[Kind];
644 llvm::InstrProfValueKind::IPVK_MemOPSize);
668 if (
auto AK = TLI->getExtAttrForI32Param(
false))
669 Call->addParamAttr(2, AK);
675 auto *Counters = getOrCreateRegionCounters(
I);
678 if (isa<InstrProfTimestampInst>(
I))
679 Counters->setAlignment(
Align(8));
682 Counters->getValueType(), Counters, 0,
I->getIndex()->getZExtValue());
684 if (!isRuntimeCounterRelocationEnabled())
688 Function *Fn =
I->getParent()->getParent();
689 LoadInst *&BiasLI = FunctionToProfileBiasMap[Fn];
706 Bias->setComdat(
M->getOrInsertComdat(Bias->getName()));
708 BiasLI = EntryBuilder.CreateLoad(Int64Ty, Bias);
715 auto *
Addr = getCounterAddress(CoverInstruction);
722void InstrProfiling::lowerTimestamp(
725 "timestamp probes are always the first probe for a function");
726 auto &Ctx =
M->getContext();
727 auto *TimestampAddr = getCounterAddress(TimestampInstruction);
731 auto Callee =
M->getOrInsertFunction(
732 INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_SET_TIMESTAMP), CalleeTy);
733 Builder.CreateCall(Callee, {TimestampAddr});
738 auto *
Addr = getCounterAddress(Inc);
741 if (Options.
Atomic || AtomicCounterUpdateAll ||
750 if (isCounterPromotionEnabled())
751 PromotionCandidates.emplace_back(cast<Instruction>(Load), Store);
756void InstrProfiling::lowerCoverageData(
GlobalVariable *CoverageNamesVar) {
762 assert(isa<GlobalVariable>(V) &&
"Missing reference to function name");
766 ReferencedNames.push_back(
Name);
767 if (isa<ConstantExpr>(
NC))
768 NC->dropAllReferences();
776 for (
auto *NameVar: ReferencedNames) {
777 Metadata *CovFunctionNameAnnotation[] = {
785 auto *DICovName =
DB.createGlobalVariableExpression(
788 0,
DB.createUnspecifiedType(
"Coverage Type"),
794 ReferencedNames.clear();
811 return (Prefix +
Name).str();
817 return (Prefix +
Name).str();
818 return (Prefix +
Name +
"." +
Twine(FuncHash)).str();
822 auto *MD = dyn_cast_or_null<ConstantAsMetadata>(M.getModuleFlag(Flag));
828 return cast<ConstantInt>(MD->getValue())->getZExtValue();
850 bool HasAvailableExternallyLinkage =
F->hasAvailableExternallyLinkage();
851 if (!
F->hasLinkOnceLinkage() && !
F->hasLocalLinkage() &&
852 !HasAvailableExternallyLinkage)
858 if (HasAvailableExternallyLinkage &&
859 F->hasFnAttribute(Attribute::AlwaysInline))
865 if (
F->hasLocalLinkage() &&
F->hasComdat())
875 return F->hasAddressTaken() ||
F->hasLinkOnceLinkage();
949 if (TT.isOSAIX() || TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
950 TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS() || TT.isOSWindows())
960 auto &Ctx =
M->getContext();
962 if (isa<InstrProfCoverInst>(Inc)) {
966 std::vector<Constant *> InitialValues(NumCounters,
984 auto &
PD = ProfileDataMap[NamePtr];
985 if (
PD.RegionCounters)
986 return PD.RegionCounters;
1028 std::string CntsVarName =
1030 std::string DataVarName =
1038 Comdat *
C =
M->getOrInsertComdat(GroupName);
1053 auto *CounterPtr = createRegionCounters(Inc, CntsVarName, Linkage);
1054 CounterPtr->setVisibility(Visibility);
1055 CounterPtr->setSection(
1057 CounterPtr->setLinkage(Linkage);
1058 MaybeSetComdat(CounterPtr);
1059 PD.RegionCounters = CounterPtr;
1063 Metadata *FunctionNameAnnotation[] = {
1071 Metadata *NumCountersAnnotation[] = {
1080 auto *DICounter =
DB.createGlobalVariableExpression(
1081 SP, CounterPtr->getName(),
StringRef(), SP->getFile(),
1082 0,
DB.createUnspecifiedType(
"Profile Data Type"),
1083 CounterPtr->hasLocalLinkage(),
true,
nullptr,
1084 nullptr,
nullptr, 0,
1086 CounterPtr->addDebugInfo(DICounter);
1097 NS +=
PD.NumValueSites[Kind];
1098 if (NS > 0 && ValueProfileStaticAlloc &&
1104 ValuesVar->setVisibility(Visibility);
1105 ValuesVar->setSection(
1107 ValuesVar->setAlignment(
Align(8));
1108 MaybeSetComdat(ValuesVar);
1115 CompilerUsedVars.push_back(
PD.RegionCounters);
1116 return PD.RegionCounters;
1120 auto *IntPtrTy =
M->getDataLayout().getIntPtrType(
M->getContext());
1123 Type *DataTypes[] = {
1124#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) LLVMType,
1131 Constant *Int16ArrayVals[IPVK_Last + 1];
1146 if (NS == 0 && !(DataReferencedByCode && NeedComdat && !Renamed) &&
1153 new GlobalVariable(*M, DataTy,
false, Linkage,
nullptr, DataVarName);
1156 auto *RelativeCounterPtr =
1161#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
1166 Data->setVisibility(Visibility);
1168 Data->setAlignment(
Align(INSTR_PROF_DATA_ALIGNMENT));
1169 MaybeSetComdat(
Data);
1174 CompilerUsedVars.push_back(
Data);
1180 ReferencedNames.push_back(NamePtr);
1182 return PD.RegionCounters;
1185void InstrProfiling::emitVNodes() {
1186 if (!ValueProfileStaticAlloc)
1196 for (
auto &PD : ProfileDataMap) {
1198 TotalNS +=
PD.second.NumValueSites[Kind];
1204 uint64_t NumCounters = TotalNS * NumCountersPerValueSite;
1212#define INSTR_PROF_MIN_VAL_COUNTS 10
1216 auto &Ctx =
M->getContext();
1217 Type *VNodeTypes[] = {
1218#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init) LLVMType,
1227 VNodesVar->setSection(
1229 VNodesVar->setAlignment(
M->getDataLayout().getABITypeAlign(VNodesTy));
1232 UsedVars.push_back(VNodesVar);
1235void InstrProfiling::emitNameData() {
1236 std::string UncompressedData;
1238 if (ReferencedNames.empty())
1241 std::string CompressedNameStr;
1247 auto &Ctx =
M->getContext();
1253 NamesSize = CompressedNameStr.size();
1262 UsedVars.push_back(NamesVar);
1264 for (
auto *NamePtr : ReferencedNames)
1268void InstrProfiling::emitRegistration() {
1281 RegisterF->addFnAttr(Attribute::NoRedZone);
1284 auto *RuntimeRegisterF =
1290 if (!isa<Function>(
Data))
1291 IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(
Data, VoidPtrTy));
1293 if (
Data != NamesVar && !isa<Function>(
Data))
1294 IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(
Data, VoidPtrTy));
1297 Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
1298 auto *NamesRegisterTy =
1300 auto *NamesRegisterF =
1303 IRB.CreateCall(NamesRegisterF, {IRB.CreateBitCast(NamesVar, VoidPtrTy),
1304 IRB.getInt64(NamesSize)});
1307 IRB.CreateRetVoid();
1310bool InstrProfiling::emitRuntimeHook() {
1329 CompilerUsedVars.push_back(Var);
1335 User->addFnAttr(Attribute::NoInline);
1337 User->addFnAttr(Attribute::NoRedZone);
1344 IRB.CreateRet(Load);
1347 CompilerUsedVars.push_back(
User);
1352void InstrProfiling::emitUses() {
1374void InstrProfiling::emitInitialization() {
1391 F->addFnAttr(Attribute::NoInline);
1393 F->addFnAttr(Attribute::NoRedZone);
1397 IRB.CreateCall(RegisterF, {});
1398 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.
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.
void addDebugInfo(DIGlobalVariableExpression *GV)
Attach a DIGlobalVariableExpression.
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 * CovFunctionNameAttributeName
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.timestamp intrinsic.
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.
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...
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).
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.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt16Ty(LLVMContext &C)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
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.
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.