40
40
#include < stack>
41
41
#include < string>
42
42
#include < system_error>
43
+ #include < unordered_map>
43
44
#include < utility>
44
45
#include < vector>
45
46
@@ -975,7 +976,7 @@ class MCDCDecisionRecorder {
975
976
Error CoverageMapping::loadFunctionRecord (
976
977
const CoverageMappingRecord &Record,
977
978
const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
978
- &ProfileReader) {
979
+ &ProfileReader, StringRef ObjectFilename ) {
979
980
StringRef OrigFuncName = Record.FunctionName ;
980
981
if (OrigFuncName.empty ())
981
982
return make_error<CoverageMapError>(coveragemap_error::malformed,
@@ -997,12 +998,10 @@ Error CoverageMapping::loadFunctionRecord(
997
998
998
999
std::vector<uint64_t > Counts;
999
1000
if (ProfileReader) {
1000
- if (Error E = ProfileReader.value ().get ().getFunctionCounts (
1001
- Record.FunctionName , FuncArchHash, Counts)) {
1001
+ if (Error E = ProfileReader.value ().get ().getFunctionCounts (Record.FunctionName , FuncArchHash, Counts)) {
1002
1002
instrprof_error IPE = std::get<0 >(InstrProfError::take (std::move (E)));
1003
1003
if (IPE == instrprof_error::hash_mismatch) {
1004
- FuncHashMismatches.emplace_back (std::string (Record.FunctionName ),
1005
- FuncArchHash);
1004
+ FuncHashMismatches.emplace_back (std::string (Record.FunctionName ), FuncArchHash);
1006
1005
return Error::success ();
1007
1006
}
1008
1007
if (IPE != instrprof_error::unknown_function)
@@ -1035,6 +1034,7 @@ Error CoverageMapping::loadFunctionRecord(
1035
1034
} else {
1036
1035
Bitmap = BitVector (getMaxBitmapSize (Record, false ));
1037
1036
}
1037
+
1038
1038
Ctx.setBitmap (std::move (Bitmap));
1039
1039
1040
1040
assert (!Record.MappingRegions .empty () && " Function has no regions" );
@@ -1049,7 +1049,7 @@ Error CoverageMapping::loadFunctionRecord(
1049
1049
return Error::success ();
1050
1050
1051
1051
MCDCDecisionRecorder MCDCDecisions;
1052
- FunctionRecord Function (OrigFuncName, Record.Filenames );
1052
+ FunctionRecord Function (OrigFuncName, Record.Filenames , ObjectFilename );
1053
1053
for (const auto &Region : Record.MappingRegions ) {
1054
1054
// MCDCDecisionRegion should be handled first since it overlaps with
1055
1055
// others inside.
@@ -1102,9 +1102,9 @@ Error CoverageMapping::loadFunctionRecord(
1102
1102
1103
1103
// Don't create records for (filenames, function) pairs we've already seen.
1104
1104
auto FilenamesHash = hash_combine_range (Record.Filenames );
1105
- if (!RecordProvenance[FilenamesHash].insert (hash_value (OrigFuncName)) .second )
1105
+ if (!RecordProvenance[FilenamesHash].insert (FuncArchHash) .second ){
1106
1106
return Error::success ();
1107
-
1107
+ }
1108
1108
Functions.push_back (std::move (Function));
1109
1109
1110
1110
// Performance optimization: keep track of the indices of the function records
@@ -1152,7 +1152,7 @@ Error CoverageMapping::loadFromReaders(
1152
1152
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
1153
1153
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1154
1154
&ProfileReader,
1155
- CoverageMapping &Coverage, StringRef Arch) {
1155
+ CoverageMapping &Coverage, StringRef Arch, StringRef ObjectFilename ) {
1156
1156
1157
1157
Coverage.setArchitecture (Arch);
1158
1158
assert (!Coverage.SingleByteCoverage || !ProfileReader ||
@@ -1165,7 +1165,7 @@ Error CoverageMapping::loadFromReaders(
1165
1165
if (Error E = RecordOrErr.takeError ())
1166
1166
return E;
1167
1167
const auto &Record = *RecordOrErr;
1168
- if (Error E = Coverage.loadFunctionRecord (Record, ProfileReader))
1168
+ if (Error E = Coverage.loadFunctionRecord (Record, ProfileReader, ObjectFilename ))
1169
1169
return E;
1170
1170
}
1171
1171
}
@@ -1196,7 +1196,7 @@ Error CoverageMapping::loadFromFile(
1196
1196
std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1197
1197
&ProfileReader,
1198
1198
CoverageMapping &Coverage, bool &DataFound,
1199
- SmallVectorImpl<object::BuildID> *FoundBinaryIDs) {
1199
+ SmallVectorImpl<object::BuildID> *FoundBinaryIDs, StringRef ObjectFilename ) {
1200
1200
auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN (
1201
1201
Filename, /* IsText=*/ false , /* RequiresNullTerminator=*/ false );
1202
1202
if (std::error_code EC = CovMappingBufOrErr.getError ())
@@ -1228,7 +1228,7 @@ Error CoverageMapping::loadFromFile(
1228
1228
}));
1229
1229
}
1230
1230
DataFound |= !Readers.empty ();
1231
- if (Error E = loadFromReaders (Readers, ProfileReader, Coverage, Arch))
1231
+ if (Error E = loadFromReaders (Readers, ProfileReader, Coverage, Arch, ObjectFilename ))
1232
1232
return createFileError (Filename, std::move (E));
1233
1233
return Error::success ();
1234
1234
}
@@ -1262,14 +1262,20 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
1262
1262
return Arches[Idx];
1263
1263
};
1264
1264
1265
+ // I beleive there is an error in this area of code, it's iterating through all arch's of the object files
1266
+ // but its only filling *Coverage with last architecture it gets to
1267
+
1265
1268
SmallVector<object::BuildID> FoundBinaryIDs;
1266
1269
for (const auto &File : llvm::enumerate (ObjectFilenames)) {
1267
1270
if (Error E = loadFromFile (File.value (), GetArch (File.index ()),
1268
1271
CompilationDir, ProfileReaderRef, *Coverage,
1269
- DataFound, &FoundBinaryIDs))
1272
+ DataFound, &FoundBinaryIDs, ObjectFilenames[File. index ()] ))
1270
1273
return std::move (E);
1271
1274
}
1272
1275
1276
+ // I beleive there is an error in this area of code, it's iterating through all arch's of the object files
1277
+ // but its only filling *Coverage with last architecture it gets to
1278
+
1273
1279
if (BIDFetcher) {
1274
1280
std::vector<object::BuildID> ProfileBinaryIDs;
1275
1281
if (ProfileReader)
@@ -1508,19 +1514,24 @@ class SegmentBuilder {
1508
1514
}
1509
1515
1510
1516
// / Combine counts of regions which cover the same area.
1517
+ // [(3:12, 10:1), (4:1, 6:7), (6:7, 8:1)]
1511
1518
static ArrayRef<CountedRegion>
1512
1519
combineRegions (MutableArrayRef<CountedRegion> Regions) {
1513
1520
if (Regions.empty ())
1514
1521
return Regions;
1522
+
1523
+
1515
1524
auto Active = Regions.begin ();
1516
1525
auto End = Regions.end ();
1517
1526
for (auto I = Regions.begin () + 1 ; I != End; ++I) {
1518
- if (Active->startLoc () != I->startLoc () ||
1519
- Active->endLoc () != I->endLoc ()) {
1527
+ if (Active->startLoc () != I->startLoc () || Active->endLoc () != I->endLoc ()) {
1520
1528
// Shift to the next region.
1521
1529
++Active;
1522
- if (Active != I)
1530
+ if (Active != I){
1523
1531
*Active = *I;
1532
+ // Active->ExecutionCount = 1;
1533
+ // Active->Kind = CounterMappingRegion::CodeRegion;
1534
+ }
1524
1535
continue ;
1525
1536
}
1526
1537
// Merge duplicate region.
@@ -1549,6 +1560,29 @@ class SegmentBuilder {
1549
1560
SegmentBuilder Builder (Segments);
1550
1561
1551
1562
sortNestedRegions (Regions);
1563
+
1564
+ for (auto *I = Regions.begin (); I != Regions.end (); ++I){
1565
+ bool FoundMatchInOtherBinary = false ;
1566
+ for (auto *J = I + 1 ; J != Regions.end (); ++J){
1567
+ if (I->ObjectFilename != J->ObjectFilename &&
1568
+ J->Kind == CounterMappingRegion::SkippedRegion
1569
+ && I->Kind != CounterMappingRegion::SkippedRegion &&
1570
+ J->startLoc () >= I->startLoc () && J->endLoc () <= I->endLoc ()){
1571
+ for (auto *K = J + 1 ; K != Regions.end (); ++K){
1572
+ if (K->ObjectFilename == I->ObjectFilename &&
1573
+ J->startLoc () == K->startLoc () && J->endLoc () == K->endLoc ()){
1574
+ FoundMatchInOtherBinary = true ;
1575
+ }
1576
+ }
1577
+ if (!FoundMatchInOtherBinary){
1578
+ J->Kind = I->Kind ;
1579
+ J->ExecutionCount = I->ExecutionCount ;
1580
+ }
1581
+ }
1582
+ }
1583
+ }
1584
+
1585
+
1552
1586
ArrayRef<CountedRegion> CombinedRegions = combineRegions (Regions);
1553
1587
1554
1588
LLVM_DEBUG ({
0 commit comments