From: Justin Bogner Date: Fri, 1 Aug 2014 22:50:16 +0000 (+0000) Subject: InstrProf: Update for LLVM API change X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b16d21adf263b8bef7f455e8c2454754431f893c;p=clang InstrProf: Update for LLVM API change 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 --- diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index b233e3c7d7..4def789132 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -917,13 +917,15 @@ void CodeGenPGO::loadRegionCounts(llvm::IndexedInstrProfReader *PGOReader, bool IsInMainFile) { CGM.getPGOStats().addVisited(IsInMainFile); RegionCounts.reset(new std::vector); - 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 index 0000000000..e7dedcbf97 Binary files /dev/null and b/test/Profile/Inputs/c-general.profdata.v1 differ diff --git a/test/Profile/c-general.c b/test/Profile/c-general.c index 442fdd336c..79707ad2f5 100644 --- a/test/Profile/c-general.c +++ b/test/Profile/c-general.c @@ -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