[K/N] Option to specify IR validation severity
This commit is contained in:
+6
-2
@@ -285,8 +285,12 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xverify-bitcode", deprecatedName = "--verify_bitcode", description = "Verify llvm bitcode after each method")
|
||||
var verifyBitCode: Boolean = false
|
||||
|
||||
@Argument(value = "-Xverify-ir", description = "Verify IR")
|
||||
var verifyIr: Boolean = false
|
||||
@Argument(
|
||||
value = "-Xverify-ir",
|
||||
valueDescription = "{none|warning|error}",
|
||||
description = "IR verification mode (no verification by default)"
|
||||
)
|
||||
var verifyIr: String? = null
|
||||
|
||||
@Argument(value = "-Xverify-compiler", description = "Verify compiler")
|
||||
var verifyCompiler: String? = null
|
||||
|
||||
+8
-2
@@ -24,6 +24,12 @@ import org.jetbrains.kotlin.konan.util.visibleName
|
||||
import org.jetbrains.kotlin.library.metadata.resolver.TopologicalLibraryOrder
|
||||
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
||||
|
||||
enum class IrVerificationMode {
|
||||
NONE,
|
||||
WARNING,
|
||||
ERROR
|
||||
}
|
||||
|
||||
class KonanConfig(val project: Project, val configuration: CompilerConfiguration) {
|
||||
internal val distribution = run {
|
||||
val overridenProperties = mutableMapOf<String, String>().apply {
|
||||
@@ -165,8 +171,8 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
val gcMarkSingleThreaded: Boolean
|
||||
get() = configuration.get(BinaryOptions.gcMarkSingleThreaded) == true
|
||||
|
||||
val needVerifyIr: Boolean
|
||||
get() = configuration.get(KonanConfigKeys.VERIFY_IR) == true
|
||||
val irVerificationMode: IrVerificationMode
|
||||
get() = configuration.getNotNull(KonanConfigKeys.VERIFY_IR)
|
||||
|
||||
val needCompilerVerification: Boolean
|
||||
get() = configuration.get(KonanConfigKeys.VERIFY_COMPILER)
|
||||
|
||||
+2
-2
@@ -127,8 +127,8 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("save LLVM IR")
|
||||
val VERIFY_BITCODE: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("verify bitcode")
|
||||
val VERIFY_IR: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("verify IR")
|
||||
val VERIFY_IR: CompilerConfigurationKey<IrVerificationMode>
|
||||
= CompilerConfigurationKey.create("IR verification mode")
|
||||
val VERIFY_COMPILER: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("verify compiler")
|
||||
val DEBUG_INFO_VERSION: CompilerConfigurationKey<Int>
|
||||
|
||||
+10
-1
@@ -103,7 +103,16 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
|
||||
|
||||
if (arguments.verifyCompiler != null)
|
||||
put(VERIFY_COMPILER, arguments.verifyCompiler == "true")
|
||||
put(VERIFY_IR, arguments.verifyIr)
|
||||
put(VERIFY_IR, when (arguments.verifyIr) {
|
||||
null -> IrVerificationMode.NONE
|
||||
"none" -> IrVerificationMode.NONE
|
||||
"warning" -> IrVerificationMode.WARNING
|
||||
"error" -> IrVerificationMode.ERROR
|
||||
else -> {
|
||||
report(ERROR, "Unsupported IR verification mode ${arguments.verifyIr}")
|
||||
IrVerificationMode.NONE
|
||||
}
|
||||
})
|
||||
put(VERIFY_BITCODE, arguments.verifyBitCode)
|
||||
|
||||
put(ENABLE_ASSERTIONS, arguments.enableAssertions)
|
||||
|
||||
+3
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.backend.common.phaser.Action
|
||||
import org.jetbrains.kotlin.backend.common.phaser.ActionState
|
||||
import org.jetbrains.kotlin.backend.common.phaser.BeforeOrAfter
|
||||
import org.jetbrains.kotlin.backend.common.phaser.defaultDumper
|
||||
import org.jetbrains.kotlin.backend.konan.IrVerificationMode
|
||||
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
|
||||
import org.jetbrains.kotlin.backend.konan.reportCompilationWarning
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
@@ -56,7 +57,7 @@ private fun ActionState.isDumpNeeded() =
|
||||
|
||||
private fun <Context : PhaseContext, Data> getIrValidator(): Action<Data, Context> =
|
||||
fun(state: ActionState, data: Data, context: Context) {
|
||||
if (!context.config.needVerifyIr) return
|
||||
if (context.config.irVerificationMode == IrVerificationMode.NONE) return
|
||||
|
||||
val backendContext: CommonBackendContext? = findBackendContext(context)
|
||||
if (backendContext == null) {
|
||||
@@ -71,7 +72,7 @@ private fun <Context : PhaseContext, Data> getIrValidator(): Action<Data, Contex
|
||||
return
|
||||
}
|
||||
val validatorConfig = IrValidatorConfig(
|
||||
abortOnError = true,
|
||||
abortOnError = context.config.irVerificationMode == IrVerificationMode.ERROR,
|
||||
ensureAllNodesAreDifferent = true,
|
||||
checkTypes = true,
|
||||
checkDescriptors = false
|
||||
|
||||
@@ -6275,7 +6275,7 @@ task buildKonanTests { t ->
|
||||
baseDir testOutputLocal
|
||||
extraOpts '-ea' // Without this option assertions would remain inactive.
|
||||
extraOpts '-tr'
|
||||
extraOpts '-Xverify-ir'
|
||||
extraOpts '-Xverify-ir=error'
|
||||
extraOpts project.globalTestArgs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ open class KonanStandaloneTest : KonanLocalTest() {
|
||||
if (enableKonanAssertions)
|
||||
result += "-ea"
|
||||
if (verifyIr)
|
||||
result += "-Xverify-ir"
|
||||
result += "-Xverify-ir=error"
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ internal abstract class BasicCompilation<A : TestCompilationArtifact>(
|
||||
add(
|
||||
"-enable-assertions",
|
||||
"-Xskip-prerelease-check",
|
||||
"-Xverify-ir"
|
||||
"-Xverify-ir=error"
|
||||
)
|
||||
addFlattened(binaryOptions.entries) { (name, value) -> listOf("-Xbinary=$name=$value") }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user