Skip to content

Commit 50ea777

Browse files
authored
[opt][timers] Fix time-passes.ll test failing on reversed iterators (#131941)
After #131217 was submitted, time-passes.ll fails because `opt` prints `-time-report` when `ManagedTimerGlobals` is destroyed. `ManagedTimerGlobals` stores `TimerGroup`s in an unordered map, so the ordering of the output `TimerGroup`s depends on the underlying iterator. To fix this, we do what Clang does and use `llvm::TimerGroup::printAll(...)`, which *is* deterministic. This is also what Clang does. This does put move analysis section before the pass section for `-time-report`, but again, this is also what Clang currently does.
1 parent d8e44a9 commit 50ea777

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

llvm/test/Other/time-passes.ll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
; RUN: rm -f %t; opt < %s -disable-output -passes='default<O2>' -time-passes -info-output-file=%t
1515
; RUN: cat %t | FileCheck %s --check-prefix=TIME
1616
;
17+
; TIME: Analysis execution timing report
18+
; TIME: Total Execution Time:
19+
; TIME: Name
20+
; TIME-PER-RUN-DAG: ScalarEvolutionAnalysis
21+
; TIME-PER-RUN-DAG: LoopAnalysis
22+
; TIME-PER-RUN-DAG: DominatorTreeAnalysis
23+
; TIME-PER-RUN-DAG: TargetLibraryAnalysis
24+
; TIME-PER-PASS-DAG: ScalarEvolutionAnalysis
25+
; TIME-PER-PASS-DAG: LoopAnalysis
26+
; TIME-PER-PASS-DAG: DominatorTreeAnalysis
27+
; TIME-PER-PASS-DAG: TargetLibraryAnalysis
28+
; TIME-PER-PASS-NOT: ScalarEvolutionAnalysis #
29+
; TIME-PER-PASS-NOT: LoopAnalysis #
30+
; TIME-PER-PASS-NOT: DominatorTreeAnalysis #
31+
; TIME-PER-PASS-NOT: TargetLibraryAnalysis #
32+
; TIME: Total{{$}}
33+
1734
; TIME: Pass execution timing report
1835
; TIME: Total Execution Time:
1936
; TIME: Name
@@ -46,23 +63,6 @@
4663
; TIME-PER-PASS-NOT: VerifierPass #
4764
; TIME: Total{{$}}
4865

49-
; TIME: Analysis execution timing report
50-
; TIME: Total Execution Time:
51-
; TIME: Name
52-
; TIME-PER-RUN-DAG: ScalarEvolutionAnalysis
53-
; TIME-PER-RUN-DAG: LoopAnalysis
54-
; TIME-PER-RUN-DAG: DominatorTreeAnalysis
55-
; TIME-PER-RUN-DAG: TargetLibraryAnalysis
56-
; TIME-PER-PASS-DAG: ScalarEvolutionAnalysis
57-
; TIME-PER-PASS-DAG: LoopAnalysis
58-
; TIME-PER-PASS-DAG: DominatorTreeAnalysis
59-
; TIME-PER-PASS-DAG: TargetLibraryAnalysis
60-
; TIME-PER-PASS-NOT: ScalarEvolutionAnalysis #
61-
; TIME-PER-PASS-NOT: LoopAnalysis #
62-
; TIME-PER-PASS-NOT: DominatorTreeAnalysis #
63-
; TIME-PER-PASS-NOT: TargetLibraryAnalysis #
64-
; TIME: Total{{$}}
65-
6666
define i32 @foo() {
6767
%res = add i32 5, 4
6868
br label %loop1

llvm/tools/opt/NewPMDriver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "NewPMDriver.h"
1616
#include "llvm/ADT/SmallVector.h"
17+
#include "llvm/ADT/Statistic.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/Analysis/AliasAnalysis.h"
1920
#include "llvm/Analysis/CGSCCPassManager.h"
@@ -30,6 +31,7 @@
3031
#include "llvm/Passes/PassPlugin.h"
3132
#include "llvm/Passes/StandardInstrumentations.h"
3233
#include "llvm/Support/ErrorHandling.h"
34+
#include "llvm/Support/Timer.h"
3335
#include "llvm/Support/ToolOutputFile.h"
3436
#include "llvm/Support/VirtualFileSystem.h"
3537
#include "llvm/Support/raw_ostream.h"
@@ -566,6 +568,9 @@ bool llvm::runPassPipeline(
566568
if (DebugifyEach && !DebugifyExport.empty())
567569
exportDebugifyStats(DebugifyExport, Debugify.getDebugifyStatsMap());
568570

571+
TimerGroup::printAll(*CreateInfoOutputFile());
572+
TimerGroup::clearAll();
573+
569574
return true;
570575
}
571576

0 commit comments

Comments
 (0)