From 5fbd1a333aa1a0b70903d036b98ea56c51ae5224 Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Wed, 10 Feb 2021 00:25:34 -0800 Subject: [Coverage] Store compilation dir separately in coverage mapping We currently always store absolute filenames in coverage mapping. This is problematic for several reasons. It poses a problem for distributed compilation as source location might vary across machines. We are also duplicating the path prefix potentially wasting space. This change modifies how we store filenames in coverage mapping. Rather than absolute paths, it stores the compilation directory and file paths as given to the compiler, either relative or absolute. Later when reading the coverage mapping information, we recombine relative paths with the working directory. This approach is similar to handling ofDW_AT_comp_dir in DWARF. Finally, we also provide a new option, -fprofile-compilation-dir akin to -fdebug-compilation-dir which can be used to manually override the compilation directory which is useful in distributed compilation cases. Differential Revision: https://reviews.llvm.org/D95753 --- llvm/unittests/ProfileData/CoverageMappingTest.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp') diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index cbe9c1e..44b7a13 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -129,6 +129,7 @@ struct InputFunctionCoverageData { struct CoverageMappingTest : ::testing::TestWithParam> { bool UseMultipleReaders; StringMap Files; + std::vector Filenames; std::vector InputFunctions; std::vector OutputFunctions; @@ -146,7 +147,7 @@ struct CoverageMappingTest : ::testing::TestWithParam> { auto R = Files.find(Name); if (R != Files.end()) return R->second; - unsigned Index = Files.size(); + unsigned Index = Files.size() + 1; Files.try_emplace(Name, Index); return Index; } @@ -200,11 +201,12 @@ struct CoverageMappingTest : ::testing::TestWithParam> { void readCoverageRegions(const std::string &Coverage, OutputFunctionCoverageData &Data) { - SmallVector Filenames(Files.size()); + Filenames.resize(Files.size() + 1); for (const auto &E : Files) - Filenames[E.getValue()] = E.getKey(); + Filenames[E.getValue()] = E.getKey().str(); std::vector Expressions; - RawCoverageMappingReader Reader(Coverage, Filenames, Data.Filenames, + ArrayRef FilenameRefs = llvm::makeArrayRef(Filenames); + RawCoverageMappingReader Reader(Coverage, FilenameRefs, Data.Filenames, Expressions, Data.Regions); EXPECT_THAT_ERROR(Reader.read(), Succeeded()); } @@ -895,7 +897,7 @@ INSTANTIATE_TEST_CASE_P(ParameterizedCovMapTest, CoverageMappingTest, std::pair({true, true})),); TEST(CoverageMappingTest, filename_roundtrip) { - std::vector Paths({"a", "b", "c", "d", "e"}); + std::vector Paths({"", "a", "b", "c", "d", "e"}); for (bool Compress : {false, true}) { std::string EncodedFilenames; @@ -905,16 +907,12 @@ TEST(CoverageMappingTest, filename_roundtrip) { Writer.write(OS, Compress); } - std::vector ReadFilenames; + std::vector ReadFilenames; RawCoverageFilenamesReader Reader(EncodedFilenames, ReadFilenames); - BinaryCoverageReader::DecompressedData Decompressed; - EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion, Decompressed), - Succeeded()); - if (!Compress) - ASSERT_EQ(Decompressed.size(), 0U); + EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion), Succeeded()); ASSERT_EQ(ReadFilenames.size(), Paths.size()); - for (unsigned I = 0; I < Paths.size(); ++I) + for (unsigned I = 1; I < Paths.size(); ++I) ASSERT_TRUE(ReadFilenames[I] == Paths[I]); } } -- cgit v1.1