aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2019-10-21 11:48:38 -0700
committerVedant Kumar <vsk@apple.com>2019-12-04 10:10:55 -0800
commite18531595bba495946aa52c0a16b9f9238cff8bc (patch)
tree489f93c6cda69f1e7255d0aa0fc596e466f30628 /clang/lib/CodeGen/CoverageMappingGen.h
parent[Gold Tests] Add missing target flag to X86 test (diff)
downloadllvm-project-e18531595bba495946aa52c0a16b9f9238cff8bc.tar.gz
llvm-project-e18531595bba495946aa52c0a16b9f9238cff8bc.tar.bz2
llvm-project-e18531595bba495946aa52c0a16b9f9238cff8bc.zip
[Coverage] Revise format to reduce binary size
Revise the coverage mapping format to reduce binary size by: 1. Naming function records and marking them `linkonce_odr`, and 2. Compressing filenames. This shrinks the size of llc's coverage segment by 82% (334MB -> 62MB) and speeds up end-to-end single-threaded report generation by 10%. For reference the compressed name data in llc is 81MB (__llvm_prf_names). Rationale for changes to the format: - With the current format, most coverage function records are discarded. E.g., more than 97% of the records in llc are *duplicate* placeholders for functions visible-but-not-used in TUs. Placeholders *are* used to show under-covered functions, but duplicate placeholders waste space. - We reached general consensus about giving (1) a try at the 2017 code coverage BoF [1]. The thinking was that using `linkonce_odr` to merge duplicates is simpler than alternatives like teaching build systems about a coverage-aware database/module/etc on the side. - Revising the format is expensive due to the backwards compatibility requirement, so we might as well compress filenames while we're at it. This shrinks the encoded filenames in llc by 86% (12MB -> 1.6MB). See CoverageMappingFormat.rst for the details on what exactly has changed. Fixes PR34533 [2], hopefully. [1] http://lists.llvm.org/pipermail/llvm-dev/2017-October/118428.html [2] https://bugs.llvm.org/show_bug.cgi?id=34533 Differential Revision: https://reviews.llvm.org/D69471
Diffstat (limited to 'clang/lib/CodeGen/CoverageMappingGen.h')
-rw-r--r--clang/lib/CodeGen/CoverageMappingGen.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CoverageMappingGen.h b/clang/lib/CodeGen/CoverageMappingGen.h
index 3bf51f590479..5d79d1e65670 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.h
+++ b/clang/lib/CodeGen/CoverageMappingGen.h
@@ -47,17 +47,27 @@ class CodeGenModule;
/// Organizes the cross-function state that is used while generating
/// code coverage mapping data.
class CoverageMappingModuleGen {
+ /// Information needed to emit a coverage record for a function.
+ struct FunctionInfo {
+ uint64_t NameHash;
+ uint64_t FuncHash;
+ std::string CoverageMapping;
+ bool IsUsed;
+ };
+
CodeGenModule &CGM;
CoverageSourceInfo &SourceInfo;
llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries;
- std::vector<llvm::Constant *> FunctionRecords;
std::vector<llvm::Constant *> FunctionNames;
- llvm::StructType *FunctionRecordTy;
- std::vector<std::string> CoverageMappings;
+ std::vector<FunctionInfo> FunctionRecords;
+
+ /// Emit a function record.
+ void emitFunctionMappingRecord(const FunctionInfo &Info,
+ uint64_t FilenamesRef);
public:
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
- : CGM(CGM), SourceInfo(SourceInfo), FunctionRecordTy(nullptr) {}
+ : CGM(CGM), SourceInfo(SourceInfo) {}
CoverageSourceInfo &getSourceInfo() const {
return SourceInfo;