@@ -823,8 +823,7 @@ class MCDCDecisionRecorder {
823823
824824Error CoverageMapping::loadFunctionRecord (
825825 const CoverageMappingRecord &Record,
826- const std::optional<std::reference_wrapper<IndexedInstrProfReader>>
827- &ProfileReader) {
826+ IndexedInstrProfReader &ProfileReader) {
828827 StringRef OrigFuncName = Record.FunctionName ;
829828 if (OrigFuncName.empty ())
830829 return make_error<CoverageMapError>(coveragemap_error::malformed,
@@ -838,44 +837,35 @@ Error CoverageMapping::loadFunctionRecord(
838837 CounterMappingContext Ctx (Record.Expressions );
839838
840839 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 ();
853847 }
854- } else {
848+ if (IPE != instrprof_error::unknown_function)
849+ return make_error<InstrProfError>(IPE);
855850 Counts.assign (getMaxCounterID (Ctx, Record) + 1 , 0 );
856851 }
857852 Ctx.setCounts (Counts);
858853
859854 bool IsVersion11 =
860- ProfileReader && ProfileReader.value ().get ().getVersion () <
861- IndexedInstrProf::ProfVersion::Version12;
855+ ProfileReader.getVersion () < IndexedInstrProf::ProfVersion::Version12;
862856
863857 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 ();
876865 }
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));
879869 }
880870 Ctx.setBitmap (std::move (Bitmap));
881871
@@ -969,14 +959,10 @@ Error CoverageMapping::loadFunctionRecord(
969959// of CoverageMappingReader instances.
970960Error CoverageMapping::loadFromReaders (
971961 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 ();
980966 for (const auto &CoverageReader : CoverageReaders) {
981967 for (auto RecordOrErr : *CoverageReader) {
982968 if (Error E = RecordOrErr.takeError ())
@@ -991,8 +977,7 @@ Error CoverageMapping::loadFromReaders(
991977
992978Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load (
993979 ArrayRef<std::unique_ptr<CoverageMappingReader>> CoverageReaders,
994- std::optional<std::reference_wrapper<IndexedInstrProfReader>>
995- &ProfileReader) {
980+ IndexedInstrProfReader &ProfileReader) {
996981 auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping ());
997982 if (Error E = loadFromReaders (CoverageReaders, ProfileReader, *Coverage))
998983 return std::move (E);
@@ -1001,19 +986,18 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
1001986
1002987// If E is a no_data_found error, returns success. Otherwise returns E.
1003988static 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+ });
1009995}
1010996
1011997Error CoverageMapping::loadFromFile (
1012998 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) {
10171001 auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN (
10181002 Filename, /* IsText=*/ false , /* RequiresNullTerminator=*/ false );
10191003 if (std::error_code EC = CovMappingBufOrErr.getError ())
@@ -1049,23 +1033,13 @@ Error CoverageMapping::loadFromFile(
10491033}
10501034
10511035Expected<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,
10551038 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 ());
10691043 auto Coverage = std::unique_ptr<CoverageMapping>(new CoverageMapping ());
10701044 bool DataFound = false ;
10711045
@@ -1079,17 +1053,16 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
10791053
10801054 SmallVector<object::BuildID> FoundBinaryIDs;
10811055 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))
10851059 return std::move (E);
10861060 }
10871061
10881062 if (BIDFetcher) {
10891063 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));
10931066
10941067 SmallVector<object::BuildIDRef> BinaryIDsToFetch;
10951068 if (!ProfileBinaryIDs.empty ()) {
@@ -1109,12 +1082,12 @@ Expected<std::unique_ptr<CoverageMapping>> CoverageMapping::load(
11091082 if (PathOpt) {
11101083 std::string Path = std::move (*PathOpt);
11111084 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))
11141087 return std::move (E);
11151088 } else if (CheckBinaryIDs) {
11161089 return createFileError (
1117- ProfileFilename. value () ,
1090+ ProfileFilename,
11181091 createStringError (errc::no_such_file_or_directory,
11191092 " Missing binary ID: " +
11201093 llvm::toHex (BinaryID, /* LowerCase=*/ true )));
0 commit comments