]> granicus.if.org Git - clang/commitdiff
Coverage Mapping: store function's hash in coverage function records.
authorAlex Lorenz <arphaman@gmail.com>
Thu, 21 Aug 2014 19:25:27 +0000 (19:25 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 21 Aug 2014 19:25:27 +0000 (19:25 +0000)
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

lib/CodeGen/CodeGenPGO.cpp
lib/CodeGen/CoverageMappingGen.cpp
lib/CodeGen/CoverageMappingGen.h
test/CoverageMapping/ir.c

index 7fb64b85a05bc6df885a4ac4c68eff55df3f04e4..d341baf523c57605271d14b06157810cde18ce22 100644 (file)
@@ -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
index 86e2be8fbe283457c7f8bb0efc6cb00c5bf4bbf1..1bfa7cda76db87b5cfb2006c08b0e9f4af29bd2b 100644 (file)
@@ -1094,12 +1094,13 @@ 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));
   }
@@ -1107,7 +1108,8 @@ void CoverageMappingModuleGen::addFunctionMappingRecord(
   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;
index 8f4d745604511623f5e03b637fec43ffacce2337..45e0db8bce3cac07f605bb5afd4b980d513a641b 100644 (file)
@@ -69,6 +69,7 @@ public:
   /// 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.
index eb83959f1d289490541e9e09d45d858ca67ced4d..a1cb57020f9a0a3cabe2362c834345de25f977f1 100644 (file)
@@ -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]+}} }]