[clang] 0fa20c5 - demangle function names in trace files (#87626)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 10 09:14:33 PDT 2024
Author: Trass3r
Date: 2024-07-10T12:14:28-04:00
New Revision: 0fa20c55b58deb94090985a5c5ffda4d5ceb3cd1
URL: https://github.com/llvm/llvm-project/commit/0fa20c55b58deb94090985a5c5ffda4d5ceb3cd1
DIFF: https://github.com/llvm/llvm-project/commit/0fa20c55b58deb94090985a5c5ffda4d5ceb3cd1.diff
LOG: demangle function names in trace files (#87626)
This improves consistency in the trace files as other entries are
demangled too.
Submitted by jamieschmeiser on behalf of trass3r
@jamieschmeiser @An-DJ
Added:
Modified:
clang/test/Driver/ftime-trace-sections.py
llvm/lib/IR/LegacyPassManager.cpp
llvm/lib/Passes/CMakeLists.txt
llvm/lib/Passes/StandardInstrumentations.cpp
Removed:
################################################################################
diff --git a/clang/test/Driver/ftime-trace-sections.py b/clang/test/Driver/ftime-trace-sections.py
old mode 100644
new mode 100755
index 02afa4ac54eb7..b332931d29a62
--- a/clang/test/Driver/ftime-trace-sections.py
+++ b/clang/test/Driver/ftime-trace-sections.py
@@ -19,7 +19,10 @@ def is_before(range1, range2):
log_contents = json.loads(sys.stdin.read())
events = log_contents["traceEvents"]
+
+instants = [event for event in events if event["name"] == "InstantiateFunction"]
codegens = [event for event in events if event["name"] == "CodeGen Function"]
+opts = [event for event in events if event["name"] == "OptFunction"]
frontends = [event for event in events if event["name"] == "Frontend"]
backends = [event for event in events if event["name"] == "Backend"]
@@ -48,3 +51,11 @@ def is_before(range1, range2):
]
):
sys.exit("Not all Frontend section are before all Backend sections!")
+
+# Check that entries for foo exist and are in a demangled form.
+if not any(e for e in instants if "foo<int>" in e["args"]["detail"]):
+ sys.exit("Missing Instantiate entry for foo!")
+if not any(e for e in codegens if "foo<int>" in e["args"]["detail"]):
+ sys.exit("Missing CodeGen entry for foo!")
+if not any(e for e in opts if "foo<int>" in e["args"]["detail"]):
+ sys.exit("Missing Optimize entry for foo!")
diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp
index 01aaedcf7d547..9c44eff7953ac 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -12,6 +12,7 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/ADT/MapVector.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
@@ -1415,7 +1416,8 @@ bool FPPassManager::runOnFunction(Function &F) {
// Store name outside of loop to avoid redundant calls.
const StringRef Name = F.getName();
- llvm::TimeTraceScope FunctionScope("OptFunction", Name);
+ llvm::TimeTraceScope FunctionScope(
+ "OptFunction", [&F]() { return demangle(F.getName().str()); });
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
FunctionPass *FP = getContainedPass(Index);
diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt
index 6425f4934b210..b5224327d7921 100644
--- a/llvm/lib/Passes/CMakeLists.txt
+++ b/llvm/lib/Passes/CMakeLists.txt
@@ -21,6 +21,7 @@ add_llvm_component_library(LLVMPasses
CodeGen
Core
Coroutines
+ Demangle
HipStdPar
IPO
InstCombine
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 429edabcc6558..2ed0e237d8de7 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/MIRPrinter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
@@ -234,12 +235,12 @@ void printIR(raw_ostream &OS, const MachineFunction *MF) {
MF->print(OS);
}
-std::string getIRName(Any IR) {
+std::string getIRName(Any IR, bool demangled = false) {
if (unwrapIR<Module>(IR))
return "[module]";
if (const auto *F = unwrapIR<Function>(IR))
- return F->getName().str();
+ return demangled ? demangle(F->getName()) : F->getName().str();
if (const auto *C = unwrapIR<LazyCallGraph::SCC>(IR))
return C->getName();
@@ -249,7 +250,7 @@ std::string getIRName(Any IR) {
L->getHeader()->getParent()->getName().str();
if (const auto *MF = unwrapIR<MachineFunction>(IR))
- return MF->getName().str();
+ return demangled ? demangle(MF->getName()) : MF->getName().str();
llvm_unreachable("Unknown wrapped IR type");
}
@@ -1579,7 +1580,7 @@ void TimeProfilingPassesHandler::registerCallbacks(
}
void TimeProfilingPassesHandler::runBeforePass(StringRef PassID, Any IR) {
- timeTraceProfilerBegin(PassID, getIRName(IR));
+ timeTraceProfilerBegin(PassID, getIRName(IR, true));
}
void TimeProfilingPassesHandler::runAfterPass() { timeTraceProfilerEnd(); }
More information about the cfe-commits
mailing list