Skip to content

Commit 630dad8

Browse files
projediSpace Team
authored andcommitted
[K/N] Use new llvm pass profiling for -Xprofile-phases compatible output
^KT-79381
1 parent 075f911 commit 630dad8

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/OptimizationPipeline.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ abstract class LlvmOptimizationPipeline(
215215

216216
fun execute(llvmModule: LLVMModuleRef) {
217217
initLLVMOnce()
218-
if (config.timePasses) {
219-
LLVMSetTimePasses(1)
220-
}
221218
executeCustomPreprocessing(config, llvmModule)
222219
val passDescription = passes.joinToString(",")
223220
logger?.log {
@@ -233,7 +230,7 @@ abstract class LlvmOptimizationPipeline(
233230
""".trimIndent()
234231
}
235232
if (passDescription.isEmpty()) return
236-
val (errorCode, profile) = withLLVMPassesProfile(performanceManager != null, pipelineName) {
233+
val (errorCode, profile) = withLLVMPassesProfile(performanceManager != null || config.timePasses, pipelineName) {
237234
LLVMKotlinRunPasses(
238235
llvmModule,
239236
passDescription,
@@ -247,10 +244,9 @@ abstract class LlvmOptimizationPipeline(
247244
}
248245
profile?.let {
249246
performanceManager?.addLlvmPassesProfile(it)
250-
}
251-
if (config.timePasses) {
252-
LLVMPrintAllTimersToStdOut()
253-
LLVMClearAllTimers()
247+
if (config.timePasses) {
248+
it.print()
249+
}
254250
}
255251
}
256252

kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmPassesProfile.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ internal inline fun <T> withLLVMPassesProfile(
6868
}
6969
}
7070

71+
/**
72+
* Record [LlvmPassesProfile] in [PerformanceManager] as dynamic stats.
73+
*/
7174
internal fun PerformanceManager.addLlvmPassesProfile(profile: LlvmPassesProfile) {
7275
addOtherUnitStats(UnitStats(
7376
name = "$presentableName (llvm)",
@@ -88,3 +91,14 @@ internal fun PerformanceManager.addLlvmPassesProfile(profile: LlvmPassesProfile)
8891
}
8992
))
9093
}
94+
95+
/**
96+
* Print out [LlvmPassesProfile] in a format similar to `-Xprofile-phases`.
97+
*
98+
* @see org.jetbrains.kotlin.config.phaser.NamedCompilerPhase.runAndProfile
99+
*/
100+
internal fun LlvmPassesProfile.print() {
101+
entries.forEach { (pass, duration) ->
102+
println("$pass: ${duration.millis} msec")
103+
}
104+
}

kotlin-native/libllvmext/src/main/cpp/CAPIExtensions.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <llvm/IR/Module.h>
77
#include <llvm/Passes/PassBuilder.h>
88
#include <llvm/Passes/StandardInstrumentations.h>
9-
#include <llvm/Support/Timer.h>
109
#include <llvm/Transforms/Utils/Cloning.h>
1110

1211
#include "PassesProfileHandler.h"
@@ -43,18 +42,6 @@ int LLVMInlineCall(LLVMValueRef call) {
4342
return InlineFunction(*unwrap<CallBase>(call), IFI).isSuccess();
4443
}
4544

46-
void LLVMSetTimePasses(int enabled) {
47-
llvm::TimePassesIsEnabled = static_cast<bool>(enabled);
48-
}
49-
50-
void LLVMPrintAllTimersToStdOut() {
51-
llvm::TimerGroup::printAll(llvm::outs());
52-
}
53-
54-
void LLVMClearAllTimers() {
55-
llvm::TimerGroup::clearAll();
56-
}
57-
5845
extern "C" LLVMErrorRef LLVMKotlinRunPasses(
5946
LLVMModuleRef M,
6047
const char *Passes,

kotlin-native/libllvmext/src/main/include/CAPIExtensions.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ void LLVMSetNoTailCall(LLVMValueRef Call);
2222

2323
int LLVMInlineCall(LLVMValueRef call);
2424

25-
/// Control LLVM -time-passes flag.
26-
void LLVMSetTimePasses(int enabled);
27-
28-
/// Print timing results. Useful in combination with LLVMSetTimePasses.
29-
void LLVMPrintAllTimersToStdOut(void);
30-
31-
/// Clear all LLVM timers. Allows avoiding automatic printing on shutdown
32-
void LLVMClearAllTimers(void);
33-
3425
/// Run `Passes` on module `M`.
3526
/// When `Profile` is not `NULL` also collect profiling data and store the result in it.
3627
LLVMErrorRef LLVMKotlinRunPasses(

0 commit comments

Comments
 (0)