46#define DEBUG_TYPE "coverage-mapping"
48STATISTIC(CovMapNumRecords,
"The # of coverage function records");
49STATISTIC(CovMapNumUsedRecords,
"The # of used coverage function records");
51void CoverageMappingIterator::increment() {
73 "the size of ULEB128 is too big");
81 if (Result >= MaxPlus1)
84 "the value of ULEB128 is greater than or equal to MaxPlus1");
91 if (Result >
Data.size())
93 "the value of ULEB128 is too big");
107 uint64_t NumFilenames;
108 if (
auto Err =
readSize(NumFilenames))
112 "number of filenames is zero");
115 return readUncompressed(
Version, NumFilenames);
119 uint64_t UncompressedLen;
123 uint64_t CompressedLen;
124 if (
auto Err =
readSize(CompressedLen))
127 if (CompressedLen > 0) {
136 StringRef CompressedFilenames =
Data.substr(0, CompressedLen);
149 return Delegate.readUncompressed(
Version, NumFilenames);
152 return readUncompressed(
Version, NumFilenames);
156 uint64_t NumFilenames) {
159 for (
size_t I = 0;
I < NumFilenames; ++
I) {
163 Filenames.push_back(
Filename.str());
169 Filenames.push_back(CWD.
str());
171 for (
size_t I = 1;
I < NumFilenames; ++
I) {
176 Filenames.push_back(
Filename.str());
179 if (!CompilationDir.empty())
180 P.assign(CompilationDir);
185 Filenames.push_back(
static_cast<std::string
>(
P.str()));
209 if (ID >= Expressions.size())
211 "counter expression is invalid");
218 "counter expression kind is invalid");
226 readIntMax(EncodedCounter, std::numeric_limits<unsigned>::max()))
228 if (
auto Err = decodeCounter(EncodedCounter,
C))
239Error RawCoverageMappingReader::readMappingRegionsSubArray(
240 std::vector<CounterMappingRegion> &MappingRegions,
unsigned InferredFileID,
243 if (
auto Err =
readSize(NumRegions))
245 unsigned LineStart = 0;
246 for (
size_t I = 0;
I < NumRegions; ++
I) {
256 if (
auto Err =
readIntMax(EncodedCounterAndRegion,
257 std::numeric_limits<unsigned>::max()))
274 if (
auto Err = decodeCounter(EncodedCounterAndRegion,
C))
280 ExpandedFileID = EncodedCounterAndRegion >>
282 if (ExpandedFileID >= NumFileIDs)
284 "ExpandedFileID is invalid");
286 switch (EncodedCounterAndRegion >>
297 if (
auto Err = readCounter(
C))
299 if (
auto Err = readCounter(C2))
305 if (
auto Err = readCounter(
C))
307 if (
auto Err = readCounter(C2))
309 if (
auto Err =
readIntMax(ID1, std::numeric_limits<int16_t>::max()))
311 if (
auto Err =
readIntMax(TID1, std::numeric_limits<int16_t>::max()))
313 if (
auto Err =
readIntMax(FID1, std::numeric_limits<int16_t>::max()))
318 "MCDCConditionID shouldn't be zero");
320 static_cast<int16_t
>(
static_cast<int16_t
>(ID1) - 1),
321 {
static_cast<int16_t
>(
static_cast<int16_t
>(FID1) - 1),
322 static_cast<int16_t
>(
static_cast<int16_t
>(TID1) - 1)}};
326 if (
auto Err =
readIntMax(BIDX, std::numeric_limits<unsigned>::max()))
328 if (
auto Err =
readIntMax(
NC, std::numeric_limits<int16_t>::max()))
335 "region kind is incorrect");
341 uint64_t LineStartDelta, ColumnStart, NumLines, ColumnEnd;
343 readIntMax(LineStartDelta, std::numeric_limits<unsigned>::max()))
347 if (ColumnStart > std::numeric_limits<unsigned>::max())
349 "start column is too big");
350 if (
auto Err =
readIntMax(NumLines, std::numeric_limits<unsigned>::max()))
352 if (
auto Err =
readIntMax(ColumnEnd, std::numeric_limits<unsigned>::max()))
354 LineStart += LineStartDelta;
357 if (ColumnEnd & (1U << 31)) {
359 ColumnEnd &= ~(1U << 31);
370 if (ColumnStart == 0 && ColumnEnd == 0) {
372 ColumnEnd = std::numeric_limits<unsigned>::max();
376 dbgs() <<
"Counter in file " << InferredFileID <<
" " << LineStart <<
":"
377 << ColumnStart <<
" -> " << (LineStart + NumLines) <<
":"
378 << ColumnEnd <<
", ";
380 dbgs() <<
"Expands to file " << ExpandedFileID;
387 C, C2, InferredFileID, ExpandedFileID, LineStart, ColumnStart,
388 LineStart + NumLines, ColumnEnd,
Kind, Params);
389 if (CMR.startLoc() > CMR.endLoc())
392 "counter mapping region locations are incorrect");
393 MappingRegions.push_back(CMR);
401 uint64_t NumFileMappings;
402 if (
auto Err =
readSize(NumFileMappings))
404 for (
size_t I = 0;
I < NumFileMappings; ++
I) {
405 uint64_t FilenameIndex;
406 if (
auto Err =
readIntMax(FilenameIndex, TranslationUnitFilenames.size()))
408 VirtualFileMapping.
push_back(FilenameIndex);
412 for (
auto I : VirtualFileMapping) {
413 Filenames.push_back(TranslationUnitFilenames[
I]);
417 uint64_t NumExpressions;
418 if (
auto Err =
readSize(NumExpressions))
426 for (
size_t I = 0;
I < NumExpressions; ++
I) {
427 if (
auto Err = readCounter(Expressions[
I].LHS))
429 if (
auto Err = readCounter(Expressions[
I].RHS))
434 for (
unsigned InferredFileID = 0, S = VirtualFileMapping.
size();
435 InferredFileID < S; ++InferredFileID) {
436 if (
auto Err = readMappingRegionsSubArray(MappingRegions, InferredFileID,
437 VirtualFileMapping.
size()))
447 FileIDExpansionRegionMapping.
resize(VirtualFileMapping.
size(),
nullptr);
449 for (
auto &R : MappingRegions) {
452 assert(!FileIDExpansionRegionMapping[R.ExpandedFileID]);
453 FileIDExpansionRegionMapping[R.ExpandedFileID] = &R;
456 for (
auto &R : MappingRegions) {
457 auto *&Slot = FileIDExpansionRegionMapping[R.FileID];
459 if (Slot->Count != R.Count) {
460 Slot->Count = R.Count;
473 return L.FileID < R.FileID;
475 "Coverage mapping regions must be sorted by FileID");
482 uint64_t NumFileMappings;
484 return std::move(Err);
485 if (NumFileMappings != 1)
488 uint64_t FilenameIndex;
490 readIntMax(FilenameIndex, std::numeric_limits<unsigned>::max()))
491 return std::move(Err);
492 uint64_t NumExpressions;
494 return std::move(Err);
495 if (NumExpressions != 0)
499 return std::move(Err);
502 uint64_t EncodedCounterAndRegion;
504 std::numeric_limits<unsigned>::max()))
505 return std::move(Err);
529 Address = Section.getAddress();
532 Data = Data.substr(1);
538 if (Pointer < Address)
540 auto Offset = Pointer - Address;
543 return Data.substr(Pointer - Address,
Size);
570struct CovMapFuncRecordReader {
571 virtual ~CovMapFuncRecordReader() =
default;
580 virtual Expected<const char *> readCoverageHeader(
const char *CovBuf,
581 const char *CovBufEnd) = 0;
594 readFunctionRecords(
const char *FuncRecBuf,
const char *FuncRecBufEnd,
595 std::optional<FilenameRange> OutOfLineFileRange,
596 const char *OutOfLineMappingBuf,
597 const char *OutOfLineMappingBufEnd) = 0;
599 template <
class IntPtrT, llvm::endianness Endian>
600 static Expected<std::unique_ptr<CovMapFuncRecordReader>>
602 std::vector<BinaryCoverageReader::ProfileMappingRecord> &R, StringRef
D,
603 std::vector<std::string> &
F);
607template <CovMapVersion Version,
class IntPtrT, llvm::endianness Endian>
608class VersionedCovMapFuncRecordReader :
public CovMapFuncRecordReader {
609 using FuncRecordType =
615 DenseMap<NameRefType, size_t> FunctionRecords;
616 InstrProfSymtab &ProfileNames;
617 StringRef CompilationDir;
618 std::vector<std::string> &Filenames;
619 std::vector<BinaryCoverageReader::ProfileMappingRecord> &
Records;
623 DenseMap<uint64_t, FilenameRange> FileRangeMap;
631 Error insertFunctionRecordIfNeeded(
const FuncRecordType *CFR,
633 FilenameRange FileRange) {
636 NameRefType NameRef = CFR->template getFuncNameRef<Endian>();
639 if (InsertResult.second) {
641 if (
Error Err = CFR->template getFuncName<Endian>(ProfileNames, FuncName))
643 if (FuncName.
empty())
645 "function name is empty");
646 ++CovMapNumUsedRecords;
652 size_t OldRecordIndex = InsertResult.first->second;
653 BinaryCoverageReader::ProfileMappingRecord &OldRecord =
659 if (!*OldIsDummyExpected)
661 Expected<bool> NewIsDummyExpected =
665 if (*NewIsDummyExpected)
667 ++CovMapNumUsedRecords;
676 VersionedCovMapFuncRecordReader(
678 std::vector<BinaryCoverageReader::ProfileMappingRecord> &R, StringRef
D,
679 std::vector<std::string> &
F)
680 : ProfileNames(
P), CompilationDir(
D), Filenames(
F),
Records(
R) {}
682 ~VersionedCovMapFuncRecordReader()
override =
default;
684 Expected<const char *> readCoverageHeader(
const char *CovBuf,
685 const char *CovBufEnd)
override {
686 using namespace support;
688 if (CovBuf +
sizeof(CovMapHeader) > CovBufEnd)
690 coveragemap_error::malformed,
691 "coverage mapping header section is larger than buffer size");
692 auto CovHeader =
reinterpret_cast<const CovMapHeader *
>(CovBuf);
693 uint32_t NRecords = CovHeader->getNRecords<Endian>();
694 uint32_t FilenamesSize = CovHeader->getFilenamesSize<Endian>();
695 uint32_t CoverageSize = CovHeader->getCoverageSize<Endian>();
697 CovBuf =
reinterpret_cast<const char *
>(CovHeader + 1);
702 const char *FuncRecBuf =
nullptr;
703 const char *FuncRecBufEnd =
nullptr;
704 if (
Version < CovMapVersion::Version4)
706 CovBuf += NRecords *
sizeof(FuncRecordType);
707 if (
Version < CovMapVersion::Version4)
708 FuncRecBufEnd = CovBuf;
711 if (CovBuf + FilenamesSize > CovBufEnd)
713 coveragemap_error::malformed,
714 "filenames section is larger than buffer size");
715 size_t FilenamesBegin = Filenames.size();
716 StringRef FilenameRegion(CovBuf, FilenamesSize);
717 RawCoverageFilenamesReader Reader(FilenameRegion, Filenames,
719 if (
auto Err = Reader.read(
Version))
720 return std::move(Err);
721 CovBuf += FilenamesSize;
722 FilenameRange FileRange(FilenamesBegin, Filenames.size() - FilenamesBegin);
724 if (
Version >= CovMapVersion::Version4) {
727 int64_t FilenamesRef =
730 FileRangeMap.
insert(std::make_pair(FilenamesRef, FileRange));
734 auto It = Filenames.begin();
735 FilenameRange &OrigRange =
Insert.first->getSecond();
741 FileRange = OrigRange;
751 const char *MappingBuf = CovBuf;
752 if (
Version >= CovMapVersion::Version4 && CoverageSize != 0)
754 "coverage mapping size is not zero");
755 CovBuf += CoverageSize;
756 const char *MappingEnd = CovBuf;
758 if (CovBuf > CovBufEnd)
760 coveragemap_error::malformed,
761 "function records section is larger than buffer size");
763 if (
Version < CovMapVersion::Version4) {
765 if (
Error E = readFunctionRecords(FuncRecBuf, FuncRecBufEnd, FileRange,
766 MappingBuf, MappingEnd))
777 Error readFunctionRecords(
const char *FuncRecBuf,
const char *FuncRecBufEnd,
778 std::optional<FilenameRange> OutOfLineFileRange,
779 const char *OutOfLineMappingBuf,
780 const char *OutOfLineMappingBufEnd)
override {
781 auto CFR =
reinterpret_cast<const FuncRecordType *
>(FuncRecBuf);
782 while ((
const char *)CFR < FuncRecBufEnd) {
784 const char *NextMappingBuf;
785 const FuncRecordType *NextCFR;
786 std::tie(NextMappingBuf, NextCFR) =
787 CFR->template advanceByOne<Endian>(OutOfLineMappingBuf);
788 if (
Version < CovMapVersion::Version4)
789 if (NextMappingBuf > OutOfLineMappingBufEnd)
791 coveragemap_error::malformed,
792 "next mapping buffer is larger than buffer size");
795 std::optional<FilenameRange> FileRange;
796 if (
Version < CovMapVersion::Version4) {
797 FileRange = OutOfLineFileRange;
799 uint64_t FilenamesRef = CFR->template getFilenamesRef<Endian>();
800 auto It = FileRangeMap.
find(FilenamesRef);
801 if (It == FileRangeMap.
end())
803 coveragemap_error::malformed,
804 "no filename found for function with hash=0x" +
807 FileRange = It->getSecond();
811 if (FileRange && !FileRange->isInvalid()) {
813 CFR->template getCoverageMapping<Endian>(OutOfLineMappingBuf);
814 if (
Version >= CovMapVersion::Version4 &&
815 Mapping.
data() + Mapping.
size() > FuncRecBufEnd)
817 coveragemap_error::malformed,
818 "coverage mapping data is larger than buffer size");
819 if (
Error Err = insertFunctionRecordIfNeeded(CFR, Mapping, *FileRange))
823 std::tie(OutOfLineMappingBuf, CFR) = std::tie(NextMappingBuf, NextCFR);
831template <
class IntPtrT, llvm::endianness Endian>
832Expected<std::unique_ptr<CovMapFuncRecordReader>> CovMapFuncRecordReader::get(
834 std::vector<BinaryCoverageReader::ProfileMappingRecord> &R, StringRef
D,
835 std::vector<std::string> &
F) {
836 using namespace coverage;
840 return std::make_unique<VersionedCovMapFuncRecordReader<
849 if (
Error E =
P.create(
P.getNameData()))
852 return std::make_unique<VersionedCovMapFuncRecordReader<
855 return std::make_unique<VersionedCovMapFuncRecordReader<
858 return std::make_unique<VersionedCovMapFuncRecordReader<
861 return std::make_unique<VersionedCovMapFuncRecordReader<
864 return std::make_unique<VersionedCovMapFuncRecordReader<
867 return std::make_unique<VersionedCovMapFuncRecordReader<
873template <
typename T, llvm::endianness Endian>
876 std::vector<BinaryCoverageReader::ProfileMappingRecord> &Records,
877 StringRef CompilationDir, std::vector<std::string> &Filenames) {
887 CovMapFuncRecordReader::get<T, Endian>(Version, ProfileNames, Records,
888 CompilationDir, Filenames);
891 auto Reader = std::move(ReaderExpected.
get());
892 const char *CovBuf = CovMap.
data();
893 const char *CovBufEnd = CovBuf + CovMap.
size();
894 const char *FuncRecBuf = FuncRecords.
data();
895 const char *FuncRecBufEnd = FuncRecords.
data() + FuncRecords.
size();
896 while (CovBuf < CovBufEnd) {
903 auto NextOrErr = Reader->readCoverageHeader(CovBuf, CovBufEnd);
904 if (
auto E = NextOrErr.takeError())
906 CovBuf = NextOrErr.get();
911 return Reader->readFunctionRecords(FuncRecBuf, FuncRecBufEnd, std::nullopt,
916Expected<std::unique_ptr<BinaryCoverageReader>>
920 std::unique_ptr<InstrProfSymtab> ProfileNamesPtr,
uint8_t BytesInAddress,
922 if (ProfileNamesPtr ==
nullptr)
924 "Caller must provide ProfileNames");
925 std::unique_ptr<BinaryCoverageReader> Reader(
926 new BinaryCoverageReader(std::move(ProfileNamesPtr),
927 std::move(FuncRecords), std::move(CoverageMap)));
929 StringRef FuncRecordsRef = Reader->FuncRecords->getBuffer();
932 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
933 CompilationDir, Reader->Filenames))
937 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
938 CompilationDir, Reader->Filenames))
942 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
943 CompilationDir, Reader->Filenames))
947 ProfileNames, Coverage, FuncRecordsRef, Reader->MappingRecords,
948 CompilationDir, Reader->Filenames))
953 "not supported endianness or bytes in address");
954 return std::move(Reader);
966 "the size of data is too small");
980 "the size of TestingFormatMagic is too big");
988 "the size of ULEB128 is too big");
990 if (
Data.size() < ProfileNamesSize)
992 "the size of ProfileNames is too big");
993 auto ProfileNames = std::make_unique<InstrProfSymtab>();
994 if (
Error E = ProfileNames->
create(
Data.substr(0, ProfileNamesSize), Address))
996 Data =
Data.substr(ProfileNamesSize);
1003 if (
N >
Data.size())
1005 "the size of ULEB128 is too big");
1010 "the size of CoverageMapping is teoo small");
1017 if (
Data.size() < Pad)
1019 "insufficient padding");
1024 "coverage mapping header section is larger than data size");
1025 auto const *CovHeader =
reinterpret_cast<const CovMapHeader *
>(
1033 CoverageMappingSize =
Data.size();
1035 auto FilenamesSize =
1037 CoverageMappingSize =
sizeof(
CovMapHeader) + FilenamesSize;
1042 Data =
Data.substr(CoverageMappingSize);
1048 "data is not empty");
1053 if (
Data.size() < Pad)
1055 "insufficient padding");
1063 std::move(ProfileNames), BytesInAddress, Endian, CompilationDir);
1068static Expected<std::vector<SectionRef>>
1070 auto ObjFormat = OF.getTripleObjectFormat();
1078 return IsCOFF ?
N.split(
'$').first :
N;
1080 Name = stripSuffix(Name);
1082 std::vector<SectionRef> Sections;
1083 for (
const auto &Section : OF.sections()) {
1087 if (stripSuffix(*NameOrErr) == Name) {
1091 if (IPSK == IPSK_name &&
1092 (Section.getSize() == 0 || (IsCOFF && Section.getSize() == 2)))
1094 Sections.push_back(Section);
1097 if (Sections.empty())
1105static Expected<std::pair<StringRef, uint64_t>>
1109 std::vector<const WasmSegment *> Segments;
1110 auto ObjFormat = OF.getTripleObjectFormat();
1113 for (
const auto &DebugName : WOF->debugNames()) {
1115 DebugName.Name != Name)
1117 if (DebugName.Index >= WOF->dataSegments().size())
1119 auto &Segment = WOF->dataSegments()[DebugName.Index];
1120 Segments.push_back(&Segment);
1122 if (Segments.empty())
1124 if (Segments.size() != 1)
1127 const auto &Segment = *Segments.front();
1128 auto &
Data = Segment.Data;
1129 StringRef Content(
reinterpret_cast<const char *
>(
Data.Content.data()),
1130 Data.Content.size());
1131 return std::make_pair(Content, Segment.SectionOffset);
1137 return Sections.takeError();
1138 if (Sections->size() != 1)
1141 "the size of coverage mapping section is not one");
1142 auto &Section = Sections->front();
1143 auto ContentsOrErr = Section.getContents();
1145 return ContentsOrErr.takeError();
1146 auto Content = *ContentsOrErr;
1148 Content = Content.drop_front(1);
1149 return std::make_pair(Content, Section.getAddress());
1152static Expected<std::unique_ptr<BinaryCoverageReader>>
1156 std::unique_ptr<ObjectFile> OF;
1160 auto ObjectFileOrErr = Universal->getMachOObjectForArch(Arch);
1161 if (!ObjectFileOrErr)
1162 return ObjectFileOrErr.takeError();
1163 OF = std::move(ObjectFileOrErr.get());
1168 if (!Arch.
empty() && OF->getArch() !=
Triple(Arch).getArch())
1173 "binary is not an object file");
1176 uint8_t BytesInAddress = OF->getBytesInAddress();
1181 auto ProfileNames = std::make_unique<InstrProfSymtab>();
1185 if (
auto E = NamesSection.takeError()) {
1188 if (
auto E = NamesSection.takeError())
1189 return std::move(
E);
1194 std::tie(NamesContent, NamesAddress) = *NamesSection;
1195 if (
Error E = ProfileNames->
create(NamesContent, NamesAddress))
1196 return std::move(
E);
1199 if (
auto E = CoverageSection.takeError())
1200 return std::move(
E);
1201 std::vector<SectionRef> CoverageSectionRefs = *CoverageSection;
1202 if (CoverageSectionRefs.size() != 1)
1204 "the size of name section is not one");
1205 auto CoverageMappingOrErr = CoverageSectionRefs.back().getContents();
1206 if (!CoverageMappingOrErr)
1207 return CoverageMappingOrErr.takeError();
1213 std::unique_ptr<MemoryBuffer> CoverageMapCopy;
1223 if (
auto E = CoverageRecordsSections.takeError()) {
1231 const Align RecordAlignment(8);
1233 for (
SectionRef Section : *CoverageRecordsSections) {
1234 auto CoverageRecordsOrErr = Section.getContents();
1235 if (!CoverageRecordsOrErr)
1236 return CoverageRecordsOrErr.takeError();
1237 FuncRecordsSize +=
alignTo(CoverageRecordsOrErr->size(), RecordAlignment);
1239 auto WritableBuffer =
1241 char *FuncRecordsBuffer = WritableBuffer->getBufferStart();
1243 "Allocated memory is correctly aligned");
1245 for (
SectionRef Section : *CoverageRecordsSections) {
1246 auto CoverageRecordsOrErr = Section.getContents();
1247 if (!CoverageRecordsOrErr)
1248 return CoverageRecordsOrErr.takeError();
1249 const auto &CoverageRecords = CoverageRecordsOrErr.get();
1250 FuncRecordsBuffer =
llvm::copy(CoverageRecords, FuncRecordsBuffer);
1252 std::fill_n(FuncRecordsBuffer,
1253 alignAddr(FuncRecordsBuffer, RecordAlignment) -
1257 assert(FuncRecordsBuffer == WritableBuffer->getBufferEnd() &&
1259 FuncRecords = std::move(WritableBuffer);
1267 std::move(ProfileNames), BytesInAddress, Endian, CompilationDir);
1275 for (
auto &ObjForArch : Universal->objects())
1276 if (Arch == ObjForArch.getArchFlagName())
1283Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
1288 std::vector<std::unique_ptr<BinaryCoverageReader>> Readers;
1292 *
reinterpret_cast<const uint64_t *
>(ObjectBuffer.
getBufferStart()),
1299 return ReaderOrErr.takeError();
1300 Readers.push_back(std::move(ReaderOrErr.get()));
1301 return std::move(Readers);
1307 return BinOrErr.takeError();
1308 std::unique_ptr<Binary>
Bin = std::move(BinOrErr.get());
1317 for (
auto &ObjForArch : Universal->objects()) {
1319 std::string ObjArch = ObjForArch.getArchFlagName();
1320 if (Arch != ObjArch)
1323 auto ArchiveOrErr = ObjForArch.getAsArchive();
1324 if (!ArchiveOrErr) {
1331 ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
1332 CompilationDir, BinaryIDs);
1339 for (
auto &Child : Ar->children(Err)) {
1345 ChildBufOrErr.
get(), Arch, ObjectFileBuffers, CompilationDir,
1347 if (!ChildReadersOrErr)
1348 return ChildReadersOrErr.takeError();
1349 for (
auto &Reader : ChildReadersOrErr.get())
1350 Readers.push_back(std::move(Reader));
1353 return std::move(Err);
1359 for (
auto &Buffer : Ar->takeThinBuffers())
1360 ObjectFileBuffers.push_back(std::move(Buffer));
1362 return std::move(Readers);
1367 BinaryIDs ? &BinaryID :
nullptr);
1369 return ReaderOrErr.takeError();
1370 Readers.push_back(std::move(ReaderOrErr.get()));
1371 if (!BinaryID.
empty())
1373 return std::move(Readers);
1377 if (CurrentRecord >= MappingRecords.size())
1380 FunctionsFilenames.clear();
1381 Expressions.clear();
1382 MappingRegions.clear();
1383 auto &R = MappingRecords[CurrentRecord];
1384 auto F =
ArrayRef(Filenames).slice(R.FilenamesBegin, R.FilenamesSize);
1386 Expressions, MappingRegions);
1387 if (
auto Err = Reader.
read())
1390 Record.FunctionName = R.FunctionName;
1391 Record.FunctionHash = R.FunctionHash;
1392 Record.Filenames = FunctionsFilenames;
1393 Record.Expressions = Expressions;
1394 Record.MappingRegions = MappingRegions;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static Error readCoverageMappingData(InstrProfSymtab &ProfileNames, StringRef CovMap, StringRef FuncRecords, std::vector< BinaryCoverageReader::ProfileMappingRecord > &Records, StringRef CompilationDir, std::vector< std::string > &Filenames)
static Expected< std::pair< StringRef, uint64_t > > lookupAllocatableSection(ObjectFile &OF, InstrProfSectKind IPSK)
Find a section that matches Name and is allocatable at runtime.
static Expected< std::unique_ptr< BinaryCoverageReader > > loadBinaryFormat(std::unique_ptr< Binary > Bin, StringRef Arch, StringRef CompilationDir="", object::BuildIDRef *BinaryID=nullptr)
static Expected< std::unique_ptr< BinaryCoverageReader > > loadTestingFormat(StringRef Data, StringRef CompilationDir)
static Expected< std::vector< SectionRef > > lookupSections(ObjectFile &OF, InstrProfSectKind IPSK)
Find all sections that match IPSK name.
static bool isArchSpecifierInvalidOrMissing(Binary *Bin, StringRef Arch)
Determine whether Arch is invalid or empty, given Bin.
static bool shouldSkipSectionFirstByte(SectionRef &Section)
Determine if we should skip the first byte of the section content.
static Expected< bool > isCoverageMappingDummy(uint64_t Hash, StringRef Mapping)
static const unsigned EncodingExpansionRegionBit
This file defines the DenseMap class.
static constexpr StringLiteral Filename
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
bool empty() const
Check if the array is empty.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
A symbol table used for function [IR]PGO name look-up with keys (such as pointers,...
LLVM_ABI StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize) const
Return function's PGO name from the function name's symbol address in the object file.
LLVM_ABI Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
const char * getBufferStart() const
StringRef getBuffer() const
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
constexpr bool empty() const
Check if the string is empty.
constexpr size_t size() const
Get the string size.
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Triple - Helper class for working with autoconf configuration names.
static Twine utohexstr(uint64_t Val)
static LLVM_ABI std::unique_ptr< WritableMemoryBuffer > getNewUninitMemBuffer(size_t Size, const Twine &BufferName="", std::optional< Align > Alignment=std::nullopt)
Allocate a new MemoryBuffer of the specified size that is not initialized.
static Expected< std::unique_ptr< BinaryCoverageReader > > createCoverageReaderFromBuffer(StringRef Coverage, FuncRecordsStorage &&FuncRecords, CoverageMapCopyStorage &&CoverageMap, std::unique_ptr< InstrProfSymtab > ProfileNamesPtr, uint8_t BytesInAddress, llvm::endianness Endian, StringRef CompilationDir="")
std::unique_ptr< MemoryBuffer > CoverageMapCopyStorage
static Expected< std::vector< std::unique_ptr< BinaryCoverageReader > > > create(MemoryBufferRef ObjectBuffer, StringRef Arch, SmallVectorImpl< std::unique_ptr< MemoryBuffer > > &ObjectFileBuffers, StringRef CompilationDir="", SmallVectorImpl< object::BuildIDRef > *BinaryIDs=nullptr)
std::unique_ptr< MemoryBuffer > FuncRecordsStorage
Error readNextRecord(CoverageMappingRecord &Record) override
A Counter mapping context is used to connect the counters, expressions and the obtained counter value...
LLVM_ABI void dump(const Counter &C, raw_ostream &OS) const
coveragemap_error get() const
CoverageMappingIterator()
virtual Error readNextRecord(CoverageMappingRecord &Record)=0
The mapping of profile information to coverage data.
RawCoverageFilenamesReader(StringRef Data, std::vector< std::string > &Filenames, StringRef CompilationDir="")
LLVM_ABI Error read(CovMapVersion Version)
Checks if the given coverage mapping data is exported for an unused function.
LLVM_ABI Expected< bool > isDummy()
Reader for the raw coverage mapping data.
LLVM_ABI Error readSize(uint64_t &Result)
LLVM_ABI Error readIntMax(uint64_t &Result, uint64_t MaxPlus1)
LLVM_ABI Error readULEB128(uint64_t &Result)
LLVM_ABI Error readString(StringRef &Result)
This class is the base class for all object file types.
Represents a GOFF physical record.
This is a value type class that represents a single section in the list of sections in the object fil...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
uint64_t ComputeHash(StringRef K)
llvm::SmallVector< std::shared_ptr< RecordsSlice >, 4 > Records
LLVM_ABI Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
LLVM_ABI bool isAvailable()
std::variant< std::monostate, DecisionParameters, BranchParameters > Parameters
The type of MC/DC-specific parameters.
@ invalid_or_missing_arch_specifier
constexpr uint64_t TestingFormatMagic
LLVM_ABI BuildIDRef getBuildID(const ObjectFile *Obj)
Returns the build ID, if any, contained in the given object file.
ArrayRef< uint8_t > BuildIDRef
A reference to a BuildID in binary form.
LLVM_ABI Expected< std::unique_ptr< Binary > > createBinary(MemoryBufferRef Source, LLVMContext *Context=nullptr, bool InitContent=true)
Create a Binary from Source, autodetecting the file type.
value_type byte_swap(value_type value, endianness endian)
Swap the bytes of value to match the given endianness.
LLVM_ABI bool remove_dots(SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
Remove '.
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct an array ref of bytes from a string ref.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment)
Returns the necessary adjustment for aligning Addr to Alignment bytes, rounding up.
LLVM_ABI std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void consumeError(Error Err)
Consume a Error without doing anything.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
uint64_t decodeULEB128(const uint8_t *p, unsigned *n, const uint8_t *end, const char **error, ULEB128DecodeError *errorCode)
Utility function to decode a ULEB128 value and report a typed error.
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
uintptr_t alignAddr(const void *Addr, Align Alignment)
Aligns Addr to Alignment bytes, rounding up.
FilenameRange(unsigned StartingIndex, unsigned Length)
This struct is a compact representation of a valid (non-zero power of two) alignment.
StringRef CoverageMapping
A Counter expression is a value that represents an arithmetic operation with two counters.
A Counter mapping region associates a source range with a specific counter.
@ ExpansionRegion
An ExpansionRegion represents a file expansion region that associates a source range with the expansi...
@ MCDCDecisionRegion
A DecisionRegion represents a top-level boolean expression and is associated with a variable length b...
@ MCDCBranchRegion
A Branch Region can be extended to include IDs to facilitate MC/DC.
@ SkippedRegion
A SkippedRegion represents a source range with code that was skipped by a preprocessor or similar mea...
@ GapRegion
A GapRegion is like a CodeRegion, but its count is only set as the line execution count when its the ...
@ BranchRegion
A BranchRegion represents leaf-level boolean expressions and is associated with two counters,...
@ CodeRegion
A CodeRegion associates some code with a counter.
A Counter is an abstract value that describes how to compute the execution count for a region of code...
static const unsigned EncodingTagBits
static Counter getZero()
Return the counter that represents the number zero.
static Counter getCounter(unsigned CounterId)
Return the counter that corresponds to a specific profile counter.
static const unsigned EncodingCounterTagAndExpansionRegionTagBits
static const unsigned EncodingTagMask
static Counter getExpression(unsigned ExpressionId)
Return the counter that corresponds to a specific addition counter expression.
CovMapFunctionRecordV3 CovMapFuncRecordType
Coverage mapping information for a single function.