llvm.org GIT mirror llvm / e72b881
[llvm-cov] Allow specifying distinct architectures for each loaded binary The coverage tool needs to know which slice to look at when it's handed a universal binary. Some projects need to look at aggregate coverage reports for a variety of slices in different binaries: this patch adds support for these kinds of projects to llvm-cov. rdar://problem/33579007 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309747 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
5 changed file(s) with 41 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
221221
222222 Enable or disable color output. By default this is autodetected.
223223
224 .. option:: -arch=
225
226 If the covered binary is a universal binary, select the architecture to use.
227 It is an error to specify an architecture that is not included in the
228 universal binary or to use an architecture that does not match a
229 non-universal binary.
224 .. option:: -arch=[*NAMES*]
225
226 Specify a list of architectures such that the Nth entry in the list
227 corresponds to the Nth specified binary. If the covered object is a universal
228 binary, this specifies the architecture to use. It is an error to specify an
229 architecture that is not included in the universal binary or to use an
230 architecture that does not match a non-universal binary.
230231
231232 .. option:: -name=
232233
448448 CoverageMapping(const CoverageMapping &) = delete;
449449 CoverageMapping &operator=(const CoverageMapping &) = delete;
450450
451 /// \brief Load the coverage mapping using the given readers.
451 /// Load the coverage mapping using the given readers.
452452 static Expected>
453453 load(ArrayRef> CoverageReaders,
454454 IndexedInstrProfReader &ProfileReader);
455455
456 /// Load the coverage mapping from the given object files and profile. If
457 /// \p Arches is non-empty, it must specify an architecture for each object.
456458 static Expected>
457459 load(ArrayRef ObjectFilenames, StringRef ProfileFilename,
458 StringRef Arch = StringRef());
460 ArrayRef Arches = None);
459461
460462 /// \brief The number of functions that couldn't have their profiles mapped.
461463 ///
259259
260260 Expected>
261261 CoverageMapping::load(ArrayRef ObjectFilenames,
262 StringRef ProfileFilename, StringRef Arch) {
262 StringRef ProfileFilename, ArrayRef Arches) {
263263 auto ProfileReaderOrErr = IndexedInstrProfReader::create(ProfileFilename);
264264 if (Error E = ProfileReaderOrErr.takeError())
265265 return std::move(E);
267267
268268 SmallVector, 4> Readers;
269269 SmallVector, 4> Buffers;
270 for (StringRef ObjectFilename : ObjectFilenames) {
271 auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
270 for (const auto &File : llvm::enumerate(ObjectFilenames)) {
271 auto CovMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(File.value());
272272 if (std::error_code EC = CovMappingBufOrErr.getError())
273273 return errorCodeToError(EC);
274 StringRef Arch = Arches.empty() ? StringRef() : Arches[File.index()];
274275 auto CoverageReaderOrErr =
275276 BinaryCoverageReader::create(CovMappingBufOrErr.get(), Arch);
276277 if (Error E = CoverageReaderOrErr.takeError())
66 // RUN: llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -filename-equivalence %s -arch x86_64 | FileCheck %s
77 // RUN: llvm-cov export %S/Inputs/universal-binary -instr-profile %t.profdata -arch x86_64 2>&1 | FileCheck %S/Inputs/universal-binary.json
88
9 // RUN: llvm-cov report %S/Inputs/universal-binary -arch x86_64 -object %S/Inputs/templateInstantiations.covmapping -arch i386 -instr-profile %t.profdata 2>&1 | FileCheck %s --check-prefix=COMBINED
10 // COMBINED: showTemplateInstantiations.cpp
11 // COMBINED-NEXT: universal-binary.c
912
1013 // RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -filename-equivalence %s -arch i386 2>&1 | FileCheck --check-prefix=WRONG-ARCH %s
1114 // WRONG-ARCH: Failed to load coverage
1215
16 // RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -filename-equivalence %s -arch definitly_a_made_up_architecture 2>&1 | FileCheck --check-prefix=MADE-UP-ARCH %s
17 // MADE-UP-ARCH: Unknown architecture: definitly_a_made_up_architecture
18
19 // RUN: not llvm-cov show %S/Inputs/universal-binary -instr-profile %t.profdata -filename-equivalence %s -arch=x86_64 -arch=x86_64 2>&1 | FileCheck --check-prefix=TOO-MANY-ARCH %s
20 // TOO-MANY-ARCH: Number of architectures doesn't match the number of objects
21 //
1322 // RUN: not llvm-cov report -instr-profile %t.profdata 2>&1 | FileCheck --check-prefix=MISSING-BINARY %s
1423 // MISSING-BINARY: No filenames specified!
132132 StringMap RemappedFilenames;
133133
134134 /// The architecture the coverage mapping data targets.
135 std::string CoverageArch;
135 std::vector CoverageArches;
136136
137137 /// A cache for demangled symbols.
138138 DemangleCache DC;
328328 warning("profile data may be out of date - object is newer",
329329 ObjectFilename);
330330 auto CoverageOrErr =
331 CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArch);
331 CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArches);
332332 if (Error E = CoverageOrErr.takeError()) {
333333 error("Failed to load coverage: " + toString(std::move(E)),
334334 join(ObjectFilenames.begin(), ObjectFilenames.end(), ", "));
498498 cl::desc(
499499 "File with the profile data obtained after an instrumented run"));
500500
501 cl::opt Arch(
502 "arch", cl::desc("architecture of the coverage mapping binary"));
501 cl::list Arches(
502 "arch", cl::desc("architectures of the coverage mapping binaries"));
503503
504504 cl::opt DebugDump("dump", cl::Optional,
505505 cl::desc("Show internal debug dump"));
631631 Filters.push_back(std::unique_ptr(StatFilterer));
632632 }
633633
634 if (!Arch.empty() &&
635 Triple(Arch).getArch() == llvm::Triple::ArchType::UnknownArch) {
636 error("Unknown architecture: " + Arch);
637 return 1;
638 }
639 CoverageArch = Arch;
634 if (!Arches.empty()) {
635 for (const std::string &Arch : Arches) {
636 if (Triple(Arch).getArch() == llvm::Triple::ArchType::UnknownArch) {
637 error("Unknown architecture: " + Arch);
638 return 1;
639 }
640 CoverageArches.emplace_back(Arch);
641 }
642 if (CoverageArches.size() != ObjectFilenames.size()) {
643 error("Number of architectures doesn't match the number of objects");
644 return 1;
645 }
646 }
640647
641648 for (const std::string &File : InputSourceFiles)
642649 collectPaths(File);