Skip to content

Commit e78d131

Browse files
committed
[ProfileData] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 296846
1 parent 1fa6030 commit e78d131

19 files changed

+547
-277
lines changed

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

+46-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//=-- CoverageMapping.h - Code coverage mapping support ---------*- C++ -*-=//
1+
//===- CoverageMapping.h - Code coverage mapping support --------*- C++ -*-===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -12,25 +12,42 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef LLVM_PROFILEDATA_COVERAGEMAPPING_H_
16-
#define LLVM_PROFILEDATA_COVERAGEMAPPING_H_
15+
#ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
16+
#define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H
1717

1818
#include "llvm/ADT/ArrayRef.h"
1919
#include "llvm/ADT/DenseMap.h"
2020
#include "llvm/ADT/Hashing.h"
21-
#include "llvm/ADT/StringSet.h"
22-
#include "llvm/ADT/Triple.h"
2321
#include "llvm/ADT/iterator.h"
22+
#include "llvm/ADT/iterator_range.h"
23+
#include "llvm/ADT/None.h"
24+
#include "llvm/ADT/StringSet.h"
25+
#include "llvm/ADT/StringRef.h"
2426
#include "llvm/ProfileData/InstrProf.h"
27+
#include "llvm/Support/Compiler.h"
2528
#include "llvm/Support/Debug.h"
2629
#include "llvm/Support/Endian.h"
30+
#include "llvm/Support/Error.h"
2731
#include "llvm/Support/raw_ostream.h"
32+
#include <cassert>
33+
#include <cstdint>
34+
#include <iterator>
35+
#include <memory>
36+
#include <string>
2837
#include <system_error>
2938
#include <tuple>
39+
#include <utility>
40+
#include <vector>
3041

