119 #include <unordered_map> 123 using namespace llvm;
127 #define DEBUG_TYPE "pgo-instrumentation" 129 STATISTIC(NumOfPGOInstrument,
"Number of edges instrumented.");
130 STATISTIC(NumOfPGOSelectInsts,
"Number of select instruction instrumented.");
131 STATISTIC(NumOfPGOMemIntrinsics,
"Number of mem intrinsics instrumented.");
132 STATISTIC(NumOfPGOEdge,
"Number of edges.");
133 STATISTIC(NumOfPGOBB,
"Number of basic-blocks.");
134 STATISTIC(NumOfPGOSplit,
"Number of critical edge splits.");
135 STATISTIC(NumOfPGOFunc,
"Number of functions having valid profile counts.");
136 STATISTIC(NumOfPGOMismatch,
"Number of functions having mismatch profile.");
137 STATISTIC(NumOfPGOMissing,
"Number of functions without profile.");
138 STATISTIC(NumOfPGOICall,
"Number of indirect call value instrumentations.");
139 STATISTIC(NumOfCSPGOInstrument,
"Number of edges instrumented in CSPGO.");
141 "Number of select instruction instrumented in CSPGO.");
143 "Number of mem intrinsics instrumented in CSPGO.");
144 STATISTIC(NumOfCSPGOEdge,
"Number of edges in CSPGO.");
145 STATISTIC(NumOfCSPGOBB,
"Number of basic-blocks in CSPGO.");
146 STATISTIC(NumOfCSPGOSplit,
"Number of critical edge splits in CSPGO.");
148 "Number of functions having valid profile counts in CSPGO.");
150 "Number of functions having mismatch profile in CSPGO.");
151 STATISTIC(NumOfCSPGOMissing,
"Number of functions without profile in CSPGO.");
158 cl::desc(
"Specify the path of profile data file. This is" 159 "mainly for test purpose."));
163 cl::desc(
"Specify the path of profile remapping file. This is mainly for " 170 cl::desc(
"Disable Value Profiling"));
176 cl::desc(
"Max number of annotations for a single indirect " 183 cl::desc(
"Max number of preicise value annotations for a single memop" 190 cl::desc(
"Append function hash to the name of COMDAT function to avoid " 191 "function hash mismatch due to the preinliner"));
197 cl::desc(
"Use this option to turn on/off " 198 "warnings about missing profile data for " 205 cl::desc(
"Use this option to turn off/on " 206 "warnings about profile cfg mismatch."));
214 cl::desc(
"The option is used to turn on/off " 215 "warnings about hash mismatch for comdat " 221 cl::desc(
"Use this option to turn on/off SELECT " 222 "instruction instrumentation. "));
227 cl::desc(
"A boolean option to show CFG dag or text " 228 "with raw profile counts from " 229 "profile data. See also option " 230 "-pgo-view-counts. To limit graph " 231 "display to only one function, use " 232 "filtering option -view-bfi-func-name."),
240 cl::desc(
"Use this option to turn on/off " 241 "memory intrinsic size profiling."));
246 cl::desc(
"When this option is on, the annotated " 247 "branch probability will be emitted as " 248 "optimization remarks: -{Rpass|" 249 "pass-remarks}=pgo-instrumentation"));
264 return std::string();
269 return std::string();
281 else if (CV->
isOne())
293 #define VALUE_PROF_KIND(Enumerator, Value, Descr) Descr, 304 enum VisitMode { VM_counting, VM_instrument, VM_annotate };
308 struct SelectInstVisitor :
public InstVisitor<SelectInstVisitor> {
312 unsigned *CurCtrIdx =
nullptr;
313 unsigned TotalNumCtrs = 0;
315 uint64_t FuncHash = 0;
316 PGOUseFunc *UseFunc =
nullptr;
318 SelectInstVisitor(
Function &Func) :
F(Func) {}
330 void instrumentSelects(
Function &Func,
unsigned *Ind,
unsigned TotalNC,
332 Mode = VM_instrument;
334 TotalNumCtrs = TotalNC;
341 void annotateSelects(
Function &Func, PGOUseFunc *UF,
unsigned *Ind) {
356 unsigned getNumOfSelectInsts()
const {
return NSIs; }
360 class PGOInstrumentationGenLegacyPass :
public ModulePass {
364 PGOInstrumentationGenLegacyPass(
bool IsCS =
false)
370 StringRef getPassName()
const override {
return "PGOInstrumentationGenPass"; }
375 bool runOnModule(
Module &M)
override;
382 class PGOInstrumentationUseLegacyPass :
public ModulePass {
387 PGOInstrumentationUseLegacyPass(std::string Filename =
"",
bool IsCS =
false)
388 :
ModulePass(ID), ProfileFileName(std::move(Filename)), IsCS(IsCS) {
395 StringRef getPassName()
const override {
return "PGOInstrumentationUsePass"; }
398 std::string ProfileFileName;
402 bool runOnModule(
Module &M)
override;
410 class PGOInstrumentationGenCreateVarLegacyPass :
public ModulePass {
414 return "PGOInstrumentationGenCreateVarPass";
416 PGOInstrumentationGenCreateVarLegacyPass(std::string CSInstrName =
"")
417 :
ModulePass(ID), InstrProfileOutput(CSInstrName) {
423 bool runOnModule(
Module &M)
override {
428 std::string InstrProfileOutput;
436 "PGO instrumentation.",
false,
false)
443 return new PGOInstrumentationGenLegacyPass(IsCS);
449 "Read PGO instrumentation profile.",
false,
false)
458 return new PGOInstrumentationUseLegacyPass(Filename.str(), IsCS);
464 "pgo-instr-gen-create-var",
465 "Create PGO instrumentation version variable for CSPGO.",
false,
470 return new PGOInstrumentationGenCreateVarLegacyPass(CSInstrName);
486 bool Removed =
false;
487 bool IsCritical =
false;
490 : SrcBB(Src), DestBB(Dest), Weight(
W) {}
493 const std::string infoString()
const {
494 return (
Twine(Removed ?
"-" :
" ") + (InMST ?
" " :
"*") +
495 (IsCritical ?
"c" :
" ") +
" W=" +
Twine(Weight)).str();
505 BBInfo(
unsigned IX) : Group(
this),
Index(IX) {}
508 const std::string infoString()
const {
509 return (
Twine(
"Index=") +
Twine(Index)).str();
516 void addInEdge(PGOEdge *
E LLVM_ATTRIBUTE_UNUSED) {}
520 template <
class Edge,
class BBInfo>
class FuncPGOInstrumentation {
528 std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers;
532 void computeCFGHash();
533 void renameComdatFunction();
536 std::vector<std::vector<VPCandidateInfo>> ValueSites;
537 SelectInstVisitor SIVisitor;
538 std::string FuncName;
542 uint64_t FunctionHash = 0;
549 void getInstrumentBBs(std::vector<BasicBlock *> &InstrumentBBs);
562 void dumpInfo(std::string Str =
"")
const {
564 Twine(FunctionHash) +
"\t" + Str);
567 FuncPGOInstrumentation(
569 std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
572 :
F(Func), IsCS(IsCS), ComdatMembers(ComdatMembers), VPC(Func),
573 ValueSites(IPVK_Last + 1), SIVisitor(Func), MST(F, BPI,
BFI) {
575 SIVisitor.countSelects(Func);
576 ValueSites[IPVK_MemOPSize] = VPC.
get(IPVK_MemOPSize);
578 NumOfPGOSelectInsts += SIVisitor.getNumOfSelectInsts();
579 NumOfPGOMemIntrinsics += ValueSites[IPVK_MemOPSize].size();
580 NumOfPGOBB += MST.
BBInfos.size();
581 ValueSites[IPVK_IndirectCallTarget] = VPC.
get(IPVK_IndirectCallTarget);
583 NumOfCSPGOSelectInsts += SIVisitor.getNumOfSelectInsts();
584 NumOfCSPGOMemIntrinsics += ValueSites[IPVK_MemOPSize].size();
585 NumOfCSPGOBB += MST.
BBInfos.size();
590 if (!ComdatMembers.empty())
591 renameComdatFunction();
597 IsCS ? NumOfCSPGOEdge++ : NumOfPGOEdge++;
599 IsCS ? NumOfCSPGOInstrument++ : NumOfPGOInstrument++;
611 template <
class Edge,
class BBInfo>
612 void FuncPGOInstrumentation<Edge, BBInfo>::computeCFGHash() {
613 std::vector<uint8_t> Indexes;
619 auto BI = findBBInfo(Succ);
623 for (
int J = 0; J < 4; J++)
624 Indexes.push_back((uint8_t)(Index >> (J * 8)));
631 FunctionHash = (uint64_t)SIVisitor.getNumOfSelectInsts() << 56 |
632 (uint64_t)ValueSites[IPVK_IndirectCallTarget].
size() << 48 |
634 (uint64_t)MST.AllEdges.size() << 32 | JC.
getCRC();
636 FunctionHash &= 0x0FFFFFFFFFFFFFFF;
639 LLVM_DEBUG(
dbgs() <<
"Function Hash Computation for " << F.getName() <<
":\n" 640 <<
" CRC = " << JC.
getCRC()
641 <<
", Selects = " << SIVisitor.getNumOfSelectInsts()
642 <<
", Edges = " << MST.AllEdges.size() <<
", ICSites = " 643 << ValueSites[IPVK_IndirectCallTarget].size()
644 <<
", Hash = " << FunctionHash <<
"\n";);
650 std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers) {
662 for (
auto &&CM :
make_range(ComdatMembers.equal_range(C))) {
663 if (dyn_cast<GlobalAlias>(CM.second))
673 template <
class Edge,
class BBInfo>
674 void FuncPGOInstrumentation<Edge, BBInfo>::renameComdatFunction() {
677 std::string OrigName =
F.getName().str();
678 std::string NewFuncName =
679 Twine(
F.getName() +
"." +
Twine(FunctionHash)).str();
680 F.setName(
Twine(NewFuncName));
682 FuncName =
Twine(FuncName +
"." +
Twine(FunctionHash)).
str();
688 if (!
F.hasComdat()) {
692 F.setComdat(NewComdat);
697 Comdat *OrigComdat =
F.getComdat();
698 std::string NewComdatName =
703 for (
auto &&CM :
make_range(ComdatMembers.equal_range(OrigComdat))) {
704 if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(CM.second)) {
706 assert(dyn_cast<Function>(GA->getAliasee()->stripPointerCasts()) == &
F);
707 std::string OrigGAName = GA->getName().str();
708 GA->setName(
Twine(GA->getName() +
"." +
Twine(FunctionHash)));
721 template <
class Edge,
class BBInfo>
722 void FuncPGOInstrumentation<Edge, BBInfo>::getInstrumentBBs(
723 std::vector<BasicBlock *> &InstrumentBBs) {
725 std::vector<Edge *> EdgeList;
726 EdgeList.reserve(MST.AllEdges.size());
727 for (
auto &
E : MST.AllEdges)
728 EdgeList.push_back(
E.get());
730 for (
auto &
E : EdgeList) {
733 InstrumentBBs.push_back(InstrBB);
737 for (
auto &
E : MST.AllEdges) {
742 BBInfo &SrcInfo = getBBInfo(SrcBB);
743 BBInfo &DestInfo = getBBInfo(DestBB);
744 SrcInfo.addOutEdge(
E.get());
745 DestInfo.addInEdge(
E.get());
751 template <
class Edge,
class BBInfo>
752 BasicBlock *FuncPGOInstrumentation<Edge, BBInfo>::getInstrBB(Edge *
E) {
753 if (E->InMST || E->Removed)
759 if (SrcBB ==
nullptr)
761 if (DestBB ==
nullptr)
767 if (BB->getFirstInsertionPt() == BB->end())
776 return canInstrument(SrcBB);
778 return canInstrument(DestBB);
784 dbgs() <<
"Fail to split critical edge: not instrument this edge.\n");
789 IsCS ? NumOfCSPGOSplit++ : NumOfPGOSplit++;
791 <<
" --> " << getBBInfo(DestBB).
Index <<
"\n");
793 MST.addEdge(SrcBB, InstrBB, 0);
795 Edge &NewEdge1 = MST.addEdge(InstrBB, DestBB, 0);
796 NewEdge1.InMST =
true;
799 return canInstrument(InstrBB);
806 std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
812 FuncPGOInstrumentation<PGOEdge, BBInfo> FuncInfo(F, ComdatMembers,
true, BPI,
814 std::vector<BasicBlock *> InstrumentBBs;
815 FuncInfo.getInstrumentBBs(InstrumentBBs);
816 unsigned NumCounters =
817 InstrumentBBs.size() + FuncInfo.SIVisitor.getNumOfSelectInsts();
821 for (
auto *InstrBB : InstrumentBBs) {
822 IRBuilder<> Builder(InstrBB, InstrBB->getFirstInsertionPt());
823 assert(Builder.GetInsertPoint() != InstrBB->end() &&
824 "Cannot get the Instrumentation point");
828 Builder.getInt64(FuncInfo.FunctionHash), Builder.getInt32(NumCounters),
829 Builder.getInt32(I++)});
833 FuncInfo.SIVisitor.instrumentSelects(F, &I, NumCounters, FuncInfo.FuncNameVar,
834 FuncInfo.FunctionHash);
840 NumOfPGOICall += FuncInfo.ValueSites[IPVK_IndirectCallTarget].size();
844 unsigned SiteIndex = 0;
850 <<
" site: CallSite Index = " << SiteIndex <<
"\n");
854 "Cannot get the Instrumentation point");
856 Value *ToProfile =
nullptr;
857 if (Cand.V->getType()->isIntegerTy())
859 else if (Cand.V->getType()->isPointerTy())
861 assert(ToProfile &&
"value profiling Value is of unexpected type");
866 Builder.
getInt64(FuncInfo.FunctionHash), ToProfile,
875 struct PGOUseEdge :
public PGOEdge {
876 bool CountValid =
false;
877 uint64_t CountValue = 0;
880 : PGOEdge(Src, Dest,
W) {}
883 void setEdgeCount(uint64_t
Value) {
889 const std::string infoString()
const {
891 return PGOEdge::infoString();
892 return (
Twine(PGOEdge::infoString()) +
" Count=" +
Twine(CountValue))
900 struct UseBBInfo :
public BBInfo {
901 uint64_t CountValue = 0;
903 int32_t UnknownCountInEdge = 0;
904 int32_t UnknownCountOutEdge = 0;
906 DirectEdges OutEdges;
908 UseBBInfo(
unsigned IX) : BBInfo(IX), CountValid(
false) {}
910 UseBBInfo(
unsigned IX, uint64_t
C)
911 : BBInfo(IX), CountValue(C), CountValid(
true) {}
914 void setBBInfoCount(uint64_t
Value) {
920 const std::string infoString()
const {
922 return BBInfo::infoString();
923 return (
Twine(BBInfo::infoString()) +
" Count=" +
Twine(CountValue)).str();
927 void addOutEdge(PGOUseEdge *E) {
928 OutEdges.push_back(E);
929 UnknownCountOutEdge++;
933 void addInEdge(PGOUseEdge *E) {
934 InEdges.push_back(E);
935 UnknownCountInEdge++;
944 for (
auto &E : Edges) {
947 Total += E->CountValue;
957 std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
960 :
F(Func), M(Modu),
BFI(BFIin), PSI(PSI),
961 FuncInfo(Func, ComdatMembers,
false, BPI, BFIin, IsCS),
962 FreqAttr(FFA_Normal), IsCS(IsCS) {}
968 void populateCounters();
974 void annotateValueSites();
980 void annotateIrrLoopHeaderWeights();
983 enum FuncFreqAttr { FFA_Normal, FFA_Cold, FFA_Hot };
986 FuncFreqAttr getFuncFreqAttr()
const {
return FreqAttr; }
989 uint64_t getFuncHash()
const {
return FuncInfo.FunctionHash; }
995 UseBBInfo &getBBInfo(
const BasicBlock *BB)
const {
996 return FuncInfo.getBBInfo(BB);
1000 UseBBInfo *findBBInfo(
const BasicBlock *BB)
const {
1001 return FuncInfo.findBBInfo(BB);
1006 void dumpInfo(std::string Str =
"")
const {
1007 FuncInfo.dumpInfo(Str);
1010 uint64_t getProgramMaxCount()
const {
return ProgramMaxCount; }
1018 FuncPGOInstrumentation<PGOUseEdge, UseBBInfo> FuncInfo;
1022 uint64_t ProgramMaxCount;
1034 FuncFreqAttr FreqAttr;
1040 bool setInstrumentedCounts(
const std::vector<uint64_t> &CountFromProfile);
1044 void setEdgeCount(DirectEdges &Edges, uint64_t
Value);
1047 const std::string getFuncName()
const {
return FuncInfo.FuncName; }
1052 void markFunctionAttributes(uint64_t EntryCount, uint64_t MaxCount) {
1056 FreqAttr = FFA_Cold;
1064 bool PGOUseFunc::setInstrumentedCounts(
1065 const std::vector<uint64_t> &CountFromProfile) {
1067 std::vector<BasicBlock *> InstrumentBBs;
1068 FuncInfo.getInstrumentBBs(InstrumentBBs);
1069 unsigned NumCounters =
1070 InstrumentBBs.size() + FuncInfo.SIVisitor.getNumOfSelectInsts();
1073 if (NumCounters != CountFromProfile.size()) {
1079 uint64_t CountValue = CountFromProfile[I++];
1080 UseBBInfo &
Info = getBBInfo(InstrBB);
1081 Info.setBBInfoCount(CountValue);
1083 ProfileCountSize = CountFromProfile.size();
1087 auto setEdgeCount = [
this](PGOUseEdge *
E, uint64_t
Value) ->
void {
1088 E->setEdgeCount(
Value);
1089 this->getBBInfo(E->SrcBB).UnknownCountOutEdge--;
1090 this->getBBInfo(E->DestBB).UnknownCountInEdge--;
1096 for (
auto &E : FuncInfo.MST.AllEdges) {
1097 if (E->Removed || E->InMST)
1100 UseBBInfo &SrcInfo = getBBInfo(SrcBB);
1104 if (SrcInfo.CountValid && SrcInfo.OutEdges.size() == 1)
1105 setEdgeCount(E.get(), SrcInfo.CountValue);
1108 UseBBInfo &DestInfo = getBBInfo(DestBB);
1111 if (DestInfo.CountValid && DestInfo.InEdges.size() == 1)
1112 setEdgeCount(E.get(), DestInfo.CountValue);
1118 setEdgeCount(E.get(), 0);
1125 void PGOUseFunc::setEdgeCount(DirectEdges &Edges, uint64_t
Value) {
1126 for (
auto &E : Edges) {
1129 E->setEdgeCount(Value);
1131 getBBInfo(E->SrcBB).UnknownCountOutEdge--;
1132 getBBInfo(E->DestBB).UnknownCountInEdge--;
1142 auto &Ctx = M->getContext();
1147 auto Err = IPE.
get();
1148 bool SkipWarning =
false;
1150 << FuncInfo.FuncName <<
": ");
1152 IsCS ? NumOfCSPGOMissing++ : NumOfPGOMissing++;
1157 IsCS ? NumOfCSPGOMismatch++ : NumOfPGOMismatch++;
1163 LLVM_DEBUG(
dbgs() <<
"hash mismatch (skip=" << SkipWarning <<
")");
1170 std::string Msg = IPE.
message() + std::string(
" ") +
F.getName().str() +
1171 std::string(
" Hash = ") +
1179 ProfileRecord = std::move(Result.
get());
1180 std::vector<uint64_t> &CountFromProfile = ProfileRecord.Counts;
1182 IsCS ? NumOfCSPGOFunc++ : NumOfPGOFunc++;
1184 uint64_t ValueSum = 0;
1185 for (
unsigned I = 0, S = CountFromProfile.size();
I < S;
I++) {
1187 ValueSum += CountFromProfile[
I];
1189 AllZeros = (ValueSum == 0);
1193 getBBInfo(
nullptr).UnknownCountOutEdge = 2;
1194 getBBInfo(
nullptr).UnknownCountInEdge = 2;
1196 if (!setInstrumentedCounts(CountFromProfile)) {
1198 dbgs() <<
"Inconsistent number of counts, skipping this function");
1200 M->getName().data(),
1201 Twine(
"Inconsistent number of counts in ") +
F.getName().str()
1202 +
Twine(
": the profile may be stale or there is a function name collision."),
1212 void PGOUseFunc::populateCounters() {
1213 bool Changes =
true;
1214 unsigned NumPasses = 0;
1222 UseBBInfo *Count = findBBInfo(&BB);
1223 if (Count ==
nullptr)
1225 if (!Count->CountValid) {
1226 if (Count->UnknownCountOutEdge == 0) {
1228 Count->CountValid =
true;
1230 }
else if (Count->UnknownCountInEdge == 0) {
1232 Count->CountValid =
true;
1236 if (Count->CountValid) {
1237 if (Count->UnknownCountOutEdge == 1) {
1243 if (Count->CountValue > OutSum)
1244 Total = Count->CountValue - OutSum;
1245 setEdgeCount(Count->OutEdges, Total);
1248 if (Count->UnknownCountInEdge == 1) {
1251 if (Count->CountValue > InSum)
1252 Total = Count->CountValue - InSum;
1253 setEdgeCount(Count->InEdges, Total);
1260 LLVM_DEBUG(
dbgs() <<
"Populate counts in " << NumPasses <<
" passes.\n");
1263 for (
auto &BB :
F) {
1264 auto BI = findBBInfo(&BB);
1267 assert(BI->CountValid &&
"BB count is not valid");
1270 uint64_t FuncEntryCount = getBBInfo(&*F.begin()).CountValue;
1272 uint64_t FuncMaxCount = FuncEntryCount;
1273 for (
auto &BB : F) {
1274 auto BI = findBBInfo(&BB);
1277 FuncMaxCount =
std::max(FuncMaxCount, BI->CountValue);
1279 markFunctionAttributes(FuncEntryCount, FuncMaxCount);
1282 FuncInfo.SIVisitor.annotateSelects(F,
this, &CountPosition);
1283 assert(CountPosition == ProfileCountSize);
1285 LLVM_DEBUG(FuncInfo.dumpInfo(
"after reading profile."));
1291 LLVM_DEBUG(
dbgs() <<
"\nSetting branch weights for func " <<
F.getName()
1292 <<
" IsCS=" << IsCS <<
"\n");
1293 for (
auto &BB :
F) {
1297 if (!(isa<BranchInst>(TI) || isa<SwitchInst>(TI) ||
1298 isa<IndirectBrInst>(TI)))
1301 if (getBBInfo(&BB).CountValue == 0)
1305 const UseBBInfo &BBCountInfo = getBBInfo(&BB);
1306 unsigned Size = BBCountInfo.OutEdges.size();
1308 uint64_t MaxCount = 0;
1309 for (
unsigned s = 0; s <
Size; s++) {
1310 const PGOUseEdge *E = BBCountInfo.OutEdges[s];
1313 if (DestBB ==
nullptr)
1316 uint64_t EdgeCount = E->CountValue;
1317 if (EdgeCount > MaxCount)
1318 MaxCount = EdgeCount;
1319 EdgeCounts[SuccNum] = EdgeCount;
1327 if (isa<IndirectBrInst>((*PI)->getTerminator()))
1333 void PGOUseFunc::annotateIrrLoopHeaderWeights() {
1334 LLVM_DEBUG(
dbgs() <<
"\nAnnotating irreducible loop header weights.\n");
1336 for (
auto &BB :
F) {
1342 const UseBBInfo &BBCountInfo = getBBInfo(&BB);
1348 void SelectInstVisitor::instrumentOneSelectInst(
SelectInst &
SI) {
1358 Builder.
getInt32(*CurCtrIdx), Step});
1362 void SelectInstVisitor::annotateOneSelectInst(
SelectInst &SI) {
1363 std::vector<uint64_t> &CountFromProfile = UseFunc->getProfileRecord().Counts;
1364 assert(*CurCtrIdx < CountFromProfile.size() &&
1365 "Out of bound access of counters");
1366 uint64_t SCounts[2];
1367 SCounts[0] = CountFromProfile[*CurCtrIdx];
1369 uint64_t TotalCount = 0;
1370 auto BI = UseFunc->findBBInfo(SI.
getParent());
1372 TotalCount = BI->CountValue;
1374 SCounts[1] = (TotalCount > SCounts[0] ? TotalCount - SCounts[0] : 0);
1375 uint64_t MaxCount =
std::max(SCounts[0], SCounts[1]);
1380 void SelectInstVisitor::visitSelectInst(
SelectInst &SI) {
1392 instrumentOneSelectInst(SI);
1395 annotateOneSelectInst(SI);
1403 void PGOUseFunc::annotateValueSites() {
1411 annotateValueSites(
Kind);
1416 assert(Kind <= IPVK_Last);
1417 unsigned ValueSiteIndex = 0;
1418 auto &ValueSites = FuncInfo.ValueSites[
Kind];
1419 unsigned NumValueSites = ProfileRecord.getNumValueSites(Kind);
1420 if (NumValueSites != ValueSites.size()) {
1421 auto &Ctx = M->getContext();
1423 M->getName().data(),
1424 Twine(
"Inconsistent number of value sites for ") +
1426 Twine(
" profiling in \"") +
F.getName().str() +
1427 Twine(
"\", possibly due to the use of a stale profile."),
1433 LLVM_DEBUG(
dbgs() <<
"Read one value site profile (kind = " << Kind
1434 <<
"): Index = " << ValueSiteIndex <<
" out of " 1435 << NumValueSites <<
"\n");
1437 static_cast<InstrProfValueKind>(Kind), ValueSiteIndex,
1448 std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers) {
1453 ComdatMembers.insert(std::make_pair(
C, &
F));
1455 if (
Comdat *
C = GV.getComdat())
1456 ComdatMembers.insert(std::make_pair(
C, &GV));
1458 if (
Comdat *
C = GA.getComdat())
1459 ComdatMembers.insert(std::make_pair(
C, &GA));
1469 std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
1473 if (
F.isDeclaration())
1475 auto *BPI = LookupBPI(
F);
1476 auto *
BFI = LookupBFI(
F);
1489 bool PGOInstrumentationGenLegacyPass::runOnModule(
Module &M) {
1494 return &this->getAnalysis<BranchProbabilityInfoWrapperPass>(
F).getBPI();
1497 return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(
F).getBFI();
1529 if (
Error E = ReaderOrErr.takeError()) {
1537 std::unique_ptr<IndexedInstrProfReader> PGOReader =
1538 std::move(ReaderOrErr.get());
1544 if (!PGOReader->hasCSIRLevelProfile() && IsCS)
1548 if (!PGOReader->isIRLevelProfile()) {
1550 ProfileFileName.
data(),
"Not an IR level instrumentation profile"));
1561 std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
1563 std::vector<Function *> HotFunctions;
1564 std::vector<Function *> ColdFunctions;
1566 if (
F.isDeclaration())
1568 auto *BPI = LookupBPI(
F);
1569 auto *
BFI = LookupBFI(
F);
1573 PGOUseFunc Func(
F, &M, ComdatMembers, BPI,
BFI, PSI, IsCS);
1574 bool AllZeros =
false;
1575 if (!Func.readCounters(PGOReader.get(), AllZeros))
1579 if (Func.getProgramMaxCount() != 0)
1580 ColdFunctions.push_back(&
F);
1583 Func.populateCounters();
1584 Func.setBranchWeights();
1585 Func.annotateValueSites();
1586 Func.annotateIrrLoopHeaderWeights();
1587 PGOUseFunc::FuncFreqAttr FreqAttr = Func.getFuncFreqAttr();
1588 if (FreqAttr == PGOUseFunc::FFA_Cold)
1589 ColdFunctions.push_back(&
F);
1590 else if (FreqAttr == PGOUseFunc::FFA_Hot)
1591 HotFunctions.push_back(&
F);
1596 std::unique_ptr<BranchProbabilityInfo> NewBPI =
1597 std::make_unique<BranchProbabilityInfo>(
F, LI);
1598 std::unique_ptr<BlockFrequencyInfo> NewBFI =
1599 std::make_unique<BlockFrequencyInfo>(
F, *NewBPI, LI);
1603 dbgs() <<
"pgo-view-counts: " << Func.getFunc().getName() <<
"\n";
1604 NewBFI->print(
dbgs());
1614 ViewGraph(&Func,
Twine(
"PGORawCounts_") + Func.getFunc().getName());
1616 dbgs() <<
"pgo-view-raw-counts: " << Func.getFunc().getName() <<
"\n";
1626 for (
auto &
F : HotFunctions) {
1627 F->addFnAttr(Attribute::InlineHint);
1628 LLVM_DEBUG(
dbgs() <<
"Set inline attribute to function: " <<
F->getName()
1631 for (
auto &
F : ColdFunctions) {
1633 LLVM_DEBUG(
dbgs() <<
"Set cold attribute to function: " <<
F->getName()
1640 std::string RemappingFilename,
1642 : ProfileFileName(
std::move(Filename)),
1643 ProfileRemappingFileName(
std::move(RemappingFilename)), IsCS(IsCS) {
1665 LookupBPI, LookupBFI, PSI, IsCS))
1671 bool PGOInstrumentationUseLegacyPass::runOnModule(
Module &M) {
1676 return &this->getAnalysis<BranchProbabilityInfoWrapperPass>(
F).getBPI();
1679 return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(
F).getBFI();
1682 auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
1691 std::string SimpleNodeName;
1699 uint64_t MaxCount) {
1701 assert(MaxCount > 0 &&
"Bad max count");
1704 for (
const auto &ECI : EdgeCounts)
1714 TI->
setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
1717 if (BrCondStr.empty())
1721 std::accumulate(Weights.begin(), Weights.end(), (uint64_t)0,
1722 [](uint64_t w1, uint64_t w2) {
return w1 + w2; });
1723 uint64_t TotalCount =
1724 std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), (uint64_t)0,
1725 [](uint64_t c1, uint64_t c2) {
return c1 + c2; });
1729 std::string BranchProbStr;
1732 OS <<
" (total count : " << TotalCount <<
")";
1738 << BrCondStr <<
" is true with probability : " << BranchProbStr;
1748 MDB.createIrrLoopHeaderWeight(Count));
1757 return &G->getFunc().front();
1780 return G->getFunc().getName();
1788 UseBBInfo *BI = Graph->findBBInfo(Node);
1790 if (BI && BI->CountValid)
1791 OS << BI->CountValue <<
"\\l";
1798 for (
auto BI = Node->
begin(); BI != Node->
end(); ++BI) {
1800 if (!isa<SelectInst>(
I))
1803 OS <<
"SELECT : { T = ";
1805 bool HasProf =
I->extractProfMetadata(TC, FC);
1807 OS <<
"Unknown, F = Unknown }\\l";
1809 OS << TC <<
", F = " << FC <<
" }\\l";
ModulePass * createPGOInstrumentationGenLegacyPass(bool IsCS=false)
static uint64_t sumEdgeCount(const ArrayRef< PGOUseEdge *> Edges)
void setProfMetadata(Module *M, Instruction *TI, ArrayRef< uint64_t > EdgeCounts, uint64_t MaxCount)
static cl::opt< bool > NoPGOWarnMismatch("no-pgo-warn-mismatch", cl::init(false), cl::Hidden, cl::desc("Use this option to turn off/on " "warnings about profile cfg mismatch."))
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Base class for instruction visitors.
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
static cl::opt< bool > PGOWarnMissing("pgo-warn-missing-function", cl::init(false), cl::Hidden, cl::desc("Use this option to turn on/off " "warnings about missing profile data for " "functions."))
A Module instance is used to store all the information related to an LLVM module. ...
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
static ChildIteratorType child_begin(const NodeRef N)
std::vector< std::unique_ptr< Edge > > AllEdges
Diagnostic information for the PGO profiler.
Available for inspection, not emission.
bool isColdCount(uint64_t C)
Returns true if count C is considered cold.
void push_back(const T &Elt)
std::string getNodeLabel(const BasicBlock *Node, const PGOUseFunc *Graph)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Analysis providing profile information.
bool canRenameComdatFunc(const Function &F, bool CheckAddressTaken=false)
Check if we can safely rename this Comdat function.
PGOInstrumentationUse(std::string Filename="", std::string RemappingFilename="", bool IsCS=false)
An efficient, type-erasing, non-owning reference to a callable.
INITIALIZE_PASS_BEGIN(PGOInstrumentationGenLegacyPass, "pgo-instr-gen", "PGO instrumentation.", false, false) INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
virtual std::string message() const
Return the error message as a string.
static cl::opt< bool > PGOInstrMemOP("pgo-instr-memop", cl::init(true), cl::Hidden, cl::desc("Use this option to turn on/off " "memory intrinsic size profiling."))
LLVMContext & getContext() const
All values hold a context through their type.
static bool InstrumentAllFunctions(Module &M, function_ref< BranchProbabilityInfo *(Function &)> LookupBPI, function_ref< BlockFrequencyInfo *(Function &)> LookupBFI, bool IsCS)
STATISTIC(NumFunctions, "Total number of functions")
Value * getCondition() const
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...
bool isVectorTy() const
True if this is an instance of VectorType.
Error takeError()
Take ownership of the stored error.
SuccIterator< const Instruction, const BasicBlock > succ_const_iterator
Base class for error info classes.
bool isHotCount(uint64_t C)
Returns true if count C is considered hot.
An union-find based Minimum Spanning Tree for CFG.
*ViewGraph Emit a dot run run gv on the postscript *then cleanup For use from the debugger *void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
Function::ProfileCount ProfileCount
iterator begin()
Instruction iterator methods.
ModulePass * createPGOInstrumentationGenCreateVarLegacyPass(StringRef CSInstrName=StringRef(""))
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
This class represents the LLVM 'select' instruction.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
LLVMContext & getContext() const
Get the global data context.
static cl::opt< std::string > PGOTestProfileRemappingFile("pgo-test-profile-remapping-file", cl::init(""), cl::Hidden, cl::value_desc("filename"), cl::desc("Specify the path of profile remapping file. This is mainly for " "test purpose."))
This file contains the simple types necessary to represent the attributes associated with functions a...
Legacy analysis pass which computes BlockFrequencyInfo.
static std::string getGraphName(const PGOUseFunc *G)
void initializePGOInstrumentationGenCreateVarLegacyPassPass(PassRegistry &)
VisitMode
The select instruction visitor plays three roles specified by the mode.
Tagged union holding either a T or a Error.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
This file implements a class to represent arbitrary precision integral constant values and operations...
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
static bool isSimple(Instruction *I)
Analysis pass which computes BranchProbabilityInfo.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
This file provides the interface for IR based instrumentation passes ( (profile-gen, and profile-use).
Type * getType() const
All values are typed, get the type of this value.
static cl::opt< bool > DisableValueProfiling("disable-vp", cl::init(false), cl::Hidden, cl::desc("Disable Value Profiling"))
static NodeRef getEntryNode(const PGOUseFunc *G)
static bool isIndirectBrTarget(BasicBlock *BB)
void setComdat(Comdat *C)
static void setBranchWeights(SwitchInst *SI, ArrayRef< uint32_t > Weights)
raw_ostream & WriteGraph(raw_ostream &O, const GraphType &G, bool ShortNames=false, const Twine &Title="")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void verifyMisExpect(llvm::Instruction *I, const llvm::SmallVector< uint32_t, 4 > &Weights, llvm::LLVMContext &Ctx)
verifyMisExpect - compares PGO counters to the thresholds used for llvm.expect and warns if the PGO c...
BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
void initializePGOInstrumentationGenLegacyPassPass(PassRegistry &)
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
static bool canRenameComdat(Function &F, std::unordered_multimap< Comdat *, GlobalValue *> &ComdatMembers)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
static nodes_iterator nodes_end(const PGOUseFunc *G)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
instrprof_error get() const
Legacy analysis pass which computes BranchProbabilityInfo.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Value * getOperand(unsigned i) const
Analysis containing CSE Info
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static ChildIteratorType child_end(const NodeRef N)
Interval::succ_iterator succ_end(Interval *I)
static cl::opt< unsigned > MaxNumMemOPAnnotations("memop-max-annotations", cl::init(4), cl::Hidden, cl::ZeroOrMore, cl::desc("Max number of preicise value annotations for a single memop" "intrinsic"))
std::string message() const override
Return the error message as a string.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Same, but only replaced by something equivalent.
initializer< Ty > init(const Ty &Val)
StringRef getName() const
A set of analyses that are preserved following a run of a transformation pass.
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
Conditional or Unconditional Branch instruction.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
void setIrrLoopHeaderMetadata(Module *M, Instruction *TI, uint64_t Count)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
static StringRef getPredicateName(Predicate P)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Represent the analysis usage information of a pass.
static cl::opt< PGOViewCountsType > PGOViewRawCounts("pgo-view-raw-counts", cl::Hidden, cl::desc("A boolean option to show CFG dag or text " "with raw profile counts from " "profile data. See also option " "-pgo-view-counts. To limit graph " "display to only one function, use " "filtering option -view-bfi-func-name."), cl::values(clEnumValN(PGOVCT_None, "none", "do not show."), clEnumValN(PGOVCT_Graph, "graph", "show a graph."), clEnumValN(PGOVCT_Text, "text", "show in text.")))
static cl::opt< bool > DoComdatRenaming("do-comdat-renaming", cl::init(false), cl::Hidden, cl::desc("Append function hash to the name of COMDAT function to avoid " "function hash mismatch due to the preinliner"))
#define LLVM_ATTRIBUTE_UNUSED
This instruction compares its operands according to the predicate given to the constructor.
static std::string getBranchCondString(Instruction *TI)
static const char * ValueProfKindDescr[]
Interval::pred_iterator pred_end(Interval *I)
static uint64_t calculateCountScale(uint64_t MaxCount)
Calculate what to divide by to scale counts.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
INITIALIZE_PASS(PGOInstrumentationGenCreateVarLegacyPass, "pgo-instr-gen-create-var", "Create PGO instrumentation version variable for CSPGO.", false, false) ModulePass *llvm
static cl::opt< bool > NoPGOWarnMismatchComdat("no-pgo-warn-mismatch-comdat", cl::init(true), cl::Hidden, cl::desc("The option is used to turn on/off " "warnings about hash mismatch for comdat " "functions."))
void initializePGOInstrumentationUseLegacyPassPass(PassRegistry &)
DenseMap< const BasicBlock *, std::unique_ptr< BBInfo > > BBInfos
const Value * getCondition() const
static uint32_t scaleBranchCount(uint64_t Count, uint64_t Scale)
Scale an individual branch count.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
void annotateValueSite(Module &M, Instruction &Inst, const InstrProfRecord &InstrProfR, InstrProfValueKind ValueKind, uint32_t SiteIndx, uint32_t MaxMDCount=3)
Get the value profile data for value site SiteIdx from InstrProfR and annotate the instruction Inst w...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Class to represent profile counts.
void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName)
Create the PGOFuncName meta data if PGOFuncName is different from function's raw name.
PointerType * getInt8PtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer to an 8-bit integer value.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
BBInfo * findBBInfo(const BasicBlock *BB) const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
DOTGraphTraits(bool isSimple=false)
Analysis pass which computes BlockFrequencyInfo.
This is the shared class of boolean and integer constants.
void setSelectionKind(SelectionKind Val)
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static nodes_iterator nodes_begin(const PGOUseFunc *G)
Align max(MaybeAlign Lhs, Align Rhs)
static cl::opt< bool > PGOInstrSelect("pgo-instr-select", cl::init(true), cl::Hidden, cl::desc("Use this option to turn on/off SELECT " "instruction instrumentation. "))
uint64_t getMaximumFunctionCount(bool UseCS)
Return the maximum of all known function counts.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Utility analysis that determines what values are worth profiling.
pgo instr PGO instrumentation
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
static bool annotateAllFunctions(Module &M, StringRef ProfileFileName, StringRef ProfileRemappingFileName, function_ref< BranchProbabilityInfo *(Function &)> LookupBPI, function_ref< BlockFrequencyInfo *(Function &)> LookupBFI, ProfileSummaryInfo *PSI, bool IsCS)
static void instrumentOneFunc(Function &F, Module *M, BranchProbabilityInfo *BPI, BlockFrequencyInfo *BFI, std::unordered_multimap< Comdat *, GlobalValue *> &ComdatMembers, bool IsCS)
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
reference get()
Returns a reference to the stored T value.
bool isConditional() const
void dumpEdges(raw_ostream &OS, const Twine &Message) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
ModulePass * createPGOInstrumentationUseLegacyPass(StringRef Filename=StringRef(""), bool IsCS=false)
static cl::opt< std::string > PGOTestProfileFile("pgo-test-profile-file", cl::init(""), cl::Hidden, cl::value_desc("filename"), cl::desc("Specify the path of profile data file. This is" "mainly for test purpose."))
static void setCSFlagInHash(uint64_t &FuncHash)
BBInfo & getBBInfo(const BasicBlock *BB) const
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
const Comdat * getComdat() const
pgo instr Read PGO instrumentation profile
Predicate getPredicate() const
Return the predicate for this instruction.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
void update(ArrayRef< uint8_t > Data)
Analysis providing branch probability information.
unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
Profiling information for a single function.
Expected< InstrProfRecord > getInstrProfRecord(StringRef FuncName, uint64_t FuncHash)
Return the NamedInstrProfRecord associated with FuncName and FuncHash.
void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
std::string getPGOFuncName(const Function &F, bool InLTO=false, uint64_t Version=INSTR_PROF_INDEX_VERSION)
Return the modified name for function F suitable to be used the key for profile lookup.
bool SplitIndirectBrCriticalEdges(Function &F, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
GlobalVariable * createPGOFuncNameVar(Function &F, StringRef PGOFuncName)
Create and return the global variable for function name used in PGO instrumentation.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Keep one copy of named function when linking (weak)
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static cl::opt< unsigned > MaxNumAnnotations("icp-max-annotations", cl::init(3), cl::Hidden, cl::ZeroOrMore, cl::desc("Max number of annotations for a single indirect " "call callsite"))
std::string str() const
Return the twine contents as a std::string.
cl::opt< PGOViewCountsType > PGOViewCounts
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
const std::string to_string(const T &Value)
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
LLVM Value Representation.
void createIRLevelProfileFlagVar(Module &M, bool IsCS)
Lightweight error class with error context and mandatory checking.
BasicBlock::iterator GetInsertPoint() const
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
cl::opt< std::string > ViewBlockFreqFuncName
StringRef - Represent a constant reference to a string, i.e.
Reader for the indexed binary instrprof format.
A container for analyses that lazily runs them and caches their results.
std::vector< CandidateInfo > get(InstrProfValueKind Kind) const
returns a list of value profiling candidates of the given kind
static void collectComdatMembers(Module &M, std::unordered_multimap< Comdat *, GlobalValue *> &ComdatMembers)
This header defines various interfaces for pass management in LLVM.
static std::string getSimpleNodeName(const BasicBlock *Node)
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind)
Attach profile summary metadata to this module.
static cl::opt< bool > EmitBranchProbability("pgo-emit-branch-prob", cl::init(false), cl::Hidden, cl::desc("When this option is on, the annotated " "branch probability will be emitted as " "optimization remarks: -{Rpass|" "pass-remarks}=pgo-instrumentation"))
static Expected< std::unique_ptr< IndexedInstrProfReader > > create(const Twine &Path, const Twine &RemappingPath="")
Factory method to create an indexed reader.
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...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const BasicBlock * getParent() const
SelectionKind getSelectionKind() const
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...