[llvm] 4e0e0bb - [ProfileData] llvm::Optional => std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 12 01:12:02 PST 2022
Author: Fangrui Song
Date: 2022-12-12T09:11:55Z
New Revision: 4e0e0bbd6b060f54adeb0e36993c9856747ece9b
URL: https://github.com/llvm/llvm-project/commit/4e0e0bbd6b060f54adeb0e36993c9856747ece9b
DIFF: https://github.com/llvm/llvm-project/commit/4e0e0bbd6b060f54adeb0e36993c9856747ece9b.diff
LOG: [ProfileData] llvm::Optional => std::optional
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProfCorrelator.h
llvm/include/llvm/ProfileData/SampleProfReader.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/lib/ProfileData/InstrProfCorrelator.cpp
llvm/lib/ProfileData/SampleProfReader.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
index 3238a90c1747c..2e26a21e8839b 100644
--- a/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
+++ b/llvm/include/llvm/ProfileData/InstrProfCorrelator.h
@@ -42,7 +42,7 @@ class InstrProfCorrelator {
virtual Error dumpYaml(raw_ostream &OS) = 0;
/// Return the number of ProfileData elements.
- llvm::Optional<size_t> getDataSize() const;
+ std::optional<size_t> getDataSize() const;
/// Return a pointer to the names string that this class constructs.
const char *getNamesPointer() const { return Names.c_str(); }
@@ -166,7 +166,7 @@ class DwarfInstrProfCorrelator : public InstrProfCorrelatorImpl<IntPtrT> {
std::unique_ptr<DWARFContext> DICtx;
/// Return the address of the object that the provided DIE symbolizes.
- llvm::Optional<uint64_t> getLocation(const DWARFDie &Die) const;
+ std::optional<uint64_t> getLocation(const DWARFDie &Die) const;
/// Returns true if the provided DIE symbolizes an instrumentation probe
/// symbol.
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index ba64e15115355..57e8c8c74e4ec 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -225,7 +225,6 @@
#ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H
#define LLVM_PROFILEDATA_SAMPLEPROFREADER_H
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/DiagnosticInfo.h"
@@ -241,6 +240,7 @@
#include <cstdint>
#include <list>
#include <memory>
+#include <optional>
#include <string>
#include <system_error>
#include <unordered_set>
@@ -295,7 +295,7 @@ class SampleProfileReaderItaniumRemapper {
/// Return the equivalent name in the profile for \p FunctionName if
/// it exists.
- Optional<StringRef> lookUpNameInProfile(StringRef FunctionName);
+ std::optional<StringRef> lookUpNameInProfile(StringRef FunctionName);
private:
// The buffer holding the content read from remapping file.
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index cad368d557ebd..12fbac99ee413 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -14,7 +14,6 @@
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
@@ -676,7 +675,8 @@ static SmallBitVector gatherFileIDs(StringRef SourceFile,
}
/// Return the ID of the file where the definition of the function is located.
-static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
+static std::optional<unsigned>
+findMainViewFileID(const FunctionRecord &Function) {
SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
for (const auto &CR : Function.CountedRegions)
if (CR.Kind == CounterMappingRegion::ExpansionRegion)
@@ -690,9 +690,9 @@ static Optional<unsigned> findMainViewFileID(const FunctionRecord &Function) {
/// Check if SourceFile is the file that contains the definition of
/// the Function. Return the ID of the file in that case or std::nullopt
/// otherwise.
-static Optional<unsigned> findMainViewFileID(StringRef SourceFile,
- const FunctionRecord &Function) {
- Optional<unsigned> I = findMainViewFileID(Function);
+static std::optional<unsigned>
+findMainViewFileID(StringRef SourceFile, const FunctionRecord &Function) {
+ std::optional<unsigned> I = findMainViewFileID(Function);
if (I && SourceFile == Function.Filenames[*I])
return I;
return std::nullopt;
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 9d63b5e4acfb3..16f864bb6d666 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -517,11 +517,11 @@ struct CovMapFuncRecordReader {
//
// Prior to Version4, \p OutOfLineMappingBuf points to a sequence of coverage
// mappings associated with the function records. It is unused in Version4.
- virtual Error readFunctionRecords(const char *FuncRecBuf,
- const char *FuncRecBufEnd,
- Optional<FilenameRange> OutOfLineFileRange,
- const char *OutOfLineMappingBuf,
- const char *OutOfLineMappingBufEnd) = 0;
+ virtual Error
+ readFunctionRecords(const char *FuncRecBuf, const char *FuncRecBufEnd,
+ std::optional<FilenameRange> OutOfLineFileRange,
+ const char *OutOfLineMappingBuf,
+ const char *OutOfLineMappingBufEnd) = 0;
template <class IntPtrT, support::endianness Endian>
static Expected<std::unique_ptr<CovMapFuncRecordReader>>
@@ -695,7 +695,7 @@ class VersionedCovMapFuncRecordReader : public CovMapFuncRecordReader {
}
Error readFunctionRecords(const char *FuncRecBuf, const char *FuncRecBufEnd,
- Optional<FilenameRange> OutOfLineFileRange,
+ std::optional<FilenameRange> OutOfLineFileRange,
const char *OutOfLineMappingBuf,
const char *OutOfLineMappingBufEnd) override {
auto CFR = reinterpret_cast<const FuncRecordType *>(FuncRecBuf);
@@ -710,7 +710,7 @@ class VersionedCovMapFuncRecordReader : public CovMapFuncRecordReader {
return make_error<CoverageMapError>(coveragemap_error::malformed);
// Look up the set of filenames associated with this function record.
- Optional<FilenameRange> FileRange;
+ std::optional<FilenameRange> FileRange;
if (Version < CovMapVersion::Version4) {
FileRange = OutOfLineFileRange;
} else {
diff --git a/llvm/lib/ProfileData/InstrProfCorrelator.cpp b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
index 6bab3c41b9ca1..c822d81f8bef1 100644
--- a/llvm/lib/ProfileData/InstrProfCorrelator.cpp
+++ b/llvm/lib/ProfileData/InstrProfCorrelator.cpp
@@ -94,7 +94,7 @@ InstrProfCorrelator::get(std::unique_ptr<MemoryBuffer> Buffer) {
instrprof_error::unable_to_correlate_profile, "not an object file");
}
-Optional<size_t> InstrProfCorrelator::getDataSize() const {
+std::optional<size_t> InstrProfCorrelator::getDataSize() const {
if (auto *C = dyn_cast<InstrProfCorrelatorImpl<uint32_t>>(this)) {
return C->getDataSize();
} else if (auto *C = dyn_cast<InstrProfCorrelatorImpl<uint64_t>>(this)) {
@@ -217,7 +217,7 @@ void InstrProfCorrelatorImpl<IntPtrT>::addProbe(StringRef FunctionName,
}
template <class IntPtrT>
-llvm::Optional<uint64_t>
+std::optional<uint64_t>
DwarfInstrProfCorrelator<IntPtrT>::getLocation(const DWARFDie &Die) const {
auto Locations = Die.getLocations(dwarf::DW_AT_location);
if (!Locations) {
@@ -266,7 +266,7 @@ void DwarfInstrProfCorrelator<IntPtrT>::correlateProfileDataImpl(
return;
std::optional<const char *> FunctionName;
std::optional<uint64_t> CFGHash;
- Optional<uint64_t> CounterPtr = getLocation(Die);
+ std::optional<uint64_t> CounterPtr = getLocation(Die);
auto FnDie = Die.getParent();
auto FunctionPtr = dwarf::toAddress(FnDie.find(dwarf::DW_AT_low_pc));
std::optional<uint64_t> NumCounters;
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 5d8f321b1a24e..25b13e043aea8 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -1820,7 +1820,7 @@ void SampleProfileReaderItaniumRemapper::applyRemapping(LLVMContext &Ctx) {
RemappingApplied = true;
}
-Optional<StringRef>
+std::optional<StringRef>
SampleProfileReaderItaniumRemapper::lookUpNameInProfile(StringRef Fname) {
if (auto Key = Remappings->lookup(Fname))
return NameMap.lookup(Key);
More information about the llvm-commits
mailing list