Skip to content

Commit fbf8b95

Browse files
committed
Revert "[Coverage] Store compilation dir separately in coverage mapping"
This reverts commit 97ec8fa since the test is failing on some bots.
1 parent 8e01e2e commit fbf8b95

File tree

19 files changed

+94
-148
lines changed

19 files changed

+94
-148
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
172172
/// The string to embed in debug information as the current working directory.
173173
std::string DebugCompilationDir;
174174

175-
/// The string to embed in coverage mapping as the current working directory.
176-
std::string ProfileCompilationDir;
177-
178175
/// The string to embed in the debug information for the compile unit, if
179176
/// non-empty.
180177
std::string DwarfDebugFlags;

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,6 @@ def fdebug_compilation_dir_EQ : Joined<["-"], "fdebug-compilation-dir=">,
11031103
def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
11041104
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>,
11051105
Alias<fdebug_compilation_dir_EQ>;
1106-
def fprofile_compilation_dir_EQ : Joined<["-"], "fprofile-compilation-dir=">,
1107-
Group<f_Group>, Flags<[CC1Option, CC1AsOption, CoreOption]>,
1108-
HelpText<"The compilation directory to embed in the coverage mapping.">,
1109-
MarshallingInfoString<CodeGenOpts<"ProfileCompilationDir">>;
11101106
defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
11111107
CodeGenOpts<"DebugInfoForProfiling">, DefaultFalse,
11121108
PosFlag<SetTrue, [CC1Option], "Emit extra debug info to make sample profile more accurate">,

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,17 +1606,9 @@ CoverageMappingModuleGen::CoverageMappingModuleGen(
16061606
ProfilePrefixMap = CGM.getCodeGenOpts().ProfilePrefixMap;
16071607
}
16081608

