r257092 - [PGO] Simplify coverage mapping lowering
Xinliang David Li via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 7 12:05:56 PST 2016
Author: davidxl
Date: Thu Jan 7 14:05:55 2016
New Revision: 257092
URL: http://llvm.org/viewvc/llvm-project?rev=257092&view=rev
Log:
[PGO] Simplify coverage mapping lowering
Coverage mapping data may reference names of functions
that are skipped by FE (e.g, unused inline functions). Since
those functions are skipped, normal instr-prof function lowering
pass won't put those names in the right section, so special
handling is needed to walk through coverage mapping structure
and recollect the references.
With this patch, only names that are skipped are processed. This
simplifies the lowering code and it no longer needs to make
assumptions coverage mapping data layout. It should also be
more efficient.
Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/lib/CodeGen/CoverageMappingGen.h
Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=257092&r1=257091&r2=257092&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Thu Jan 7 14:05:55 2016
@@ -699,7 +699,7 @@ CodeGenPGO::emitEmptyCounterMapping(cons
setFuncName(Name, Linkage);
CGM.getCoverageMapping()->addFunctionMappingRecord(
- FuncNameVar, FuncName, FunctionHash, CoverageMapping);
+ FuncNameVar, FuncName, FunctionHash, CoverageMapping, false);
}
void CodeGenPGO::computeRegionCounts(const Decl *D) {
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=257092&r1=257091&r2=257092&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Thu Jan 7 14:05:55 2016
@@ -910,11 +910,11 @@ static void dump(llvm::raw_ostream &OS,
}
void CoverageMappingModuleGen::addFunctionMappingRecord(
- llvm::GlobalVariable *NamePtr, StringRef NameValue,
- uint64_t FuncHash, const std::string &CoverageMapping) {
+ llvm::GlobalVariable *NamePtr, StringRef NameValue, uint64_t FuncHash,
+ const std::string &CoverageMapping, bool isUsed) {
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
if (!FunctionRecordTy) {
- #define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) LLVMType,
+#define COVMAP_FUNC_RECORD(Type, LLVMType, Name, Init) LLVMType,
llvm::Type *FunctionRecordTypes[] = {
#include "llvm/ProfileData/InstrProfData.inc"
};
@@ -929,6 +929,9 @@ void CoverageMappingModuleGen::addFuncti
};
FunctionRecords.push_back(llvm::ConstantStruct::get(
FunctionRecordTy, makeArrayRef(FunctionRecordVals)));
+ if (!isUsed)
+ FunctionNames.push_back(
+ llvm::ConstantExpr::getBitCast(NamePtr, llvm::Type::getInt8PtrTy(Ctx)));
CoverageMappings += CoverageMapping;
if (CGM.getCodeGenOpts().DumpCoverageMapping) {
@@ -1023,6 +1026,17 @@ void CoverageMappingModuleGen::emit() {
// Make sure the data doesn't get deleted.
CGM.addUsedGlobal(CovData);
+ // Create the deferred function records array
+ if (!FunctionNames.empty()) {
+ 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) {
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.h?rev=257092&r1=257091&r2=257092&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.h (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.h Thu Jan 7 14:05:55 2016
@@ -54,6 +54,7 @@ class CoverageMappingModuleGen {
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;
@@ -70,7 +71,8 @@ public:
void addFunctionMappingRecord(llvm::GlobalVariable *FunctionName,
StringRef FunctionNameValue,
uint64_t FunctionHash,
- const std::string &CoverageMapping);
+ const std::string &CoverageMapping,
+ bool isUsed = true);
/// \brief Emit the coverage mapping data for a translation unit.
void emit();
More information about the cfe-commits
mailing list