davidxl created this revision.
davidxl added a reviewer: vsk.
davidxl added a subscriber: cfe-commits.
The names referenced by the coverage data may be associated with functions that
are never emitted by Clang. That means those PGO names won't be materialized
into the __llvm_prf_names section during instr-prof lowering. To make sure
those names are emitted, the lowering pass will need to go through the coverage
map global variable and check the referenced names.
The lowering code makes assumption about the layout of the coverage map and
function record data which is error prone. Besides, in the near future, when
name compression is implemented, the name references won't be available from
the coverage data anymore.
In this patch, the referenced names are explicitly recorded in an internal
global var and passed to the middle end. This simplifies the lowering code and
also make it possible to do name compression. This is part-2 of the patch.
Part-1 is http://reviews.llvm.org/D15852
http://reviews.llvm.org/D15853
Files:
lib/CodeGen/CoverageMappingGen.cpp
lib/CodeGen/CoverageMappingGen.h
Index: lib/CodeGen/CoverageMappingGen.h
===================================================================
--- lib/CodeGen/CoverageMappingGen.h
+++ lib/CodeGen/CoverageMappingGen.h
@@ -54,6 +54,7 @@
CoverageSourceInfo &SourceInfo;
llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries;
std::vector<llvm::Constant *> FunctionRecords;
+ std::vector<llvm::Constant *> FunctionNames;
llvm::StructType *FunctionRecordTy;
std::string CoverageMappings;
Index: lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -929,6 +929,8 @@
};
FunctionRecords.push_back(llvm::ConstantStruct::get(
FunctionRecordTy, makeArrayRef(FunctionRecordVals)));
+ FunctionNames.push_back(
+ llvm::ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)));
CoverageMappings += CoverageMapping;
if (CGM.getCodeGenOpts().DumpCoverageMapping) {
@@ -1023,6 +1025,15 @@
// Make sure the data doesn't get deleted.
CGM.addUsedGlobal(CovData);
+ // Create the deferred function records array
+ auto NamesArrTy =
+ llvm::ArrayType::get(llvm::Type::getInt8PtrTy(Ctx),
FunctionNames.size());
+ auto NamesArrVal = llvm::ConstantArray::get(NamesArrTy, FunctionNames);
+ // This variable will *NOT* be emitted to the object file. It is used
+ // to pass the list of names referenced to codegen.
+ new llvm::GlobalVariable(CGM.getModule(), NamesArrTy, true,
+ llvm::GlobalValue::InternalLinkage, NamesArrVal,
+ llvm::getCoverageNamesVarName());
}
unsigned CoverageMappingModuleGen::getFileID(const FileEntry *File) {
Index: lib/CodeGen/CoverageMappingGen.h
===================================================================
--- lib/CodeGen/CoverageMappingGen.h
+++ lib/CodeGen/CoverageMappingGen.h
@@ -54,6 +54,7 @@
CoverageSourceInfo &SourceInfo;
llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries;
std::vector<llvm::Constant *> FunctionRecords;
+ std::vector<llvm::Constant *> FunctionNames;
llvm::StructType *FunctionRecordTy;
std::string CoverageMappings;
Index: lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -929,6 +929,8 @@
};
FunctionRecords.push_back(llvm::ConstantStruct::get(
FunctionRecordTy, makeArrayRef(FunctionRecordVals)));
+ FunctionNames.push_back(
+ llvm::ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)));
CoverageMappings += CoverageMapping;
if (CGM.getCodeGenOpts().DumpCoverageMapping) {
@@ -1023,6 +1025,15 @@
// Make sure the data doesn't get deleted.
CGM.addUsedGlobal(CovData);
+ // Create the deferred function records array
+ auto NamesArrTy =
+ llvm::ArrayType::get(llvm::Type::getInt8PtrTy(Ctx), FunctionNames.size());
+ auto NamesArrVal = llvm::ConstantArray::get(NamesArrTy, FunctionNames);
+ // This variable will *NOT* be emitted to the object file. It is used
+ // to pass the list of names referenced to codegen.
+ new llvm::GlobalVariable(CGM.getModule(), NamesArrTy, true,
+ llvm::GlobalValue::InternalLinkage, NamesArrVal,
+ llvm::getCoverageNamesVarName());
}
unsigned CoverageMappingModuleGen::getFileID(const FileEntry *File) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits