From 9aadb4d6d81a1b01d2c3d4073da39d81a1f77f20 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Tue, 2 Dec 2014 23:15:30 +0000 Subject: [PATCH] InstrProf: Use the same names for variables as we use in the profile There's no need to use different names for the local variables than we use in the profile itself, and it's a bit simpler and easier to debug if we're consistent. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223173 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenPGO.cpp | 25 +++++++++++-------------- lib/CodeGen/CodeGenPGO.h | 7 +++---- test/Profile/c-captured.c | 4 ++-- test/Profile/c-general.c | 2 +- test/Profile/c-linkage.c | 8 ++++---- test/Profile/cxx-lambda.cpp | 2 +- test/Profile/objc-general.m | 4 ++-- 7 files changed, 24 insertions(+), 28 deletions(-) diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 107b29c303..38f21626e4 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -27,7 +27,7 @@ using namespace CodeGen; void CodeGenPGO::setFuncName(StringRef Name, llvm::GlobalValue::LinkageTypes Linkage) { - RawFuncName = Name; + StringRef RawFuncName = Name; // Function names may be prefixed with a binary '1' to indicate // that the backend should not modify the symbols due to any platform @@ -35,20 +35,17 @@ void CodeGenPGO::setFuncName(StringRef Name, if (RawFuncName[0] == '\1') RawFuncName = RawFuncName.substr(1); - if (!llvm::GlobalValue::isLocalLinkage(Linkage)) { - PrefixedFuncName = RawFuncName; - return; + FuncName = RawFuncName; + if (llvm::GlobalValue::isLocalLinkage(Linkage)) { + // For local symbols, prepend the main file name to distinguish them. + // Do not include the full path in the file name since there's no guarantee + // that it will stay the same, e.g., if the files are checked out from + // version control in different locations. + if (CGM.getCodeGenOpts().MainFileName.empty()) + FuncName = FuncName.insert(0, ":"); + else + FuncName = FuncName.insert(0, CGM.getCodeGenOpts().MainFileName + ":"); } - - // For local symbols, prepend the main file name to distinguish them. - // Do not include the full path in the file name since there's no guarantee - // that it will stay the same, e.g., if the files are checked out from - // version control in different locations. - PrefixedFuncName = CGM.getCodeGenOpts().MainFileName; - if (PrefixedFuncName.empty()) - PrefixedFuncName.assign(""); - PrefixedFuncName.append(":"); - PrefixedFuncName.append(RawFuncName); } void CodeGenPGO::setFuncName(llvm::Function *Fn) { diff --git a/lib/CodeGen/CodeGenPGO.h b/lib/CodeGen/CodeGenPGO.h index 3a2deae31d..57bde0fd81 100644 --- a/lib/CodeGen/CodeGenPGO.h +++ b/lib/CodeGen/CodeGenPGO.h @@ -31,8 +31,7 @@ class RegionCounter; class CodeGenPGO { private: CodeGenModule &CGM; - std::string PrefixedFuncName; - StringRef RawFuncName; + std::string FuncName; llvm::GlobalValue::LinkageTypes VarLinkage; unsigned NumRegionCounters; @@ -60,9 +59,9 @@ public: /// Get the string used to identify this function in the profile data. /// For functions with local linkage, this includes the main file name. - StringRef getFuncName() const { return StringRef(PrefixedFuncName); } + StringRef getFuncName() const { return StringRef(FuncName); } std::string getFuncVarName(StringRef VarName) const { - return ("__llvm_profile_" + VarName + "_" + RawFuncName).str(); + return ("__llvm_profile_" + VarName + "_" + FuncName).str(); } /// Return the counter value of the current region. diff --git a/test/Profile/c-captured.c b/test/Profile/c-captured.c index ef7fb31850..229aba8813 100644 --- a/test/Profile/c-captured.c +++ b/test/Profile/c-captured.c @@ -4,8 +4,8 @@ // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-captured.c %s -o - -emit-llvm -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE -check-prefix=PGOALL %s // PGOGEN: @[[DCC:__llvm_profile_counters_debug_captured]] = hidden global [3 x i64] zeroinitializer -// PGOGEN: @[[CSC:__llvm_profile_counters___captured_stmt]] = internal global [2 x i64] zeroinitializer -// PGOGEN: @[[C1C:__llvm_profile_counters___captured_stmt1]] = internal global [3 x i64] zeroinitializer +// PGOGEN: @[[CSC:"__llvm_profile_counters_c-captured.c:__captured_stmt"]] = internal global [2 x i64] zeroinitializer +// PGOGEN: @[[C1C:"__llvm_profile_counters_c-captured.c:__captured_stmt1"]] = internal global [3 x i64] zeroinitializer // PGOALL-LABEL: define void @debug_captured() // PGOGEN: store {{.*}} @[[DCC]], i64 0, i64 0 diff --git a/test/Profile/c-general.c b/test/Profile/c-general.c index 79707ad2f5..dd5dc23bae 100644 --- a/test/Profile/c-general.c +++ b/test/Profile/c-general.c @@ -18,7 +18,7 @@ // PGOGEN: @[[BLC:__llvm_profile_counters_boolop_loops]] = hidden global [9 x i64] zeroinitializer // PGOGEN: @[[COC:__llvm_profile_counters_conditional_operator]] = hidden global [3 x i64] zeroinitializer // PGOGEN: @[[MAC:__llvm_profile_counters_main]] = hidden global [1 x i64] zeroinitializer -// PGOGEN: @[[STC:__llvm_profile_counters_static_func]] = internal global [2 x i64] zeroinitializer +// PGOGEN: @[[STC:"__llvm_profile_counters_c-general.c:static_func"]] = internal global [2 x i64] zeroinitializer // PGOGEN-LABEL: @simple_loops() // PGOUSE-LABEL: @simple_loops() diff --git a/test/Profile/c-linkage.c b/test/Profile/c-linkage.c index 3b0fa1a5a6..2406e3e385 100644 --- a/test/Profile/c-linkage.c +++ b/test/Profile/c-linkage.c @@ -24,12 +24,12 @@ int main(void) { return 0; } -// CHECK: @__llvm_profile_counters_foo_internal = internal global [3 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 -// CHECK: @__llvm_profile_name_foo_internal = internal constant [24 x i8] c"c-linkage.c:foo_internal", section "__DATA,__llvm_prf_names", align 1 -// CHECK: @__llvm_profile_data_foo_internal = internal constant { i32, i32, i64, i8*, i64* } { i32 24, i32 3, i64 {{[0-9]+}}, i8* getelementptr inbounds ([24 x i8]* @__llvm_profile_name_foo_internal, i32 0, i32 0), i64* getelementptr inbounds ([3 x i64]* @__llvm_profile_counters_foo_internal, i32 0, i32 0) }, section "__DATA,__llvm_prf_data", align 8 +// CHECK: @"__llvm_profile_counters_c-linkage.c:foo_internal" = internal global [3 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 +// CHECK: @"__llvm_profile_name_c-linkage.c:foo_internal" = internal constant [24 x i8] c"c-linkage.c:foo_internal", section "__DATA,__llvm_prf_names", align 1 +// CHECK: @"__llvm_profile_data_c-linkage.c:foo_internal" = internal constant { i32, i32, i64, i8*, i64* } { i32 24, i32 3, i64 {{[0-9]+}}, i8* getelementptr inbounds ([24 x i8]* @"__llvm_profile_name_c-linkage.c:foo_internal", i32 0, i32 0), i64* getelementptr inbounds ([3 x i64]* @"__llvm_profile_counters_c-linkage.c:foo_internal", i32 0, i32 0) }, section "__DATA,__llvm_prf_data", align 8 static void foo_internal(void) { if (0){} if (0){} } -// CHECK: @llvm.used = appending global [5 x i8*] [i8* bitcast (i32 ()* @__llvm_profile_runtime_user to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_foo to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_foo_weak to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_main to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_foo_internal to i8*)], section "llvm.metadata" +// CHECK: @llvm.used = appending global [5 x i8*] [i8* bitcast (i32 ()* @__llvm_profile_runtime_user to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_foo to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_foo_weak to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @__llvm_profile_data_main to i8*), i8* bitcast ({ i32, i32, i64, i8*, i64* }* @"__llvm_profile_data_c-linkage.c:foo_internal" to i8*)], section "llvm.metadata" // CHECK: define linkonce_odr i32 @__llvm_profile_runtime_user() {{.*}} { // CHECK: %[[REG:.*]] = load i32* @__llvm_profile_runtime diff --git a/test/Profile/cxx-lambda.cpp b/test/Profile/cxx-lambda.cpp index 6c37a863e5..6f6a1a330b 100644 --- a/test/Profile/cxx-lambda.cpp +++ b/test/Profile/cxx-lambda.cpp @@ -11,7 +11,7 @@ // PGOGEN: @[[LWC:__llvm_profile_counters__Z7lambdasv]] = hidden global [4 x i64] zeroinitializer // PGOGEN: @[[MAC:__llvm_profile_counters_main]] = hidden global [1 x i64] zeroinitializer -// LMBGEN: @[[LFC:"__llvm_profile_counters__ZZ7lambdasvENK3\$_0clEi"]] = internal global [3 x i64] zeroinitializer +// LMBGEN: @[[LFC:"__llvm_profile_counters_cxx-lambda.cpp:_ZZ7lambdasvENK3\$_0clEi"]] = internal global [3 x i64] zeroinitializer // PGOGEN-LABEL: define void @_Z7lambdasv() // PGOUSE-LABEL: define void @_Z7lambdasv() diff --git a/test/Profile/objc-general.m b/test/Profile/objc-general.m index ba06f91a7f..f54a441f2b 100644 --- a/test/Profile/objc-general.m +++ b/test/Profile/objc-general.m @@ -31,8 +31,8 @@ struct NSFastEnumerationState; @end; #endif -// PGOGEN: @[[FRC:"__llvm_profile_counters_\+\[A foreach:\]"]] = internal global [2 x i64] zeroinitializer -// PGOGEN: @[[BLC:"__llvm_profile_counters___13\+\[A foreach:\]_block_invoke"]] = internal global [2 x i64] zeroinitializer +// PGOGEN: @[[FRC:"__llvm_profile_counters_objc-general.m:\+\[A foreach:\]"]] = internal global [2 x i64] zeroinitializer +// PGOGEN: @[[BLC:"__llvm_profile_counters_objc-general.m:__13\+\[A foreach:\]_block_invoke"]] = internal global [2 x i64] zeroinitializer // PGOGEN: @[[MAC:__llvm_profile_counters_main]] = hidden global [1 x i64] zeroinitializer @interface A : NSObject -- 2.40.0