Index: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h =================================================================== --- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h +++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h @@ -67,7 +67,8 @@ /// Returns the estimated profile count of \p BB. /// This computes the relative block frequency of \p BB and multiplies it by /// the enclosing function's count (if available) and returns the value. - Optional getBlockProfileCount(const BasicBlock *BB) const; + Optional getBlockProfileCount(const BasicBlock *BB, + bool AllowSynthetic = false) const; /// Returns the estimated profile count of \p Freq. /// This uses the frequency \p Freq and multiplies it by Index: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h =================================================================== --- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -520,9 +520,11 @@ BlockFrequency getBlockFreq(const BlockNode &Node) const; Optional getBlockProfileCount(const Function &F, - const BlockNode &Node) const; + const BlockNode &Node, + bool AllowSynthetic = false) const; Optional getProfileCountFromFreq(const Function &F, - uint64_t Freq) const; + uint64_t Freq, + bool AllowSynthetic = false) const; bool isIrrLoopHeader(const BlockNode &Node); void setBlockFreq(const BlockNode &Node, uint64_t Freq); @@ -968,13 +970,17 @@ } Optional getBlockProfileCount(const Function &F, - const BlockT *BB) const { - return BlockFrequencyInfoImplBase::getBlockProfileCount(F, getNode(BB)); + const BlockT *BB, + bool AllowSynthetic = false) const { + return BlockFrequencyInfoImplBase::getBlockProfileCount(F, getNode(BB), + AllowSynthetic); } Optional getProfileCountFromFreq(const Function &F, - uint64_t Freq) const { - return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq); + uint64_t Freq, + bool AllowSynthetic = false) const { + return BlockFrequencyInfoImplBase::getProfileCountFromFreq(F, Freq, + AllowSynthetic); } bool isIrrLoopHeader(const BlockT *BB) { Index: llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h =================================================================== --- llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h +++ llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h @@ -92,7 +92,8 @@ /// Returns the profile count for \p CallInst. Optional getProfileCount(const Instruction *CallInst, - BlockFrequencyInfo *BFI); + BlockFrequencyInfo *BFI, + bool AllowSynthetic = false); /// Returns true if the working set size of the code is considered huge. bool hasHugeWorkingSetSize(); /// Returns true if \p F has hot function entry. Index: llvm/trunk/include/llvm/IR/Function.h =================================================================== --- llvm/trunk/include/llvm/IR/Function.h +++ llvm/trunk/include/llvm/IR/Function.h @@ -296,15 +296,18 @@ /// Get the entry count for this function. /// - /// Entry count is the number of times the function was executed based on - /// pgo data. - ProfileCount getEntryCount() const; + /// Entry count is the number of times the function was executed. + /// When AllowSynthetic is false, only pgo_data will be returned. + ProfileCount getEntryCount(bool AllowSynthetic = false) const; /// Return true if the function is annotated with profile data. /// /// Presence of entry counts from a profile run implies the function has - /// profile annotations. - bool hasProfileData() const { return getEntryCount().hasValue(); } + /// profile annotations. If IncludeSynthetic is false, only return true + /// when the profile data is real. + bool hasProfileData(bool IncludeSynthetic = false) const { + return getEntryCount(IncludeSynthetic).hasValue(); + } /// Returns the set of GUIDs that needs to be imported to the function for /// sample PGO, to enable the same inlines as the profiled optimized binary. Index: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp =================================================================== --- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp +++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp @@ -203,11 +203,12 @@ } Optional -BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB) const { +BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB, + bool AllowSynthetic) const { if (!BFI) return None; - return BFI->getBlockProfileCount(*getFunction(), BB); + return BFI->getBlockProfileCount(*getFunction(), BB, AllowSynthetic); } Optional Index: llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp =================================================================== --- llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ llvm/trunk/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -557,14 +557,17 @@ Optional BlockFrequencyInfoImplBase::getBlockProfileCount(const Function &F, - const BlockNode &Node) const { - return getProfileCountFromFreq(F, getBlockFreq(Node).getFrequency()); + const BlockNode &Node, + bool AllowSynthetic) const { + return getProfileCountFromFreq(F, getBlockFreq(Node).getFrequency(), + AllowSynthetic); } Optional BlockFrequencyInfoImplBase::getProfileCountFromFreq(const Function &F, - uint64_t Freq) const { - auto EntryCount = F.getEntryCount(); + uint64_t Freq, + bool AllowSynthetic) const { + auto EntryCount = F.getEntryCount(AllowSynthetic); if (!EntryCount) return None; // Use 128 bit APInt to do the arithmetic to avoid overflow. Index: llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp =================================================================== --- llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp +++ llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp @@ -95,7 +95,8 @@ Optional ProfileSummaryInfo::getProfileCount(const Instruction *Inst, - BlockFrequencyInfo *BFI) { + BlockFrequencyInfo *BFI, + bool AllowSynthetic) { if (!Inst) return None; assert((isa(Inst) || isa(Inst)) && @@ -111,7 +112,7 @@ return None; } if (BFI) - return BFI->getBlockProfileCount(Inst->getParent()); + return BFI->getBlockProfileCount(Inst->getParent(), AllowSynthetic); return None; } Index: llvm/trunk/lib/IR/Function.cpp =================================================================== --- llvm/trunk/lib/IR/Function.cpp +++ llvm/trunk/lib/IR/Function.cpp @@ -1381,7 +1381,7 @@ setEntryCount(ProfileCount(Count, Type), Imports); } -ProfileCount Function::getEntryCount() const { +ProfileCount Function::getEntryCount(bool AllowSynthetic) const { MDNode *MD = getMetadata(LLVMContext::MD_prof); if (MD && MD->getOperand(0)) if (MDString *MDS = dyn_cast(MD->getOperand(0))) { @@ -1393,7 +1393,8 @@ if (Count == (uint64_t)-1) return ProfileCount::getInvalid(); return ProfileCount(Count, PCT_Real); - } else if (MDS->getString().equals("synthetic_function_entry_count")) { + } else if (AllowSynthetic && + MDS->getString().equals("synthetic_function_entry_count")) { ConstantInt *CI = mdconst::extract(MD->getOperand(1)); uint64_t Count = CI->getValue().getZExtValue(); return ProfileCount(Count, PCT_Synthetic); Index: llvm/trunk/unittests/IR/MetadataTest.cpp =================================================================== --- llvm/trunk/unittests/IR/MetadataTest.cpp +++ llvm/trunk/unittests/IR/MetadataTest.cpp @@ -2752,7 +2752,7 @@ F = getFunction("bar"); EXPECT_FALSE(F->getEntryCount().hasValue()); F->setEntryCount(123, Function::PCT_Synthetic); - Count = F->getEntryCount(); + Count = F->getEntryCount(true /*allow synthetic*/); EXPECT_TRUE(Count.hasValue()); EXPECT_EQ(123u, Count.getCount()); EXPECT_EQ(Function::PCT_Synthetic, Count.getType());