llvm.org GIT mirror llvm / a67600c
Add optional arg to profile count getters to filter synthetic profile count. Differential Revision: http://reviews.llvm.org/D61025 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359131 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 5 months ago
9 changed file(s) with 41 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
6666 /// Returns the estimated profile count of \p BB.
6767 /// This computes the relative block frequency of \p BB and multiplies it by
6868 /// the enclosing function's count (if available) and returns the value.
69 Optional getBlockProfileCount(const BasicBlock *BB) const;
69 Optional getBlockProfileCount(const BasicBlock *BB,
70 bool AllowSynthetic = false) const;
7071
7172 /// Returns the estimated profile count of \p Freq.
7273 /// This uses the frequency \p Freq and multiplies it by
519519
520520 BlockFrequency getBlockFreq(const BlockNode &Node) const;
521521 Optional getBlockProfileCount(const Function &F,
522 const BlockNode &Node) const;
522 const BlockNode &Node,
523 bool AllowSynthetic = false) const;
523524 Optional getProfileCountFromFreq(const Function &F,
524 uint64_t Freq) const;
525 uint64_t Freq,
526 bool AllowSynthetic = false) const;
525527 bool isIrrLoopHeader(const BlockNode &Node);
526528
527529 void setBlockFreq(const BlockNode &Node, uint64_t Freq);
967969 }
968970
969971 Optional getBlockProfileCount(const Function &F,
970 const BlockT *BB) const {
971 return BlockFrequencyInfoImplBase::getBlockProfileCount(F, getNode(BB));
972 const BlockT *BB,
973 bool AllowSynthetic = false) const {
974 return BlockFrequencyInfoImplBase::getBlockProfileCount(F, getNode(BB),
975 AllowSynthetic);
972976 }
973977
974978 Optional getProfileCountFromFreq(const Function &F,
975 uint64_t Freq) const {
976 return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq);
979 uint64_t Freq,
980 bool AllowSynthetic = false) const {
981 return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq,
982 AllowSynthetic);
977983 }
978984
979985 bool isIrrLoopHeader(const BlockT *BB) {
9191
9292 /// Returns the profile count for \p CallInst.
9393 Optional getProfileCount(const Instruction *CallInst,
94 BlockFrequencyInfo *BFI);
94 BlockFrequencyInfo *BFI,
95 bool AllowSynthetic = false);
9596 /// Returns true if the working set size of the code is considered huge.
9697 bool hasHugeWorkingSetSize();
9798 /// Returns true if \p F has hot function entry.
295295
296296 /// Get the entry count for this function.
297297 ///
298 /// Entry count is the number of times the function was executed based on
299 /// pgo data.
300 ProfileCount getEntryCount() const;
298 /// Entry count is the number of times the function was executed.
299 /// When AllowSynthetic is false, only pgo_data will be returned.
300 ProfileCount getEntryCount(bool AllowSynthetic = false) const;
301301
302302 /// Return true if the function is annotated with profile data.
303303 ///
304304 /// Presence of entry counts from a profile run implies the function has
305 /// profile annotations.
306 bool hasProfileData() const { return getEntryCount().hasValue(); }
305 /// profile annotations. If IncludeSynthetic is false, only return true
306 /// when the profile data is real.
307 bool hasProfileData(bool IncludeSynthetic = false) const {
308 return getEntryCount(IncludeSynthetic).hasValue();
309 }
307310
308311 /// Returns the set of GUIDs that needs to be imported to the function for
309312 /// sample PGO, to enable the same inlines as the profiled optimized binary.
202202 }
203203
204204 Optional
205 BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB) const {
205 BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB,
206 bool AllowSynthetic) const {
206207 if (!BFI)
207208 return None;
208209
209 return BFI->getBlockProfileCount(*getFunction(), BB);
210 return BFI->getBlockProfileCount(*getFunction(), BB, AllowSynthetic);
210211 }
211212
212213 Optional
556556
557557 Optional
558558 BlockFrequencyInfoImplBase::getBlockProfileCount(const Function &F,
559 const BlockNode &Node) const {
560 return getProfileCountFromFreq(F, getBlockFreq(Node).getFrequency());
559 const BlockNode &Node,
560 bool AllowSynthetic) const {
561 return getProfileCountFromFreq(F, getBlockFreq(Node).getFrequency(),
562 AllowSynthetic);
561563 }
562564
563565 Optional
564566 BlockFrequencyInfoImplBase::getProfileCountFromFreq(const Function &F,
565 uint64_t Freq) const {
566 auto EntryCount = F.getEntryCount();
567 uint64_t Freq,
568 bool AllowSynthetic) const {
569 auto EntryCount = F.getEntryCount(AllowSynthetic);
567570 if (!EntryCount)
568571 return None;
569572 // Use 128 bit APInt to do the arithmetic to avoid overflow.
9494
9595 Optional
9696 ProfileSummaryInfo::getProfileCount(const Instruction *Inst,
97 BlockFrequencyInfo *BFI) {
97 BlockFrequencyInfo *BFI,
98 bool AllowSynthetic) {
9899 if (!Inst)
99100 return None;
100101 assert((isa(Inst) || isa(Inst)) &&
110111 return None;
111112 }
112113 if (BFI)
113 return BFI->getBlockProfileCount(Inst->getParent());
114 return BFI->getBlockProfileCount(Inst->getParent(), AllowSynthetic);
114115 return None;
115116 }
116117
13801380 setEntryCount(ProfileCount(Count, Type), Imports);
13811381 }
13821382
1383 ProfileCount Function::getEntryCount() const {
1383 ProfileCount Function::getEntryCount(bool AllowSynthetic) const {
13841384 MDNode *MD = getMetadata(LLVMContext::MD_prof);
13851385 if (MD && MD->getOperand(0))
13861386 if (MDString *MDS = dyn_cast(MD->getOperand(0))) {
13921392 if (Count == (uint64_t)-1)
13931393 return ProfileCount::getInvalid();
13941394 return ProfileCount(Count, PCT_Real);
1395 } else if (MDS->getString().equals("synthetic_function_entry_count")) {
1395 } else if (AllowSynthetic &&
1396 MDS->getString().equals("synthetic_function_entry_count")) {
13961397 ConstantInt *CI = mdconst::extract(MD->getOperand(1));
13971398 uint64_t Count = CI->getValue().getZExtValue();
13981399 return ProfileCount(Count, PCT_Synthetic);
27512751 F = getFunction("bar");
27522752 EXPECT_FALSE(F->getEntryCount().hasValue());
27532753 F->setEntryCount(123, Function::PCT_Synthetic);
2754 Count = F->getEntryCount();
2754 Count = F->getEntryCount(true /*allow synthetic*/);
27552755 EXPECT_TRUE(Count.hasValue());
27562756 EXPECT_EQ(123u, Count.getCount());
27572757 EXPECT_EQ(Function::PCT_Synthetic, Count.getType());