1609-
std::string CoverageMappingModuleGen::getCurrentDirname() {
1610-
if (!CGM.getCodeGenOpts().ProfileCompilationDir.empty())
1611-
return CGM.getCodeGenOpts().ProfileCompilationDir;
1612-
1613-
SmallString<256> CWD;
1614-
llvm::sys::fs::current_path(CWD);
1615-
return CWD.str().str();
1616-
}
1617-
16181609
std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {
16191610
llvm::SmallString<256> Path(Filename);
1611+
llvm::sys::fs::make_absolute(Path);
16201612
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
16211613
for (const auto &Entry : ProfilePrefixMap) {
16221614
if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
@@ -1697,17 +1689,18 @@ void CoverageMappingModuleGen::addFunctionMappingRecord(
16971689
// also processed by the CoverageMappingWriter which performs
16981690
// additional minimization operations such as reducing the number of
16991691
// expressions.
1700-
llvm::SmallVector<std::string, 16> FilenameStrs;
17011692
std::vector<StringRef> Filenames;
17021693
std::vector<CounterExpression> Expressions;
17031694
std::vector<CounterMappingRegion> Regions;
1704-
FilenameStrs.resize(FileEntries.size() + 1);
1705-
FilenameStrs[0] = normalizeFilename(getCurrentDirname());
1695+
llvm::SmallVector<std::string, 16> FilenameStrs;
1696+
llvm::SmallVector<StringRef, 16> FilenameRefs;
1697+
FilenameStrs.resize(FileEntries.size());
1698+
FilenameRefs.resize(FileEntries.size());
17061699
for (const auto &Entry : FileEntries) {
17071700
auto I = Entry.second;
17081701
FilenameStrs[I] = normalizeFilename(Entry.first->getName());
1702+
FilenameRefs[I] = FilenameStrs[I];
17091703
}
1710-
ArrayRef<std::string> FilenameRefs = llvm::makeArrayRef(FilenameStrs);
17111704
RawCoverageMappingReader Reader(CoverageMapping, FilenameRefs, Filenames,
17121705
Expressions, Regions);
17131706
if (Reader.read())
@@ -1724,18 +1717,19 @@ void CoverageMappingModuleGen::emit() {
17241717

17251718
// Create the filenames and merge them with coverage mappings
17261719
llvm::SmallVector<std::string, 16> FilenameStrs;
1727-
FilenameStrs.resize(FileEntries.size() + 1);
1728-
// The first filename is the current working directory.
1729-
FilenameStrs[0] = getCurrentDirname();
1720+
llvm::SmallVector<StringRef, 16> FilenameRefs;
1721+
FilenameStrs.resize(FileEntries.size());
1722+
FilenameRefs.resize(FileEntries.size());
17301723
for (const auto &Entry : FileEntries) {
17311724
auto I = Entry.second;
17321725
FilenameStrs[I] = normalizeFilename(Entry.first->getName());
1726+
FilenameRefs[I] = FilenameStrs[I];
17331727
}
17341728

17351729
std::string Filenames;
17361730
{
17371731
llvm::raw_string_ostream OS(Filenames);
1738-
CoverageFilenamesSectionWriter(FilenameStrs).write(OS);
1732+
CoverageFilenamesSectionWriter(FilenameRefs).write(OS);
17391733
}
17401734
auto *FilenamesVal =
17411735
llvm::ConstantDataArray::getString(Ctx, Filenames, false);
@@ -1793,7 +1787,7 @@ unsigned CoverageMappingModuleGen::getFileID(const FileEntry *File) {
17931787
auto It = FileEntries.find(File);
17941788
if (It != FileEntries.end())
17951789
return It->second;
1796-
unsigned FileID = FileEntries.size() + 1;
1790+
unsigned FileID = FileEntries.size();
17971791
FileEntries.insert(std::make_pair(File, FileID));
17981792
return FileID;
17991793
}

clang/lib/CodeGen/CoverageMappingGen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class CoverageMappingModuleGen {
9595
std::vector<FunctionInfo> FunctionRecords;
9696
std::map<std::string, std::string> ProfilePrefixMap;
9797

98-
std::string getCurrentDirname();
9998
std::string normalizeFilename(StringRef Filename);
10099

101100
/// Emit a function record.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,13 +858,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
858858
CmdArgs.push_back("-fcoverage-mapping");
859859
}
860860

861-
if (Arg *A = Args.getLastArg(options::OPT_fprofile_compilation_dir_EQ)) {
862-
A->render(Args, CmdArgs);
863-
} else if (llvm::ErrorOr<std::string> CWD =
864-
D.getVFS().getCurrentWorkingDirectory()) {
865-
Args.MakeArgString("-fprofile-compilation-dir=" + *CWD);
866-
}
867-
868861
if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
869862
auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
870863
if (!Args.hasArg(options::OPT_coverage))

clang/test/CodeGen/profile-compilation-dir.c

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp %S/Inputs/../abspath.cpp -o - | FileCheck -check-prefix=RMDOTS %s
22

3-
// RMDOTS: @__llvm_coverage_mapping = {{.*}}"\02
3+
// RMDOTS: @__llvm_coverage_mapping = {{.*}}"\01
44
// RMDOTS-NOT: Inputs
55
// RMDOTS: "
66

77
// RUN: mkdir -p %t/test && cd %t/test
88
// RUN: echo "void f1() {}" > f1.c
9-
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp %t/test/f1.c -o - | FileCheck -check-prefix=ABSPATH %s
9+
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp ../test/f1.c -o - | FileCheck -check-prefix=RELPATH %s
1010

11-
// RELPATH: @__llvm_coverage_mapping = {{.*}}"\02
12-
// RELPATH: {{..(/|\\\\)test(/|\\\\)f1}}.c
11+
// RELPATH: @__llvm_coverage_mapping = {{.*}}"\01
12+
// RELPATH: {{[/\\].*(/|\\\\)test(/|\\\\)f1}}.c
1313
// RELPATH: "
1414

15-
// ABSPATH: @__llvm_coverage_mapping = {{.*}}"\02
16-
// ABSPATH: {{[/\\].*(/|\\\\)test(/|\\\\)f1}}.c
17-
// ABSPATH: "
18-
1915
void f1() {}

clang/test/Profile/profile-prefix-map.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
// RUN: echo "void f1() {}" > %t/root/nested/profile-prefix-map.c
66
// RUN: cd %t/root
77

8-
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s
8+
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c nested/profile-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s
99
//
10-
// ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\02.*root.*nested.*profile-prefix-map\.c}}
10+
// ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\01.*root.*nested.*profile-prefix-map\.c}}
1111

12-
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c ../root/nested/profile-prefix-map.c -o - | FileCheck --check-prefix=RELATIVE %s
12+
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c nested/profile-prefix-map.c -fprofile-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s --implicit-check-not=root
1313
//
14-
// RELATIVE: @__llvm_coverage_mapping = {{.*"\\02.*}}..{{/|\\+}}root{{/|\\+}}nested{{.*profile-prefix-map\.c}}
15-
16-
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -fprofile-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s
17-
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c ../root/nested/profile-prefix-map.c -fprofile-prefix-map=../root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s
18-
// PROFILE-PREFIX-MAP: @__llvm_coverage_mapping = {{.*"\\02.*}}.{{/|\\+}}nested{{.*profile-prefix-map\.c}}
14+
// PROFILE-PREFIX-MAP: @__llvm_coverage_mapping = {{.*"\\01[^/]*}}.{{/|\\+}}nested{{.*profile-prefix-map\.c}}

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
649649
/* Indexed profile format version (start from 1). */
650650
#define INSTR_PROF_INDEX_VERSION 7
651651
/* Coverage mapping format version (start from 0). */
652-
#define INSTR_PROF_COVMAP_VERSION 5
652+
#define INSTR_PROF_COVMAP_VERSION 4
653653

654654
/* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
655655
* version for other variants of profile. We set the lowest bit of the upper 8

llvm/docs/CoverageMappingFormat.rst

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,7 @@ too deeply).
266266
[32 x i8] c"..." ; Encoded data (dissected later)
267267
}, section "__llvm_covmap", align 8
268268
269-
The current version of the format is version 6.
270-
271-
There is one difference between versions 6 and 5:
272-
273-
* The first entry in the filename list is the compilation directory. When the
274-
filename is relative, the compilation directory is combined with the relative
275-
path to get an absolute path. This can reduce size by omitting the duplicate
276-
prefix in filenames.
277-
278-
There is one difference between versions 5 and 4:
269+
The current version of the format is version 5. There is one difference from version 4:
279270

280271
* The notion of branch region has been introduced along with a corresponding
281272
region kind. Branch regions encode two counters, one to track how many

llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,10 +996,7 @@ enum CovMapVersion {
996996
Version4 = 3,
997997
// Branch regions referring to two counters are added
998998
Version5 = 4,
999-
// Compilation directory is stored separately and combined with relative
1000-
// filenames to produce an absolute file path.
1001-
Version6 = 5,
1002-
// The current version is Version6.
999+
// The current version is Version5.
10031000
CurrentVersion = INSTR_PROF_COVMAP_VERSION
10041001
};
10051002

llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ class RawCoverageMappingDummyChecker : public RawCoverageReader {
125125

126126
/// Reader for the raw coverage mapping data.
127127
class RawCoverageMappingReader : public RawCoverageReader {
128-
ArrayRef<std::string> &TranslationUnitFilenames;
128+
ArrayRef<StringRef> TranslationUnitFilenames;
129129
std::vector<StringRef> &Filenames;
130130
std::vector<CounterExpression> &Expressions;
131131
std::vector<CounterMappingRegion> &MappingRegions;
132132

133133
public:
134134
RawCoverageMappingReader(StringRef MappingData,
135-
ArrayRef<std::string> &TranslationUnitFilenames,
135+
ArrayRef<StringRef> TranslationUnitFilenames,
136136
std::vector<StringRef> &Filenames,
137137
std::vector<CounterExpression> &Expressions,
138138
std::vector<CounterMappingRegion> &MappingRegions)
@@ -174,8 +174,10 @@ class BinaryCoverageReader : public CoverageMappingReader {
174174
FilenamesBegin(FilenamesBegin), FilenamesSize(FilenamesSize) {}
175175
};
176176

177+
using DecompressedData = std::vector<std::unique_ptr<SmallVector<char, 0>>>;
178+
177179
private:
178-
std::vector<std::string> Filenames;
180+
std::vector<StringRef> Filenames;
179181
std::vector<ProfileMappingRecord> MappingRecords;
180182
InstrProfSymtab ProfileNames;
181183
size_t CurrentRecord = 0;
@@ -188,6 +190,10 @@ class BinaryCoverageReader : public CoverageMappingReader {
188190
// D69471, which can split up function records into multiple sections on ELF.
189191
std::string FuncRecords;
190192

193+
// Used to tie the lifetimes of decompressed strings to the lifetime of this
194+
// BinaryCoverageReader instance.
195+
DecompressedData Decompressed;
196+
191197
BinaryCoverageReader(std::string &&FuncRecords)
192198
: FuncRecords(std::move(FuncRecords)) {}
193199

@@ -210,20 +216,20 @@ class BinaryCoverageReader : public CoverageMappingReader {
210216

211217
/// Reader for the raw coverage filenames.
212218
class RawCoverageFilenamesReader : public RawCoverageReader {
213-
std::vector<std::string> &Filenames;
219+
std::vector<StringRef> &Filenames;
214220

215221
// Read an uncompressed sequence of filenames.
216-
Error readUncompressed(CovMapVersion Version, uint64_t NumFilenames);
222+
Error readUncompressed(uint64_t NumFilenames);
217223

218224
public:
219-
RawCoverageFilenamesReader(StringRef Data,
220-
std::vector<std::string> &Filenames)
225+
RawCoverageFilenamesReader(StringRef Data, std::vector<StringRef> &Filenames)
221226
: RawCoverageReader(Data), Filenames(Filenames) {}
222227
RawCoverageFilenamesReader(const RawCoverageFilenamesReader &) = delete;
223228
RawCoverageFilenamesReader &
224229
operator=(const RawCoverageFilenamesReader &) = delete;
225230

226-
Error read(CovMapVersion Version);
231+
Error read(CovMapVersion Version,
232+
BinaryCoverageReader::DecompressedData &Decompressed);
227233
};
228234

229235
} // end namespace coverage

llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ namespace coverage {
2727
/// Writer of the filenames section for the instrumentation
2828
/// based code coverage.
2929
class CoverageFilenamesSectionWriter {
30-
ArrayRef<std::string> Filenames;
30+
ArrayRef<StringRef> Filenames;
3131

3232
public:
33-
CoverageFilenamesSectionWriter(ArrayRef<std::string> Filenames);
33+
CoverageFilenamesSectionWriter(ArrayRef<StringRef> Filenames);
3434

3535
/// Write encoded filenames to the given output stream. If \p Compress is
3636
/// true, attempt to compress the filenames.

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
649649
/* Indexed profile format version (start from 1). */
650650
#define INSTR_PROF_INDEX_VERSION 7
651651
/* Coverage mapping format version (start from 0). */
652-
#define INSTR_PROF_COVMAP_VERSION 5
652+
#define INSTR_PROF_COVMAP_VERSION 4
653653

654654
/* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
655655
* version for other variants of profile. We set the lowest bit of the upper 8

0 commit comments

Comments
 (0)