From 103f82c95c39b8cf5e6e559a7d0dd05593bc77d9 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Fri, 6 Nov 2020 13:56:48 +0300 Subject: [PATCH] IR: an option to automatically select the number of lowering threads --- .../kotlin/cli/common/arguments/K2JVMCompilerArguments.kt | 7 ++++--- .../cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt | 4 +++- .../org/jetbrains/kotlin/config/CommonConfigurationKeys.kt | 2 +- .../kotlin/backend/common/phaser/PhaseBuilders.kt | 2 +- compiler/testData/cli/jvm/extraHelp.out | 7 ++++--- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 926e80406d6..f04ab6e41f2 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -115,11 +115,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var doNotClearBindingContext: Boolean by FreezableVar(false) @Argument( - value = "-Xir-threads-for-file-lowerings", + value = "-Xparallel-backend-threads", description = "When using the IR backend, run lowerings by file in N parallel threads.\n" + - "Default value is 1" + "0 means use a thread per processor core.\n" + + "Default value is 1" ) - var threadsForFileLowerings: String by FreezableVar("1") + var parallelBackendThreads: String by FreezableVar("1") @Argument(value = "-Xmodule-path", valueDescription = "", description = "Paths where to find Java 9+ modules") var javaModulePath: String? by NullableStringFreezableVar(null) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index 932a6482b19..609b21a19bc 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -292,7 +292,9 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr arguments.declarationsOutputPath?.let { put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) } - put(CommonConfigurationKeys.THREADS_FOR_FILE_LOWERINGS, arguments.threadsForFileLowerings.toIntOrNull() ?: 1) + val nThreadsRaw = arguments.parallelBackendThreads.toIntOrNull() ?: 1 + val nThreads = if (nThreadsRaw == 0) Runtime.getRuntime().availableProcessors() else nThreadsRaw + put(CommonConfigurationKeys.PARALLEL_BACKEND_THREADS, nThreads) } fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) { diff --git a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt index 9e77280ee7a..2f4518f87f5 100644 --- a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt +++ b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt @@ -52,7 +52,7 @@ object CommonConfigurationKeys { val USE_FIR_EXTENDED_CHECKERS = CompilerConfigurationKey.create("fir extended checkers") @JvmField - val THREADS_FOR_FILE_LOWERINGS = + val PARALLEL_BACKEND_THREADS = CompilerConfigurationKey.create("When using the IR backend, run lowerings by file in N parallel threads") } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt index 89e0b3b50b2..a860fb8f1a8 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt @@ -122,7 +122,7 @@ private class PerformByIrFilePhase( context: Context, input: IrModuleFragment ): IrModuleFragment { - val nThreads = context.configuration.get(CommonConfigurationKeys.THREADS_FOR_FILE_LOWERINGS) ?: 1 + val nThreads = context.configuration.get(CommonConfigurationKeys.PARALLEL_BACKEND_THREADS) ?: 1 return if (nThreads > 1) invokeParallel(phaseConfig, phaserState, context, input, nThreads) else diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 374d825bcbd..f70bdbf39b3 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -90,6 +90,9 @@ where advanced options include: -Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types -Xno-reset-jar-timestamps Do not reset jar entry timestamps to a fixed date -Xno-unified-null-checks Use pre-1.4 exception types in null checks instead of java.lang.NPE. See KT-22275 for more details + -Xparallel-backend-threads When using the IR backend, run lowerings by file in N parallel threads. + 0 means use a thread per processor core. + Default value is 1 -Xprofile= Debug option: Run compiler with async profiler, save snapshots to outputDir, command is passed to async-profiler on start You'll have to provide async-profiler.jar on classpath to use this @@ -122,9 +125,6 @@ where advanced options include: Suppress deprecation warning about deprecated JVM target versions -Xsuppress-missing-builtins-error Suppress the "cannot access built-in declaration" error (useful with -no-stdlib) - -Xir-threads-for-file-lowerings - When using the IR backend, run lowerings by file in N parallel threads. - Default value is 1 -Xuse-ir Use the IR backend -Xuse-javac Use javac for Java source and class files analysis -Xuse-old-backend Use the old JVM backend @@ -193,3 +193,4 @@ where advanced options include: Advanced options are non-standard and may be changed or removed without any notice. OK +