Skip to content

Commit 153bb2f

Browse files
committed
demangle OptFunction trace names
This improves consistency in the trace files as other entries are demangled too. Fixes #45901.
1 parent 1412210 commit 153bb2f

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

clang/test/Driver/ftime-trace-sections.py

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def is_before(range1, range2):
1919

2020
log_contents = json.loads(sys.stdin.read())
2121
events = log_contents["traceEvents"]
22+
23+
instants = [event for event in events if event["name"] == "InstantiateFunction"]
2224
codegens = [event for event in events if event["name"] == "CodeGen Function"]
25+
opts = [event for event in events if event["name"] == "OptFunction"]
2326
frontends = [event for event in events if event["name"] == "Frontend"]
2427
backends = [event for event in events if event["name"] == "Backend"]
2528

@@ -48,3 +51,11 @@ def is_before(range1, range2):
4851
]
4952
):
5053
sys.exit("Not all Frontend section are before all Backend sections!")
54+
55+
# Check that entries for foo exist and are in a demangled form.
56+
if not any(e for e in instants if "foo<int>" in e["args"]["detail"]):
57+
sys.exit("Missing Instantiate entry for foo!")
58+
if not any(e for e in codegens if "foo<int>" in e["args"]["detail"]):
59+
sys.exit("Missing CodeGen entry for foo!")
60+
if not any(e for e in opts if "foo<int>" in e["args"]["detail"]):
61+
sys.exit("Missing Optimize entry for foo!")

llvm/lib/IR/LegacyPassManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/IR/LegacyPassManager.h"
1414
#include "llvm/ADT/MapVector.h"
15+
#include "llvm/Demangle/Demangle.h"
1516
#include "llvm/IR/DiagnosticInfo.h"
1617
#include "llvm/IR/IRPrintingPasses.h"
1718
#include "llvm/IR/LLVMContext.h"
@@ -1416,7 +1417,8 @@ bool FPPassManager::runOnFunction(Function &F) {
14161417

14171418
// Store name outside of loop to avoid redundant calls.
14181419
const StringRef Name = F.getName();
1419-
llvm::TimeTraceScope FunctionScope("OptFunction", Name);
1420+
llvm::TimeTraceScope FunctionScope(
1421+
"OptFunction", [&F]() { return demangle(F.getName().str()); });
14201422

14211423
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
14221424
FunctionPass *FP = getContainedPass(Index);

llvm/lib/Passes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_llvm_component_library(LLVMPasses
2121
CodeGen
2222
Core
2323
Coroutines
24+
Demangle
2425
HipStdPar
2526
IPO
2627
InstCombine

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/CodeGen/MIRPrinter.h"
2323
#include "llvm/CodeGen/MachineFunction.h"
2424
#include "llvm/CodeGen/MachineModuleInfo.h"
25+
#include "llvm/Demangle/Demangle.h"
2526
#include "llvm/IR/Constants.h"
2627
#include "llvm/IR/Function.h"
2728
#include "llvm/IR/Module.h"
@@ -1576,7 +1577,7 @@ void TimeProfilingPassesHandler::registerCallbacks(
15761577
}
15771578

15781579
void TimeProfilingPassesHandler::runBeforePass(StringRef PassID, Any IR) {
1579-
timeTraceProfilerBegin(PassID, getIRName(IR));
1580+
timeTraceProfilerBegin(PassID, demangle(getIRName(IR)));
15801581
}
15811582

15821583
void TimeProfilingPassesHandler::runAfterPass() { timeTraceProfilerEnd(); }

0 commit comments

Comments
 (0)