Index: lib/IR/DiagnosticInfo.cpp =================================================================== --- lib/IR/DiagnosticInfo.cpp +++ lib/IR/DiagnosticInfo.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/ADT/iterator_range.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" @@ -50,6 +51,21 @@ const char *OptimizationRemarkAnalysis::AlwaysPrint = ""; +// Itanium demangle a name from a global value (global variable, function). +// Returns a pointer to a null-terminated string and the length of the string. +static std::pair, size_t> +demangleCXXGlobalValue(StringRef Function) { + if (!Function.startswith("_Z")) + return {std::unique_ptr(nullptr, nullptr), 0}; + size_t Len = 0; + int Status = 0; + char *Demangled = itaniumDemangle(Function.data(), nullptr, &Len, &Status); + if (!Demangled || Status != 0) + return {std::unique_ptr(nullptr, nullptr), 0}; + return {std::unique_ptr(Demangled, std::free), + Len - 1}; +} + DiagnosticInfoInlineAsm::DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr, DiagnosticSeverity Severity) @@ -147,9 +163,16 @@ // Only include names that correspond to user variables. FIXME: We should use // debug info if available to get the name of the user variable. - if (isa(V) || isa(V)) + if (isa(V)) { + StringRef Name = GlobalValue::dropLLVMManglingEscape(V->getName()); + auto Demangled = demangleCXXGlobalValue(Name); + if (size_t Len = Demangled.second) + Val = std::string(Demangled.first.get(), Len); + else + Val = Name; + } else if (isa(V)) { Val = GlobalValue::dropLLVMManglingEscape(V->getName()); - else if (isa(V)) { + } else if (isa(V)) { raw_string_ostream OS(Val); V->printAsOperand(OS, /*PrintType=*/false); } else if (auto *I = dyn_cast(V)) @@ -390,7 +413,15 @@ io.mapRequired("Name", OptDiag->RemarkName); if (!io.outputting() || DL.isValid()) io.mapOptional("DebugLoc", DL); - io.mapRequired("Function", FN); + + auto DemangledFN = demangleCXXGlobalValue(FN); + if (size_t Len = DemangledFN.second) { + StringRef Demangled(DemangledFN.first.get(), Len); + io.mapRequired("Function", Demangled); + } else { + io.mapRequired("Function", FN); + } + io.mapOptional("Hotness", OptDiag->Hotness); io.mapOptional("Args", OptDiag->Args); } Index: test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll =================================================================== --- test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll +++ test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll @@ -52,7 +52,7 @@ ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: CantComputeNumberOfIterations ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 4, Column: 5 } -; YAML-NEXT: Function: _Z4testPii +; YAML-NEXT: Function: 'test(int*, int)' ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'loop not vectorized: ' ; YAML-NEXT: - String: could not determine number of loop iterations @@ -61,7 +61,7 @@ ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: MissedDetails ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 4, Column: 5 } -; YAML-NEXT: Function: _Z4testPii +; YAML-NEXT: Function: 'test(int*, int)' ; YAML-NEXT: Args: ; YAML-NEXT: - String: loop not vectorized ; YAML-NEXT: ... @@ -69,7 +69,7 @@ ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: AllDisabled ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 13, Column: 5 } -; YAML-NEXT: Function: _Z13test_disabledPii +; YAML-NEXT: Function: 'test_disabled(int*, int)' ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized ; YAML-NEXT: ... @@ -77,7 +77,7 @@ ; YAML-NEXT: Pass: '' ; YAML-NEXT: Name: CantIdentifyArrayBounds ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 } -; YAML-NEXT: Function: _Z17test_array_boundsPiS_i +; YAML-NEXT: Function: 'test_array_bounds(int*, int*, int)' ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'loop not vectorized: ' ; YAML-NEXT: - String: cannot identify array bounds @@ -86,7 +86,7 @@ ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: MissedDetails ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 } -; YAML-NEXT: Function: _Z17test_array_boundsPiS_i +; YAML-NEXT: Function: 'test_array_bounds(int*, int*, int)' ; YAML-NEXT: Args: ; YAML-NEXT: - String: loop not vectorized ; YAML-NEXT: - String: ' (Force=' @@ -97,7 +97,7 @@ ; YAML-NEXT: Pass: loop-vectorize ; YAML-NEXT: Name: FailedRequestedVectorization ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 } -; YAML-NEXT: Function: _Z17test_array_boundsPiS_i +; YAML-NEXT: Function: 'test_array_bounds(int*, int*, int)' ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'loop not vectorized: ' ; YAML-NEXT: - String: failed explicitly specified loop vectorization Index: test/Transforms/SampleProfile/inline-coverage.ll =================================================================== --- test/Transforms/SampleProfile/inline-coverage.ll +++ test/Transforms/SampleProfile/inline-coverage.ll @@ -16,7 +16,7 @@ ; 11 return sum > 0 ? 0 : 1; ; 12 } ; -; CHECK: remark: coverage.cc:10:12: inlined hot callee '_Z3fool' into 'main' +; CHECK: remark: coverage.cc:10:12: inlined hot callee 'foo(long)' into 'main' ; CHECK: remark: coverage.cc:9:21: Applied 23478 samples from profile (offset: 2.1) ; CHECK: remark: coverage.cc:10:16: Applied 23478 samples from profile (offset: 3) ; CHECK: remark: coverage.cc:4:10: Applied 31878 samples from profile (offset: 1) Index: test/Transforms/SampleProfile/remarks.ll =================================================================== --- test/Transforms/SampleProfile/remarks.ll +++ test/Transforms/SampleProfile/remarks.ll @@ -21,7 +21,7 @@ ; We are expecting foo() to be inlined in main() (almost all the cycles are ; spent inside foo). -; CHECK: remark: remarks.cc:13:21: inlined hot callee '_Z3foov' into 'main' +; CHECK: remark: remarks.cc:13:21: inlined hot callee 'foo()' into 'main' ; The back edge for the loop is the hottest edge in the loop subgraph. ; CHECK: remark: remarks.cc:6:9: most popular destination for conditional branches at remarks.cc:5:3 @@ -37,7 +37,7 @@ ;YAML-NEXT: Function: main ;YAML-NEXT: Args: ;YAML-NEXT: - String: 'inlined hot callee ''' -;YAML-NEXT: - Callee: _Z3foov +;YAML-NEXT: - Callee: 'foo()' ;YAML-NEXT: DebugLoc: { File: remarks.cc, Line: 3, Column: 0 } ;YAML-NEXT: - String: ''' into ''' ;YAML-NEXT: - Caller: main