Skip to content

Commit

Permalink
[CLI] Notify JS IR perf manager when generation is started and finished
Browse files Browse the repository at this point in the history
#KT-67473

(cherry picked from commit f3cd3b1)
  • Loading branch information
ivandev0 authored and qodana-bot committed Apr 30, 2024
1 parent c3a1c4e commit cc379a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
val messageCollector: MessageCollector,
val mainCallArguments: List<String>?
) {
private val performanceManager = module.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]

private fun lowerIr(): LoweredIr {
return compile(
module,
Expand Down Expand Up @@ -126,11 +128,18 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
val transformer = IrModuleToJsTransformer(ir.context, mainCallArguments, ir.moduleFragmentToUniqueName)

val mode = TranslationMode.fromFlags(arguments.irDce, arguments.granularity, arguments.irMinimizedMemberNames)
return transformer.makeJsCodeGenerator(ir.allModules, mode)
return transformer
.also { performanceManager?.notifyIRGenerationStarted() }
.makeJsCodeGenerator(ir.allModules, mode)
}

fun compileAndTransformIrNew(): CompilationOutputsBuilt {
return makeJsCodeGenerator().generateJsCode(relativeRequirePath = true, outJsProgram = false)
return makeJsCodeGenerator()
.generateJsCode(relativeRequirePath = true, outJsProgram = false)
.also {
performanceManager?.notifyIRGenerationFinished()
performanceManager?.notifyGenerationFinished()
}
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/ir/backend.js/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

dependencies {
implementation(project(":compiler:cli-base"))
api(project(":compiler:util"))
api(project(":compiler:frontend"))
api(project(":compiler:backend-common"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.ir.backend.js
import org.jetbrains.kotlin.backend.common.linkage.issues.checkNoUnboundSymbols
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.backend.js.lower.collectNativeImplementations
Expand Down Expand Up @@ -49,6 +50,8 @@ fun compile(
filesToLower: Set<String>? = null,
granularity: JsGenerationGranularity = JsGenerationGranularity.WHOLE_PROGRAM,
): LoweredIr {
val performanceManager = depsDescriptors.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]
performanceManager?.notifyIRTranslationStarted()

val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
loadIr(depsDescriptors, irFactory, verifySignatures, filesToLower, loadFunctionInterfacesIntoStdlib = true)
Expand Down Expand Up @@ -92,6 +95,7 @@ fun compileIr(
val moduleDescriptor = moduleFragment.descriptor
val irFactory = symbolTable.irFactory
val shouldGeneratePolyfills = configuration.getBoolean(JSConfigurationKeys.GENERATE_POLYFILLS)
val performanceManager = configuration[CLIConfigurationKeys.PERF_MANAGER]

val allModules = when (mainModule) {
is MainModule.SourceFiles -> dependencyModules + listOf(moduleFragment)
Expand Down Expand Up @@ -130,10 +134,14 @@ fun compileIr(

// TODO should be done incrementally
generateJsTests(context, allModules.last())
performanceManager?.notifyIRTranslationFinished()

performanceManager?.notifyGenerationStarted()
performanceManager?.notifyIRLoweringStarted()
(irFactory.stageController as? WholeWorldStageController)?.let {
lowerPreservingTags(allModules, context, phaseConfig, it)
} ?: jsPhases.invokeToplevel(phaseConfig, context, allModules)

performanceManager?.notifyIRLoweringFinished()
return LoweredIr(context, moduleFragment, allModules, moduleToName)
}

0 comments on commit cc379a8

Please sign in to comment.