diff options
Diffstat (limited to 'include/llvm/ProfileData')
-rw-r--r-- | include/llvm/ProfileData/Coverage/CoverageMapping.h | 13 | ||||
-rw-r--r-- | include/llvm/ProfileData/InstrProf.h | 31 | ||||
-rw-r--r-- | include/llvm/ProfileData/InstrProfReader.h | 28 | ||||
-rw-r--r-- | include/llvm/ProfileData/InstrProfWriter.h | 5 | ||||
-rw-r--r-- | include/llvm/ProfileData/SampleProf.h | 13 | ||||
-rw-r--r-- | include/llvm/ProfileData/SampleProfReader.h | 8 |
6 files changed, 55 insertions, 43 deletions
diff --git a/include/llvm/ProfileData/Coverage/CoverageMapping.h b/include/llvm/ProfileData/Coverage/CoverageMapping.h index b2f73fda2bae6..0ba792e8dc43c 100644 --- a/include/llvm/ProfileData/Coverage/CoverageMapping.h +++ b/include/llvm/ProfileData/Coverage/CoverageMapping.h @@ -411,9 +411,11 @@ public: std::vector<CoverageSegment>::const_iterator begin() const { return Segments.begin(); } + std::vector<CoverageSegment>::const_iterator end() const { return Segments.end(); } + bool empty() const { return Segments.empty(); } /// \brief Expansions that can be further processed. @@ -430,6 +432,7 @@ class CoverageMapping { unsigned MismatchedFunctionCount = 0; CoverageMapping() = default; + /// \brief Add a function record corresponding to \p Record. Error loadFunctionRecord(const CoverageMappingRecord &Record, IndexedInstrProfReader &ProfileReader); @@ -607,13 +610,13 @@ enum CovMapVersion { }; template <int CovMapVersion, class IntPtrT> struct CovMapTraits { - typedef CovMapFunctionRecord CovMapFuncRecordType; - typedef uint64_t NameRefType; + using CovMapFuncRecordType = CovMapFunctionRecord; + using NameRefType = uint64_t; }; template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version1, IntPtrT> { - typedef CovMapFunctionRecordV1<IntPtrT> CovMapFuncRecordType; - typedef IntPtrT NameRefType; + using CovMapFuncRecordType = CovMapFunctionRecordV1<IntPtrT>; + using NameRefType = IntPtrT; }; } // end namespace coverage @@ -622,6 +625,7 @@ template <class IntPtrT> struct CovMapTraits<CovMapVersion::Version1, IntPtrT> { template<> struct DenseMapInfo<coverage::CounterExpression> { static inline coverage::CounterExpression getEmptyKey() { using namespace coverage; + return CounterExpression(CounterExpression::ExprKind::Subtract, Counter::getCounter(~0U), Counter::getCounter(~0U)); @@ -629,6 +633,7 @@ template<> struct DenseMapInfo<coverage::CounterExpression> { static inline coverage::CounterExpression getTombstoneKey() { using namespace coverage; + return CounterExpression(CounterExpression::ExprKind::Add, Counter::getCounter(~0U), Counter::getCounter(~0U)); diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index 0dbb2cf9f2696..573ea90cfd00b 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -410,7 +410,7 @@ uint64_t ComputeHash(StringRef K); /// on how PGO name is formed. class InstrProfSymtab { public: - typedef std::vector<std::pair<uint64_t, uint64_t>> AddrHashMap; + using AddrHashMap = std::vector<std::pair<uint64_t, uint64_t>>; private: StringRef Data; @@ -450,11 +450,11 @@ public: /// decls from module \c M. This interface is used by transformation /// passes such as indirect function call promotion. Variable \c InLTO /// indicates if this is called from LTO optimization passes. - void create(Module &M, bool InLTO = false); + Error create(Module &M, bool InLTO = false); /// Create InstrProfSymtab from a set of names iteratable from /// \p IterRange. This interface is used by IndexedProfReader. - template <typename NameIterRange> void create(const NameIterRange &IterRange); + template <typename NameIterRange> Error create(const NameIterRange &IterRange); // If the symtab is created by a series of calls to \c addFuncName, \c // finalizeSymtab needs to be called before looking up function names. @@ -464,11 +464,14 @@ public: /// Update the symtab by adding \p FuncName to the table. This interface /// is used by the raw and text profile readers. - void addFuncName(StringRef FuncName) { + Error addFuncName(StringRef FuncName) { + if (FuncName.empty()) + return make_error<InstrProfError>(instrprof_error::malformed); auto Ins = NameTab.insert(FuncName); if (Ins.second) MD5NameMap.push_back(std::make_pair( IndexedInstrProf::ComputeHash(FuncName), Ins.first->getKey())); + return Error::success(); } /// Map a function address to its name's MD5 hash. This interface @@ -511,11 +514,13 @@ Error InstrProfSymtab::create(StringRef NameStrings) { } template <typename NameIterRange> -void InstrProfSymtab::create(const NameIterRange &IterRange) { +Error InstrProfSymtab::create(const NameIterRange &IterRange) { for (auto Name : IterRange) - addFuncName(Name); + if (Error E = addFuncName(Name)) + return E; finalizeSymtab(); + return Error::success(); } void InstrProfSymtab::finalizeSymtab() { @@ -594,7 +599,7 @@ struct InstrProfRecord { InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts) : Name(Name), Hash(Hash), Counts(std::move(Counts)) {} - typedef std::vector<std::pair<uint64_t, uint64_t>> ValueMapType; + using ValueMapType = std::vector<std::pair<uint64_t, uint64_t>>; /// Return the number of value profile kinds with non-zero number /// of profile sites. @@ -668,8 +673,8 @@ struct InstrProfRecord { private: std::vector<InstrProfValueSiteRecord> IndirectCallSites; std::vector<InstrProfValueSiteRecord> MemOPSizes; - const std::vector<InstrProfValueSiteRecord> & + const std::vector<InstrProfValueSiteRecord> & getValueSitesForKind(uint32_t ValueKind) const { switch (ValueKind) { case IPVK_IndirectCallTarget: @@ -873,6 +878,11 @@ struct Summary { // The number of Cutoff Entries (Summary::Entry) following summary fields. uint64_t NumCutoffEntries; + Summary() = delete; + Summary(uint32_t Size) { memset(this, 0, Size); } + + void operator delete(void *ptr) { ::operator delete(ptr); } + static uint32_t getSize(uint32_t NumSumFields, uint32_t NumCutoffEntries) { return sizeof(Summary) + NumCutoffEntries * sizeof(Entry) + NumSumFields * sizeof(uint64_t); @@ -911,11 +921,6 @@ struct Summary { ER.MinBlockCount = E.MinCount; ER.NumBlocks = E.NumCounts; } - - Summary(uint32_t Size) { memset(this, 0, Size); } - void operator delete(void *ptr) { ::operator delete(ptr); } - - Summary() = delete; }; inline std::unique_ptr<Summary> allocSummary(uint32_t TotalSize) { diff --git a/include/llvm/ProfileData/InstrProfReader.h b/include/llvm/ProfileData/InstrProfReader.h index 1d85a7149afc8..8163ca1592098 100644 --- a/include/llvm/ProfileData/InstrProfReader.h +++ b/include/llvm/ProfileData/InstrProfReader.h @@ -92,6 +92,7 @@ public: protected: std::unique_ptr<InstrProfSymtab> Symtab; + /// Set the current error and return same. Error error(instrprof_error Err) { LastError = Err; @@ -202,7 +203,7 @@ private: public: RawInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer) - : DataBuffer(std::move(DataBuffer)) { } + : DataBuffer(std::move(DataBuffer)) {} RawInstrProfReader(const RawInstrProfReader &) = delete; RawInstrProfReader &operator=(const RawInstrProfReader &) = delete; @@ -268,8 +269,8 @@ private: } }; -typedef RawInstrProfReader<uint32_t> RawInstrProfReader32; -typedef RawInstrProfReader<uint64_t> RawInstrProfReader64; +using RawInstrProfReader32 = RawInstrProfReader<uint32_t>; +using RawInstrProfReader64 = RawInstrProfReader<uint64_t>; namespace IndexedInstrProf { @@ -292,12 +293,12 @@ public: InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion) : HashType(HashType), FormatVersion(FormatVersion) {} - typedef ArrayRef<InstrProfRecord> data_type; + using data_type = ArrayRef<InstrProfRecord>; - typedef StringRef internal_key_type; - typedef StringRef external_key_type; - typedef uint64_t hash_value_type; - typedef uint64_t offset_type; + using internal_key_type = StringRef; + using external_key_type = StringRef; + using hash_value_type = uint64_t; + using offset_type = uint64_t; static bool EqualKey(StringRef A, StringRef B) { return A == B; } static StringRef GetInternalKey(StringRef K) { return K; } @@ -343,15 +344,14 @@ struct InstrProfReaderIndexBase { virtual void setValueProfDataEndianness(support::endianness Endianness) = 0; virtual uint64_t getVersion() const = 0; virtual bool isIRLevelProfile() const = 0; - virtual void populateSymtab(InstrProfSymtab &) = 0; + virtual Error populateSymtab(InstrProfSymtab &) = 0; }; -typedef OnDiskIterableChainedHashTable<InstrProfLookupTrait> - OnDiskHashTableImplV3; +using OnDiskHashTableImplV3 = + OnDiskIterableChainedHashTable<InstrProfLookupTrait>; template <typename HashTableImpl> class InstrProfReaderIndex : public InstrProfReaderIndexBase { - private: std::unique_ptr<HashTableImpl> HashTable; typename HashTableImpl::data_iterator RecordIterator; @@ -383,8 +383,8 @@ public: return (FormatVersion & VARIANT_MASK_IR_PROF) != 0; } - void populateSymtab(InstrProfSymtab &Symtab) override { - Symtab.create(HashTable->keys()); + Error populateSymtab(InstrProfSymtab &Symtab) override { + return Symtab.create(HashTable->keys()); } }; diff --git a/include/llvm/ProfileData/InstrProfWriter.h b/include/llvm/ProfileData/InstrProfWriter.h index 10742c0228ebe..fff10af30295a 100644 --- a/include/llvm/ProfileData/InstrProfWriter.h +++ b/include/llvm/ProfileData/InstrProfWriter.h @@ -29,10 +29,11 @@ namespace llvm { /// Writer for instrumentation based profile data. class InstrProfRecordWriterTrait; class ProfOStream; +class raw_fd_ostream; class InstrProfWriter { public: - typedef SmallDenseMap<uint64_t, InstrProfRecord, 1> ProfilingData; + using ProfilingData = SmallDenseMap<uint64_t, InstrProfRecord, 1>; enum ProfKind { PF_Unknown = 0, PF_FE, PF_IRLevel }; private: @@ -58,7 +59,7 @@ public: void write(raw_fd_ostream &OS); /// Write the profile in text format to \c OS - void writeText(raw_fd_ostream &OS); + Error writeText(raw_fd_ostream &OS); /// Write \c Record in text format to \c OS static void writeRecordInText(const InstrProfRecord &Record, diff --git a/include/llvm/ProfileData/SampleProf.h b/include/llvm/ProfileData/SampleProf.h index 7a705ca5416da..7fc258831be88 100644 --- a/include/llvm/ProfileData/SampleProf.h +++ b/include/llvm/ProfileData/SampleProf.h @@ -125,7 +125,7 @@ raw_ostream &operator<<(raw_ostream &OS, const LineLocation &Loc); /// will be a list of one or more functions. class SampleRecord { public: - typedef StringMap<uint64_t> CallTargetMap; + using CallTargetMap = StringMap<uint64_t>; SampleRecord() = default; @@ -182,10 +182,11 @@ private: raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample); -typedef std::map<LineLocation, SampleRecord> BodySampleMap; class FunctionSamples; -typedef StringMap<FunctionSamples> FunctionSamplesMap; -typedef std::map<LineLocation, FunctionSamplesMap> CallsiteSampleMap; + +using BodySampleMap = std::map<LineLocation, SampleRecord>; +using FunctionSamplesMap = StringMap<FunctionSamples>; +using CallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>; /// Representation of the samples collected for a function. /// @@ -398,8 +399,8 @@ raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS); /// order of LocationT. template <class LocationT, class SampleT> class SampleSorter { public: - typedef std::pair<const LocationT, SampleT> SamplesWithLoc; - typedef SmallVector<const SamplesWithLoc *, 20> SamplesWithLocList; + using SamplesWithLoc = std::pair<const LocationT, SampleT>; + using SamplesWithLocList = SmallVector<const SamplesWithLoc *, 20>; SampleSorter(const std::map<LocationT, SampleT> &Samples) { for (const auto &I : Samples) diff --git a/include/llvm/ProfileData/SampleProfReader.h b/include/llvm/ProfileData/SampleProfReader.h index 29e3aba3e0e76..9c1f357cbbd16 100644 --- a/include/llvm/ProfileData/SampleProfReader.h +++ b/include/llvm/ProfileData/SampleProfReader.h @@ -350,7 +350,7 @@ public: class SampleProfileReaderBinary : public SampleProfileReader { public: SampleProfileReaderBinary(std::unique_ptr<MemoryBuffer> B, LLVMContext &C) - : SampleProfileReader(std::move(B), C), Data(nullptr), End(nullptr) {} + : SampleProfileReader(std::move(B), C) {} /// \brief Read and validate the file header. std::error_code readHeader() override; @@ -388,10 +388,10 @@ protected: std::error_code readProfile(FunctionSamples &FProfile); /// \brief Points to the current location in the buffer. - const uint8_t *Data; + const uint8_t *Data = nullptr; /// \brief Points to the end of the buffer. - const uint8_t *End; + const uint8_t *End = nullptr; /// Function name table. std::vector<StringRef> NameTable; @@ -403,7 +403,7 @@ private: std::error_code readSummary(); }; -typedef SmallVector<FunctionSamples *, 10> InlineCallStack; +using InlineCallStack = SmallVector<FunctionSamples *, 10>; // Supported histogram types in GCC. Currently, we only need support for // call target histograms. |