]> granicus.if.org Git - clang/commitdiff
InstrProf: Update for LLVM API change
authorJustin Bogner <mail@justinbogner.com>
Fri, 1 Aug 2014 22:50:16 +0000 (22:50 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 1 Aug 2014 22:50:16 +0000 (22:50 +0000)
We've added support for a multiple functions with the same name in
LLVM's profile data, so the lookup returning the function hash it
found doesn't make sense anymore. Update to pass in the hash we
expect.

This also adds a test that the version 1 format is still readable,
since the new API is expected to handle that.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214586 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenPGO.cpp
test/Profile/Inputs/c-general.profdata.v1 [new file with mode: 0644]
test/Profile/c-general.c

index b233e3c7d75e3b1851510d9ab3e2befc764ee86d..4def789132a528f927a1ebf144829b7287d88ae3 100644 (file)
@@ -917,13 +917,15 @@ void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader,
                                   bool IsInMainFile) {
   CGM.getPGOStats().addVisited(IsInMainFile);
   RegionCounts.reset(new std::vector<uint64_t>);
-  uint64_t Hash;
-  if (PGOReader->getFunctionCounts(getFuncName(), Hash, *RegionCounts)) {
-    CGM.getPGOStats().addMissing(IsInMainFile);
-    RegionCounts.reset();
-  } else if (Hash != FunctionHash ||
-             RegionCounts->size() != NumRegionCounters) {
-    CGM.getPGOStats().addMismatched(IsInMainFile);
+  if (std::error_code EC = PGOReader->getFunctionCounts(
+          getFuncName(), FunctionHash, *RegionCounts)) {
+    if (EC == llvm::instrprof_error::unknown_function)
+      CGM.getPGOStats().addMissing(IsInMainFile);
+    else if (EC == llvm::instrprof_error::hash_mismatch)
+      CGM.getPGOStats().addMismatched(IsInMainFile);
+    else if (EC == llvm::instrprof_error::malformed)
+      // TODO: Consider a more specific warning for this case.
+      CGM.getPGOStats().addMismatched(IsInMainFile);
     RegionCounts.reset();
   }
 }
diff --git a/test/Profile/Inputs/c-general.profdata.v1 b/test/Profile/Inputs/c-general.profdata.v1
new file mode 100644 (file)
index 0000000..e7dedcb
Binary files /dev/null and b/test/Profile/Inputs/c-general.profdata.v1 differ
index 442fdd336c7cce9a0a1a458f40cbcd9e00af8d44..79707ad2f5be28d2be10f3dc229df3f56f2724aa 100644 (file)
@@ -5,6 +5,9 @@
 // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
 
+// Also check compatibility with older profiles.
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instr-use=%S/Inputs/c-general.profdata.v1 | FileCheck -check-prefix=PGOUSE %s
+
 // PGOGEN: @[[SLC:__llvm_profile_counters_simple_loops]] = hidden global [4 x i64] zeroinitializer
 // PGOGEN: @[[IFC:__llvm_profile_counters_conditionals]] = hidden global [11 x i64] zeroinitializer
 // PGOGEN: @[[EEC:__llvm_profile_counters_early_exits]] = hidden global [9 x i64] zeroinitializer