diff options
author | Mircea Trofin <mtrofin@google.com> | 2021-11-13 22:03:10 -0800 |
---|---|---|
committer | Mircea Trofin <mtrofin@google.com> | 2021-11-14 19:03:30 -0800 |
commit | a32c2c380863d02eb0fd5e8757a62d96114b9519 (patch) | |
tree | a8efd17605ad68ca7810556740703fb38c29f9c4 /llvm/lib/IR/Function.cpp | |
parent | eec9ca622c2df2bcf3ffa7fad5a2381b829758b7 (diff) | |
download | llvm-a32c2c380863d02eb0fd5e8757a62d96114b9519.zip llvm-a32c2c380863d02eb0fd5e8757a62d96114b9519.tar.gz llvm-a32c2c380863d02eb0fd5e8757a62d96114b9519.tar.bz2 |
[NFC] Use Optional<ProfileCount> to model invalid counts
ProfileCount could model invalid values, but a user had no indication
that the getCount method could return bogus data. Optional<ProfileCount>
addresses that, because the user must dereference the optional. In
addition, the patch removes concept duplication.
Differential Revision: https://reviews.llvm.org/D113839
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 7eddffa..82b20a8 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -1892,10 +1892,9 @@ void Function::setValueSubclassDataBit(unsigned Bit, bool On) { void Function::setEntryCount(ProfileCount Count, const DenseSet<GlobalValue::GUID> *S) { - assert(Count.hasValue()); #if !defined(NDEBUG) auto PrevCount = getEntryCount(); - assert(!PrevCount.hasValue() || PrevCount.getType() == Count.getType()); + assert(!PrevCount.hasValue() || PrevCount->getType() == Count.getType()); #endif auto ImportGUIDs = getImportGUIDs(); @@ -1913,7 +1912,7 @@ void Function::setEntryCount(uint64_t Count, Function::ProfileCountType Type, setEntryCount(ProfileCount(Count, Type), Imports); } -ProfileCount Function::getEntryCount(bool AllowSynthetic) const { +Optional<ProfileCount> Function::getEntryCount(bool AllowSynthetic) const { MDNode *MD = getMetadata(LLVMContext::MD_prof); if (MD && MD->getOperand(0)) if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) { @@ -1923,7 +1922,7 @@ ProfileCount Function::getEntryCount(bool AllowSynthetic) const { // A value of -1 is used for SamplePGO when there were no samples. // Treat this the same as unknown. if (Count == (uint64_t)-1) - return ProfileCount::getInvalid(); + return None; return ProfileCount(Count, PCT_Real); } else if (AllowSynthetic && MDS->getString().equals("synthetic_function_entry_count")) { @@ -1932,7 +1931,7 @@ ProfileCount Function::getEntryCount(bool AllowSynthetic) const { return ProfileCount(Count, PCT_Synthetic); } } - return ProfileCount::getInvalid(); + return None; } DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const { |