[llvm] r204142 - Tolerate unmangled names in sample profiles.

Diego Novillo dnovillo at google.com
Tue Mar 18 05:03:12 PDT 2014


Author: dnovillo
Date: Tue Mar 18 07:03:12 2014
New Revision: 204142

URL: http://llvm.org/viewvc/llvm-project?rev=204142&view=rev
Log:
Tolerate unmangled names in sample profiles.

Summary:
The compiler does not always generate linkage names. If a function
has been inlined and its body elided, its linkage name may not be
generated.

When the binary executes, the profiler will use its unmangled name
when attributing samples. This results in unmangled names in the
input profile.

We are currently failing hard when this happens. However, in this case
all that happens is that we fail to attribute samples to the inlined
function. While this means fewer optimization opportunities, it should
not cause a compilation failure.

This patch accepts all valid function names, regardless of whether
they were mangled or not.

Reviewers: chandlerc

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3087

Added:
    llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_mangle.prof
Modified:
    llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
    llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_fn_header.prof
    llvm/trunk/test/Transforms/SampleProfile/syntax.ll

Modified: llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=204142&r1=204141&r2=204142&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp Tue Mar 18 07:03:12 2014
@@ -251,7 +251,7 @@ public:
     return Profiles[F.getName()];
   }
 
-  /// \brief Report a parse error message and stop compilation.
+  /// \brief Report a parse error message.
   void reportParseError(int64_t LineNumber, Twine Msg) const {
     DiagnosticInfoSampleProfile Diag(Filename.data(), LineNumber, Msg);
     M.getContext().diagnose(Diag);
@@ -462,15 +462,21 @@ bool SampleModuleProfile::loadText() {
   // Read the profile of each function. Since each function may be
   // mentioned more than once, and we are collecting flat profiles,
   // accumulate samples as we parse them.
-  Regex HeadRE("^([^:]+):([0-9]+):([0-9]+)$");
+  Regex HeadRE("^([^0-9].*):([0-9]+):([0-9]+)$");
   Regex LineSample("^([0-9]+)\\.?([0-9]+)?: ([0-9]+)(.*)$");
   while (!LineIt.is_at_eof()) {
-    // Read the header of each function. The function header should
-    // have this format:
+    // Read the header of each function.
     //
-    //        function_name:total_samples:total_head_samples
+    // Note that for function identifiers we are actually expecting
+    // mangled names, but we may not always get them. This happens when
+    // the compiler decides not to emit the function (e.g., it was inlined
+    // and removed). In this case, the binary will not have the linkage
+    // name for the function, so the profiler will emit the function's
+    // unmangled name, which may contain characters like ':' and '>' in its
+    // name (member functions, templates, etc).
     //
-    // See above for an explanation of each field.
+    // The only requirement we place on the identifier, then, is that it
+    // should not begin with a number.
     SmallVector<StringRef, 3> Matches;
     if (!HeadRE.match(*LineIt, &Matches)) {
       reportParseError(LineIt.line_number(),

Modified: llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_fn_header.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_fn_header.prof?rev=204142&r1=204141&r2=204142&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_fn_header.prof (original)
+++ llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_fn_header.prof Tue Mar 18 07:03:12 2014
@@ -1,3 +1,3 @@
-empty:100:BAD
+3empty:100:BAD
 0: 0
 1: 100

Added: llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_mangle.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_mangle.prof?rev=204142&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_mangle.prof (added)
+++ llvm/trunk/test/Transforms/SampleProfile/Inputs/bad_mangle.prof Tue Mar 18 07:03:12 2014
@@ -0,0 +1,3 @@
+double convert<std::string, float>(float):2909472:181842
+0: 181842
+1: 181842

Modified: llvm/trunk/test/Transforms/SampleProfile/syntax.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/syntax.ll?rev=204142&r1=204141&r2=204142&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/syntax.ll (original)
+++ llvm/trunk/test/Transforms/SampleProfile/syntax.ll Tue Mar 18 07:03:12 2014
@@ -5,6 +5,7 @@
 ; RUN: not opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad_line_values.prof 2>&1 | FileCheck -check-prefix=BAD-LINE-VALUES %s
 ; RUN: not opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad_discriminator_value.prof 2>&1 | FileCheck -check-prefix=BAD-DISCRIMINATOR-VALUE %s
 ; RUN: not opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad_samples.prof 2>&1 | FileCheck -check-prefix=BAD-SAMPLES %s
+; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad_mangle.prof 2>&1 >/dev/null
 
 define void @empty() {
 entry:
@@ -12,7 +13,7 @@ entry:
 }
 ; NO-DEBUG: error: No debug information found in function empty
 ; MISSING-FILE: error: missing.prof:
-; BAD-FN-HEADER: error: {{.*}}bad_fn_header.prof:1: Expected 'mangled_name:NUM:NUM', found empty:100:BAD
+; BAD-FN-HEADER: error: {{.*}}bad_fn_header.prof:1: Expected 'mangled_name:NUM:NUM', found 3empty:100:BAD
 ; BAD-SAMPLE-LINE: error: {{.*}}bad_sample_line.prof:3: Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found 1: BAD
 ; BAD-LINE-VALUES: error: {{.*}}bad_line_values.prof:2: Expected 'mangled_name:NUM:NUM', found -1: 10
 ; BAD-DISCRIMINATOR-VALUE: error: {{.*}}bad_discriminator_value.prof:2: Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found 1.-3: 10





More information about the llvm-commits mailing list