3142
namespace llvm {
43+
44+
class IndexedInstrProfReader;
45+
3246
namespace coverage {
3347

48+
class CoverageMappingReader;
49+
struct CoverageMappingRecord;
50+
3451
enum class coveragemap_error {
3552
success = 0,
3653
eof,
@@ -68,19 +85,6 @@ class CoverageMapError : public ErrorInfo<CoverageMapError> {
6885
coveragemap_error Err;
6986
};
7087

71-
} // end of coverage namespace.
72-
} // end of llvm namespace
73-
74-
namespace llvm {
75-
class IndexedInstrProfReader;
76-
namespace coverage {
77-
78-
class CoverageMappingReader;
79-
struct CoverageMappingRecord;
80-
81-
class CoverageMapping;
82-
struct CounterExpressions;
83-
8488
/// \brief A Counter is an abstract value that describes how to compute the
8589
/// execution count for a region of code using the collected profile count data.
8690
struct Counter {
@@ -91,13 +95,13 @@ struct Counter {
9195
EncodingTagBits + 1;
9296

9397
private:
94-
CounterKind Kind;
95-
unsigned ID;
98+
CounterKind Kind = Zero;
99+
unsigned ID = 0;
96100

97101
Counter(CounterKind Kind, unsigned ID) : Kind(Kind), ID(ID) {}
98102

99103
public:
100-
Counter() : Kind(Zero), ID(0) {}
104+
Counter() = default;
101105

102106
CounterKind getKind() const { return Kind; }
103107

@@ -153,8 +157,9 @@ struct CounterExpression {
153157
class CounterExpressionBuilder {
154158
/// \brief A list of all the counter expressions
155159
std::vector<CounterExpression> Expressions;
160+
156161
/// \brief A lookup table for the index of a given expression.
157-
llvm::DenseMap<CounterExpression, unsigned> ExpressionIndices;
162+
DenseMap<CounterExpression, unsigned> ExpressionIndices;
158163

159164
/// \brief Return the counter which corresponds to the given expression.
160165
///
@@ -238,7 +243,6 @@ struct CounterMappingRegion {
238243
LineEnd, ColumnEnd, SkippedRegion);
239244
}
240245

241-
242246
inline std::pair<unsigned, unsigned> startLoc() const {
243247
return std::pair<unsigned, unsigned>(LineStart, ColumnStart);
244248
}
@@ -269,7 +273,7 @@ class CounterMappingContext {
269273

270274
void setCounts(ArrayRef<uint64_t> Counts) { CounterValues = Counts; }
271275

272-
void dump(const Counter &C, llvm::raw_ostream &OS) const;
276+
void dump(const Counter &C, raw_ostream &OS) const;
273277
void dump(const Counter &C) const { dump(C, dbgs()); }
274278

275279
/// \brief Return the number of times that a region of code associated with
@@ -390,13 +394,14 @@ struct CoverageSegment {
390394
/// provides a sequence of CoverageSegments to iterate through, as well as the
391395
/// list of expansions that can be further processed.
392396
class CoverageData {
397+
friend class CoverageMapping;
398+
393399
std::string Filename;
394400
std::vector<CoverageSegment> Segments;
395401
std::vector<ExpansionRecord> Expansions;
396-
friend class CoverageMapping;
397402

398403
public:
399-
CoverageData() {}
404+
CoverageData() = default;
400405

401406
CoverageData(StringRef Filename) : Filename(Filename) {}
402407

@@ -422,18 +427,17 @@ class CoverageData {
422427
class CoverageMapping {
423428
StringSet<> FunctionNames;
424429
std::vector<FunctionRecord> Functions;
425-
unsigned MismatchedFunctionCount;
426-
427-
CoverageMapping() : MismatchedFunctionCount(0) {}
428-
429-
CoverageMapping(const CoverageMapping &) = delete;
430-
const CoverageMapping &operator=(const CoverageMapping &) = delete;
430+
unsigned MismatchedFunctionCount = 0;
431431

432+
CoverageMapping() = default;
432433
/// \brief Add a function record corresponding to \p Record.
433434
Error loadFunctionRecord(const CoverageMappingRecord &Record,
434435
IndexedInstrProfReader &ProfileReader);
435436

436437
public:
438+
CoverageMapping(const CoverageMapping &) = delete;
439+
CoverageMapping &operator=(const CoverageMapping &) = delete;
440+
437441
/// \brief Load the coverage mapping using the given readers.
438442
static Expected<std::unique_ptr<CoverageMapping>>
439443
load(CoverageMappingReader &CoverageReader,
@@ -517,14 +521,17 @@ template <class IntPtrT> struct CovMapFunctionRecordV1 {
517521
template <support::endianness Endian> uint64_t getFuncHash() const {
518522
return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
519523
}
524+
520525
// Return the coverage map data size for the funciton.
521526
template <support::endianness Endian> uint32_t getDataSize() const {
522527
return support::endian::byte_swap<uint32_t, Endian>(DataSize);
523528
}
529+
524530
// Return function lookup key. The value is consider opaque.
525531
template <support::endianness Endian> IntPtrT getFuncNameRef() const {
526532
return support::endian::byte_swap<IntPtrT, Endian>(NamePtr);
527533
}
534+
528535
// Return the PGO name of the function */
529536
template <support::endianness Endian>
530537
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
@@ -545,14 +552,17 @@ struct CovMapFunctionRecord {
545552
template <support::endianness Endian> uint64_t getFuncHash() const {
546553
return support::endian::byte_swap<uint64_t, Endian>(FuncHash);
547554
}
555+
548556
// Return the coverage map data size for the funciton.
549557
template <support::endianness Endian> uint32_t getDataSize() const {
550558
return support::endian::byte_swap<uint32_t, Endian>(DataSize);
551559
}
560+
552561
// Return function lookup key. The value is consider opaque.
553562
template <support::endianness Endian> uint64_t getFuncNameRef() const {
554563
return support::endian::byte_swap<uint64_t, Endian>(NameRef);
555564
}
565+
556566
// Return the PGO name of the function */
557567
template <support::endianness Endian>
558568
Error getFuncName(InstrProfSymtab &ProfileNames, StringRef &FuncName) const {
@@ -570,12 +580,15 @@ struct CovMapHeader {
570580
template <support::endianness Endian> uint32_t getNRecords() const {
571581
return support::endian::byte_swap<uint32_t, Endian>(NRecords);
572582
}
583+
573584
template <support::endianness Endian> uint32_t getFilenamesSize() const {
574585
return support::endian::byte_swap<uint32_t, Endian>(FilenamesSize);
575586
}
587+
576588
template <support::endianness Endian> uint32_t getCoverageSize() const {
577589
return support::endian::byte_swap<uint32_t, Endian>(CoverageSize);
578590
}
591+
579592
template <support::endianness Endian> uint32_t getVersion() const {
580593
return support::endian::byte_swap<uint32_t, Endian>(Version);
581594
}
@@ -635,4 +648,4 @@ template<> struct DenseMapInfo<coverage::CounterExpression> {
635648

636649
} // end namespace llvm
637650

638-
#endif // LLVM_PROFILEDATA_COVERAGEMAPPING_H_
651+
#endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPING_H

llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//=-- CoverageMappingReader.h - Code coverage mapping reader ------*- C++ -*-=//
1+
//===- CoverageMappingReader.h - Code coverage mapping reader ---*- C++ -*-===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -12,18 +12,20 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef LLVM_PROFILEDATA_COVERAGEMAPPINGREADER_H
16-
#define LLVM_PROFILEDATA_COVERAGEMAPPINGREADER_H
15+
#ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGREADER_H
16+
#define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGREADER_H
1717

1818
#include "llvm/ADT/ArrayRef.h"
1919
#include "llvm/ADT/StringRef.h"
20-
#include "llvm/ADT/Triple.h"
21-
#include "llvm/Object/ObjectFile.h"
2220
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
2321
#include "llvm/ProfileData/InstrProf.h"
24-
#include "llvm/Support/FileSystem.h"
22+
#include "llvm/Support/Error.h"
2523
#include "llvm/Support/MemoryBuffer.h"
24+
#include <cstddef>
25+
#include <cstdint>
2626
#include <iterator>
27+
#include <memory>
28+
#include <vector>
2729

2830
namespace llvm {
2931
namespace coverage {
@@ -42,13 +44,14 @@ struct CoverageMappingRecord {
4244
/// \brief A file format agnostic iterator over coverage mapping data.
4345
class CoverageMappingIterator
4446
: public std::iterator<std::input_iterator_tag, CoverageMappingRecord> {
45-
CoverageMappingReader *Reader;
47+
CoverageMappingReader *Reader = nullptr;
4648
CoverageMappingRecord Record;
4749

4850
void increment();
4951

5052
public:
51-
CoverageMappingIterator() : Reader(nullptr) {}
53+
CoverageMappingIterator() = default;
54+
5255
CoverageMappingIterator(CoverageMappingReader *Reader) : Reader(Reader) {
5356
increment();
5457
}
@@ -69,10 +72,11 @@ class CoverageMappingIterator
6972

7073
class CoverageMappingReader {
7174
public:
75+
virtual ~CoverageMappingReader() = default;
76+
7277
virtual Error readNextRecord(CoverageMappingRecord &Record) = 0;
7378
CoverageMappingIterator begin() { return CoverageMappingIterator(this); }
7479
CoverageMappingIterator end() { return CoverageMappingIterator(); }
75-
virtual ~CoverageMappingReader() {}
7680
};
7781

7882
/// \brief Base class for the raw coverage mapping and filenames data readers.
@@ -92,13 +96,12 @@ class RawCoverageReader {
9296
class RawCoverageFilenamesReader : public RawCoverageReader {
9397
std::vector<StringRef> &Filenames;
9498

95-
RawCoverageFilenamesReader(const RawCoverageFilenamesReader &) = delete;
96-
RawCoverageFilenamesReader &
97-
operator=(const RawCoverageFilenamesReader &) = delete;
98-
9999
public:
100100
RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)
101101
: RawCoverageReader(Data), Filenames(Filenames) {}
102+
RawCoverageFilenamesReader(const RawCoverageFilenamesReader &) = delete;
103+
RawCoverageFilenamesReader &
104+
operator=(const RawCoverageFilenamesReader &) = delete;
102105

103106
Error read();
104107
};
@@ -120,10 +123,6 @@ class RawCoverageMappingReader : public RawCoverageReader {
120123
std::vector<CounterExpression> &Expressions;
121124
std::vector<CounterMappingRegion> &MappingRegions;
122125

123-
RawCoverageMappingReader(const RawCoverageMappingReader &) = delete;
124-
RawCoverageMappingReader &
125-
operator=(const RawCoverageMappingReader &) = delete;
126-
127126
public:
128127
RawCoverageMappingReader(StringRef MappingData,
129128
ArrayRef<StringRef> TranslationUnitFilenames,
@@ -134,6 +133,9 @@ class RawCoverageMappingReader : public RawCoverageReader {
134133
TranslationUnitFilenames(TranslationUnitFilenames),
135134
Filenames(Filenames), Expressions(Expressions),
136135
MappingRegions(MappingRegions) {}
136+
RawCoverageMappingReader(const RawCoverageMappingReader &) = delete;
137+
RawCoverageMappingReader &
138+
operator=(const RawCoverageMappingReader &) = delete;
137139

138140
Error read();
139141

@@ -169,17 +171,17 @@ class BinaryCoverageReader : public CoverageMappingReader {
169171
std::vector<StringRef> Filenames;
170172
std::vector<ProfileMappingRecord> MappingRecords;
171173
InstrProfSymtab ProfileNames;
172-
size_t CurrentRecord;
174+
size_t CurrentRecord = 0;
173175
std::vector<StringRef> FunctionsFilenames;
174176
std::vector<CounterExpression> Expressions;
175177
std::vector<CounterMappingRegion> MappingRegions;
176178

179+
BinaryCoverageReader() = default;
180+
181+
public:
177182
BinaryCoverageReader(const BinaryCoverageReader &) = delete;
178183
BinaryCoverageReader &operator=(const BinaryCoverageReader &) = delete;
179184

180-
BinaryCoverageReader() : CurrentRecord(0) {}
181-
182-
public:
183185
static Expected<std::unique_ptr<BinaryCoverageReader>>
184186
create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
185187
StringRef Arch);
@@ -190,4 +192,4 @@ class BinaryCoverageReader : public CoverageMappingReader {
190192
} // end namespace coverage
191193
} // end namespace llvm
192194

193-
#endif
195+
#endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGREADER_H

llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//=-- CoverageMappingWriter.h - Code coverage mapping writer ------*- C++ -*-=//
1+
//===- CoverageMappingWriter.h - Code coverage mapping writer ---*- C++ -*-===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -12,15 +12,17 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef LLVM_PROFILEDATA_COVERAGEMAPPINGWRITER_H
16-
#define LLVM_PROFILEDATA_COVERAGEMAPPINGWRITER_H
15+
#ifndef LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H
16+
#define LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H
1717

1818
#include "llvm/ADT/ArrayRef.h"
19-
#include "llvm/ADT/StringMap.h"
19+
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
21-
#include "llvm/Support/raw_ostream.h"
2221

2322
namespace llvm {
23+
24+
class raw_ostream;
25+
2426
namespace coverage {
2527

2628
/// \brief Writer of the filenames section for the instrumentation
@@ -54,6 +56,7 @@ class CoverageMappingWriter {
5456
};
5557

5658
} // end namespace coverage
59+
5760
} // end namespace llvm
5861

59-
#endif
62+
#endif // LLVM_PROFILEDATA_COVERAGE_COVERAGEMAPPINGWRITER_H

0 commit comments

Comments
 (0)