Skip to content

Commit

Permalink
Coverage Mapping: store function's hash in coverage function records.
Browse files Browse the repository at this point in the history
The profile data format was recently updated and the new indexing api
requires the code coverage tool to know the function's hash as well
as the function's name to get the execution counts for a function.

Differential Revision: http://reviews.llvm.org/D4995


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216208 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
hyp committed Aug 21, 2014
1 parent c7bc814 commit 3f1e549
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/CodeGen/CodeGenPGO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ llvm::GlobalVariable *CodeGenPGO::buildDataVar() {

// Create coverage mapping data variable.
if (!CoverageMapping.empty())
CGM.getCoverageMapping()->addFunctionMappingRecord(Name,
getFuncName(),
CGM.getCoverageMapping()->addFunctionMappingRecord(Name, getFuncName(),
FunctionHash,
CoverageMapping);

// Hide all these symbols so that we correctly get a copy for each
Expand Down
8 changes: 5 additions & 3 deletions lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,20 +1094,22 @@ static void dump(llvm::raw_ostream &OS, const CoverageMappingRecord &Function) {

void CoverageMappingModuleGen::addFunctionMappingRecord(
llvm::GlobalVariable *FunctionName, StringRef FunctionNameValue,
const std::string &CoverageMapping) {
uint64_t FunctionHash, const std::string &CoverageMapping) {
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
auto *Int32Ty = llvm::Type::getInt32Ty(Ctx);
auto *Int64Ty = llvm::Type::getInt64Ty(Ctx);
auto *Int8PtrTy = llvm::Type::getInt8PtrTy(Ctx);
if (!FunctionRecordTy) {
llvm::Type *FunctionRecordTypes[] = {Int8PtrTy, Int32Ty, Int32Ty};
llvm::Type *FunctionRecordTypes[] = {Int8PtrTy, Int32Ty, Int32Ty, Int64Ty};
FunctionRecordTy =
llvm::StructType::get(Ctx, makeArrayRef(FunctionRecordTypes));
}

llvm::Constant *FunctionRecordVals[] = {
llvm::ConstantExpr::getBitCast(FunctionName, Int8PtrTy),
llvm::ConstantInt::get(Int32Ty, FunctionNameValue.size()),
llvm::ConstantInt::get(Int32Ty, CoverageMapping.size())};
llvm::ConstantInt::get(Int32Ty, CoverageMapping.size()),
llvm::ConstantInt::get(Int64Ty, FunctionHash)};
FunctionRecords.push_back(llvm::ConstantStruct::get(
FunctionRecordTy, makeArrayRef(FunctionRecordVals)));
CoverageMappings += CoverageMapping;
Expand Down
1 change: 1 addition & 0 deletions lib/CodeGen/CoverageMappingGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CoverageMappingModuleGen {
/// function mapping records.
void addFunctionMappingRecord(llvm::GlobalVariable *FunctionName,
StringRef FunctionNameValue,
uint64_t FunctionHash,
const std::string &CoverageMapping);

/// \brief Emit the coverage mapping data for a translation unit.
Expand Down
2 changes: 1 addition & 1 deletion test/CoverageMapping/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ int main(void) {
return 0;
}

// CHECK: @__llvm_coverage_mapping = internal constant { i32, i32, i32, i32, [2 x { i8*, i32, i32 }], [{{[0-9]+}} x i8] } { i32 2, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 0, [2 x { i8*, i32, i32 }] [{ i8*, i32, i32 } { i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i32 3, i32 9 }, { i8*, i32, i32 } { i8* getelementptr inbounds ([4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i32 4, i32 9 }]
// CHECK: @__llvm_coverage_mapping = internal constant { i32, i32, i32, i32, [2 x { i8*, i32, i32, i64 }], [{{[0-9]+}} x i8] } { i32 2, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 0, [2 x { i8*, i32, i32, i64 }] [{ i8*, i32, i32, i64 } { i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i32 3, i32 9, i64 {{[0-9]+}} }, { i8*, i32, i32, i64 } { i8* getelementptr inbounds ([4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i32 4, i32 9, i64 {{[0-9]+}} }]

0 comments on commit 3f1e549

Please sign in to comment.