@@ -823,8 +823,7 @@ class MCDCDecisionRecorder {
823
823
824
824
Error CoverageMapping::loadFunctionRecord (
825
825
const CoverageMappingRecord &Record,
826
- const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
827
- &ProfileReader) {
826
+ IndexedInstrProfReader &ProfileReader) {
828
827
StringRef OrigFuncName = Record.FunctionName ;
829
828
if (OrigFuncName.empty ())
830
829
return make_error<CoverageMapError>(coveragemap_error::malformed,
@@ -838,44 +837,35 @@ Error CoverageMapping::loadFunctionRecord(
838
837
CounterMappingContext Ctx (Record.Expressions );
839
838
840
839
std::vector<uint64_t > Counts;
841
- if (ProfileReader) {
842
- if (Error E = ProfileReader.value ().get ().getFunctionCounts (
843
- Record.FunctionName , Record.FunctionHash , Counts)) {
844
- instrprof_error IPE = std::get<0 >(InstrProfError::take (std::move (E)));
845
- if (IPE == instrprof_error::hash_mismatch) {
846
- FuncHashMismatches.emplace_back (std::string (Record.FunctionName ),
847
- Record.FunctionHash );
848
- return Error::success ();
849
- }
850
- if (IPE != instrprof_error::unknown_function)
851
- return make_error<InstrProfError>(IPE);
852
- Counts.assign (getMaxCounterID (Ctx, Record) + 1 , 0 );
840
+ if (Error E = ProfileReader.getFunctionCounts (Record.FunctionName ,
841
+ Record.FunctionHash , Counts)) {
842
+ instrprof_error IPE = std::get<0 >(InstrProfError::take (std::move (E)));
843
+ if (IPE == instrprof_error::hash_mismatch) {
844
+ FuncHashMismatches.emplace_back (std::string (Record.FunctionName ),
845
+ Record.FunctionHash );
846
+ return Error::success ();
853
847
}
854
- } else {
848
+ if (IPE != instrprof_error::unknown_function)
849
+ return make_error<InstrProfError>(IPE);
855
850
Counts.assign (getMaxCounterID (Ctx, Record) + 1 , 0 );
856
851
}
857
852
Ctx.setCounts (Counts);
858
853
859
854
bool IsVersion11 =
860
- ProfileReader && ProfileReader.value ().get ().getVersion () <
861
- IndexedInstrProf::ProfVersion::Version12;
855
+ ProfileReader.getVersion () < IndexedInstrProf::ProfVersion::Version12;
862
856
863
857
BitVector Bitmap;
864
- if (ProfileReader) {
865
- if (Error E = ProfileReader.value ().get ().getFunctionBitmap (
866
- Record.FunctionName , Record.FunctionHash , Bitmap)) {
867
- instrprof_error IPE = std::get<0 >(InstrProfError::take (std::move (E)));
868
- if (IPE == instrprof_error::hash_mismatch) {
869
- FuncHashMismatches.emplace_back (std::string (Record.FunctionName ),
870
- Record.FunctionHash );
871
- return Error::success ();
872
- }
873
- if (IPE != instrprof_error::unknown_function)
874
- return make_error<InstrProfError>(IPE);
875
- Bitmap = BitVector (getMaxBitmapSize (Record, IsVersion11));
858
+ if (Error E = ProfileReader.getFunctionBitmap (Record.FunctionName ,
859
+ Record.FunctionHash , Bitmap)) {
860
+ instrprof_error IPE = std::get<0 >(InstrProfError::take (std::move (E)));
861
+ if (IPE == instrprof_error::hash_mismatch) {
862
+ FuncHashMismatches.emplace_back (std::string (Record.FunctionName ),
863
+ Record.FunctionHash );
864
+ return Error::success ();
876
865
}
877
- } else {
878
- Bitmap = BitVector (getMaxBitmapSize (Record, false ));
866
+ if (IPE != instrprof_error::unknown_function)
867
+ return make_error<InstrProfError>(IPE);
868
+ Bitmap = BitVector (getMaxBitmapSize (Record, IsVersion11));
879
869
}
880
870
Ctx.setBitmap (std::move (Bitmap));
881
871
@@ -969,14 +959,10 @@ Error CoverageMapping::loadFunctionRecord(
969
959
// of CoverageMappingReader instances.
970
960
Error CoverageMapping::loadFromReaders (
971
961
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
972
- std::optional<std::reference_wrapper<IndexedInstrProfReader>>
973
- &ProfileReader,
974
- CoverageMapping &Coverage) {
975
- assert (!Coverage.SingleByteCoverage || !ProfileReader ||
976
- *Coverage.SingleByteCoverage ==
977
- ProfileReader.value ().get ().hasSingleByteCoverage ());
978
- Coverage.SingleByteCoverage =
979
- !ProfileReader || ProfileReader.value ().get ().hasSingleByteCoverage ();
962
+ IndexedInstrProfReader &ProfileReader, CoverageMapping &Coverage) {
963
+ assert (!Coverage.SingleByteCoverage ||
964
+ *Coverage.SingleByteCoverage == ProfileReader.hasSingleByteCoverage ());
965
+ Coverage.SingleByteCoverage = ProfileReader.hasSingleByteCoverage ();
980
966
for (const auto &CoverageReader : CoverageReaders) {
981
967
for (auto RecordOrErr : *CoverageReader) {
982
968
if (Error E = RecordOrErr.takeError ())
@@ -991,8 +977,7 @@ Error CoverageMapping::loadFromReaders(
991
977
992
978
Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load (
993
979
ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
994
- std::optional<std::reference_wrapper<IndexedInstrProfReader>>
995
- &ProfileReader) {
980
+ IndexedInstrProfReader &ProfileReader) {
996
981
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping ());
997
982
if (Error E = loadFromReaders (CoverageReaders, ProfileReader, *Coverage))
998
983
return std::move (E);
@@ -1001,19 +986,18 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
1001
986
1002
987
// If E is a no_data_found error, returns success. Otherwise returns E.
1003
988
static Error handleMaybeNoDataFoundError (Error E) {
1004
- return handleErrors (std::move (E), [](const CoverageMapError &CME) {
1005
- if (CME.get () == coveragemap_error::no_data_found)
1006
- return static_cast <Error>(Error::success ());
1007
- return make_error<CoverageMapError>(CME.get (), CME.getMessage ());
1008
- });
989
+ return handleErrors (
990
+ std::move (E), [](const CoverageMapError &CME) {
991
+ if (CME.get () == coveragemap_error::no_data_found)
992
+ return static_cast <Error>(Error::success ());
993
+ return make_error<CoverageMapError>(CME.get (), CME.getMessage ());
994
+ });
1009
995
}
1010
996
1011
997
Error CoverageMapping::loadFromFile (
1012
998
StringRef Filename, StringRef Arch, StringRef CompilationDir,
1013
- std::optional<std::reference_wrapper<IndexedInstrProfReader>>
1014
- &ProfileReader,
1015
- CoverageMapping &Coverage, bool &DataFound,
1016
- SmallVectorImpl<object::BuildID> *FoundBinaryIDs) {
999
+ IndexedInstrProfReader &ProfileReader, CoverageMapping &Coverage,
1000
+ bool &DataFound, SmallVectorImpl<object::BuildID> *FoundBinaryIDs) {
1017
1001
auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN (
1018
1002
Filename, /* IsText=*/ false , /* RequiresNullTerminator=*/ false );
1019
1003
if (std::error_code EC = CovMappingBufOrErr.getError ())
@@ -1049,23 +1033,13 @@ Error CoverageMapping::loadFromFile(
1049
1033
}
1050
1034
1051
1035
Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load (
1052
- ArrayRef<StringRef> ObjectFilenames,
1053
- std::optional<StringRef> ProfileFilename, vfs::FileSystem &FS,
1054
- ArrayRef<StringRef> Arches, StringRef CompilationDir,
1036
+ ArrayRef<StringRef> ObjectFilenames, StringRef ProfileFilename,
1037
+ vfs::FileSystem &FS, ArrayRef<StringRef> Arches, StringRef CompilationDir,
1055
1038
const object::BuildIDFetcher *BIDFetcher, bool CheckBinaryIDs) {
1056
- std::unique_ptr<IndexedInstrProfReader> ProfileReader;
1057
- if (ProfileFilename) {
1058
- auto ProfileReaderOrErr =
1059
- IndexedInstrProfReader::create (ProfileFilename.value (), FS);
1060
- if (Error E = ProfileReaderOrErr.takeError ())
1061
- return createFileError (ProfileFilename.value (), std::move (E));
1062
- ProfileReader = std::move (ProfileReaderOrErr.get ());
1063
- }
1064
- auto ProfileReaderRef =
1065
- ProfileReader
1066
- ? std::optional<std::reference_wrapper<IndexedInstrProfReader>>(
1067
- *ProfileReader)
1068
- : std::nullopt;
1039
+ auto ProfileReaderOrErr = IndexedInstrProfReader::create (ProfileFilename, FS);
1040
+ if (Error E = ProfileReaderOrErr.takeError ())
1041
+ return createFileError (ProfileFilename, std::move (E));
1042
+ auto ProfileReader = std::move (ProfileReaderOrErr.get ());
1069
1043
auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping ());
1070
1044
bool DataFound = false ;
1071
1045
@@ -1079,17 +1053,16 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
1079
1053
1080
1054
SmallVector<object::BuildID> FoundBinaryIDs;
1081
1055
for (const auto &File : llvm::enumerate (ObjectFilenames)) {
1082
- if (Error E = loadFromFile (File. value (), GetArch (File. index ()),
1083
- CompilationDir, ProfileReaderRef, *Coverage ,
1084
- DataFound, &FoundBinaryIDs))
1056
+ if (Error E =
1057
+ loadFromFile (File. value (), GetArch (File. index ()), CompilationDir ,
1058
+ *ProfileReader, *Coverage, DataFound, &FoundBinaryIDs))
1085
1059
return std::move (E);
1086
1060
}
1087
1061
1088
1062
if (BIDFetcher) {
1089
1063
std::vector<object::BuildID> ProfileBinaryIDs;
1090
- if (ProfileReader)
1091
- if (Error E = ProfileReader->readBinaryIds (ProfileBinaryIDs))
1092
- return createFileError (ProfileFilename.value (), std::move (E));
1064
+ if (Error E = ProfileReader->readBinaryIds (ProfileBinaryIDs))
1065
+ return createFileError (ProfileFilename, std::move (E));
1093
1066
1094
1067
SmallVector<object::BuildIDRef> BinaryIDsToFetch;
1095
1068
if (!ProfileBinaryIDs.empty ()) {
@@ -1109,12 +1082,12 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
1109
1082
if (PathOpt) {
1110
1083
std::string Path = std::move (*PathOpt);
1111
1084
StringRef Arch = Arches.size () == 1 ? Arches.front () : StringRef ();
1112
- if (Error E = loadFromFile (Path, Arch, CompilationDir, ProfileReaderRef ,
1113
- *Coverage, DataFound))
1085
+ if (Error E = loadFromFile (Path, Arch, CompilationDir, *ProfileReader ,
1086
+ *Coverage, DataFound))
1114
1087
return std::move (E);
1115
1088
} else if (CheckBinaryIDs) {
1116
1089
return createFileError (
1117
- ProfileFilename. value () ,
1090
+ ProfileFilename,
1118
1091
createStringError (errc::no_such_file_or_directory,
1119
1092
" Missing binary ID: " +
1120
1093
llvm::toHex (BinaryID, /* LowerCase=*/ true )));
0 commit comments