Skip to content

Commit

Permalink
[CLI] Notify WASM 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 0867bf1)
  • Loading branch information
ivandev0 authored and qodana-bot committed Apr 30, 2024
1 parent 4bbc4cf commit c3a1c4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
exportedDeclarations = setOf(FqName("main")),
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
)

performanceManager?.notifyIRGenerationStarted()
val dceDumpNameCache = DceDumpNameCache()
if (arguments.irDce) {
eliminateDeadDeclarations(allModules, backendContext, dceDumpNameCache)
Expand All @@ -370,6 +372,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
generateWat = configuration.get(JSConfigurationKeys.WASM_GENERATE_WAT, false),
generateSourceMaps = generateSourceMaps
)
performanceManager?.notifyIRGenerationFinished()
performanceManager?.notifyGenerationFinished()

writeCompilationResult(
result = res,
Expand Down
1 change: 1 addition & 0 deletions compiler/ir/backend.wasm/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 @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.wasm.ir2wasm.WasmModuleFragmentGenerator
import org.jetbrains.kotlin.backend.wasm.ir2wasm.toJsStringLiteral
import org.jetbrains.kotlin.backend.wasm.lower.markExportedDeclarations
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.ir.backend.js.MainModule
import org.jetbrains.kotlin.ir.backend.js.ModulesStructure
import org.jetbrains.kotlin.ir.backend.js.SourceMapsInfo
Expand Down Expand Up @@ -51,6 +52,9 @@ fun compileToLoweredIr(
): Pair<List<IrModuleFragment>, WasmBackendContext> {
val mainModule = depsDescriptors.mainModule
val configuration = depsDescriptors.compilerConfiguration
val performanceManager = depsDescriptors.compilerConfiguration[CLIConfigurationKeys.PERF_MANAGER]
performanceManager?.notifyIRTranslationStarted()

val (moduleFragment, dependencyModules, irBuiltIns, symbolTable, irLinker) = loadIr(
depsDescriptors,
irFactory,
Expand Down Expand Up @@ -83,7 +87,11 @@ fun compileToLoweredIr(
for (file in module.files)
markExportedDeclarations(context, file, exportedDeclarations)

performanceManager?.notifyIRTranslationFinished()
performanceManager?.notifyGenerationStarted()
performanceManager?.notifyIRLoweringStarted()
wasmPhases.invokeToplevel(phaseConfig, context, allModules)
performanceManager?.notifyIRLoweringFinished()

return Pair(allModules, context)
}
Expand Down Expand Up @@ -179,7 +187,7 @@ private fun generateSourceMap(
prev = location

location.apply {
// TODO resulting path goes too deep since temporary directory we compiled first is deeper than final destination.
// TODO resulting path goes too deep since temporary directory we compiled first is deeper than final destination.
val relativePath = pathResolver.getPathRelativeToSourceRoots(File(file)).substring(3)
sourceMapBuilder.addMapping(relativePath, null, { null }, line, column, null, mapping.offset)
}
Expand Down

0 comments on commit c3a1c4e

Please sign in to comment.