Skip to content

Commit fc11984

Browse files
committed
[opt][timers] Fix time-passes.ll test failing on reversed iterators
After llvm#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 9ed772c commit fc11984

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

llvm/test/Other/time-passes.ll

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
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+
18+
; TIME: Analysis execution timing report
19+
; TIME: Total Execution Time:
20+
; TIME: Name
21+
; TIME-PER-RUN-DAG: ScalarEvolutionAnalysis
22+
; TIME-PER-RUN-DAG: LoopAnalysis
23+
; TIME-PER-RUN-DAG: DominatorTreeAnalysis
24+
; TIME-PER-RUN-DAG: TargetLibraryAnalysis
25+
; TIME-PER-PASS-DAG: ScalarEvolutionAnalysis
26+
; TIME-PER-PASS-DAG: LoopAnalysis
27+
; TIME-PER-PASS-DAG: DominatorTreeAnalysis
28+
; TIME-PER-PASS-DAG: TargetLibraryAnalysis
29+
; TIME-PER-PASS-NOT: ScalarEvolutionAnalysis #
30+
; TIME-PER-PASS-NOT: LoopAnalysis #
31+
; TIME-PER-PASS-NOT: DominatorTreeAnalysis #
32+
; TIME-PER-PASS-NOT: TargetLibraryAnalysis #
33+
; TIME: Total{{$}}
34+
1735
; TIME: Pass execution timing report
1836
; TIME: Total Execution Time:
1937
; TIME: Name
@@ -46,22 +64,6 @@
4664
; TIME-PER-PASS-NOT: VerifierPass #
4765
; TIME: Total{{$}}
4866

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{{$}}
6567

6668
define i32 @foo() {
6769
%res = add i32 5, 4

llvm/tools/opt/optdriver.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "llvm/Support/SystemUtils.h"
4949
#include "llvm/Support/TargetSelect.h"
5050
#include "llvm/Support/TimeProfiler.h"
51+
#include "llvm/Support/Timer.h"
5152
#include "llvm/Support/ToolOutputFile.h"
5253
#include "llvm/Support/YAMLTraits.h"
5354
#include "llvm/Target/TargetMachine.h"
@@ -722,14 +723,16 @@ extern "C" int optMain(
722723
// The user has asked to use the new pass manager and provided a pipeline
723724
// string. Hand off the rest of the functionality to the new code for that
724725
// layer.
725-
return runPassPipeline(
726+
bool result = runPassPipeline(
726727
argv[0], *M, TM.get(), &TLII, Out.get(), ThinLinkOut.get(),
727728
RemarksFile.get(), Pipeline, PluginList, PassBuilderCallbacks,
728729
OK, VK, PreserveAssemblyUseListOrder,
729730
PreserveBitcodeUseListOrder, EmitSummaryIndex, EmitModuleHash,
730-
EnableDebugify, VerifyDebugInfoPreserve, UnifiedLTO)
731-
? 0
732-
: 1;
731+
EnableDebugify, VerifyDebugInfoPreserve, UnifiedLTO);
732+
733+
llvm::TimerGroup::printAll(*llvm::CreateInfoOutputFile());
734+
llvm::TimerGroup::clearAll();
735+
return result ? 0 : 1;
733736
}
734737

735738
if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz ||
@@ -905,5 +908,8 @@ extern "C" int optMain(
905908
if (ThinLinkOut)
906909
ThinLinkOut->keep();
907910

911+
llvm::TimerGroup::printAll(*llvm::CreateInfoOutputFile());
912+
llvm::TimerGroup::clearAll();
913+
908914
return 0;
909915
}

0 commit comments

Comments
 (0)