Add compiler option that allows to pass arguments to Clang
It is useful for compiler exploration and tuning.
This commit is contained in:
committed by
Sergey Bogolepov
parent
78ec094ce5
commit
b508b6f1af
@@ -152,6 +152,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
put(DEBUG, arguments.debug)
|
put(DEBUG, arguments.debug)
|
||||||
put(LIGHT_DEBUG, arguments.lightDebug)
|
put(LIGHT_DEBUG, arguments.lightDebug)
|
||||||
put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind))
|
put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind))
|
||||||
|
put(OVERRIDE_CLANG_OPTIONS, arguments.clangOptions.toNonNullList())
|
||||||
|
|
||||||
put(PRINT_IR, arguments.printIr)
|
put(PRINT_IR, arguments.printIr)
|
||||||
put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors)
|
put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors)
|
||||||
|
|||||||
@@ -231,6 +231,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "-Xobjc-generics", description = "Enable experimental generics support for framework header")
|
@Argument(value = "-Xobjc-generics", description = "Enable experimental generics support for framework header")
|
||||||
var objcGenerics: Boolean = false
|
var objcGenerics: Boolean = false
|
||||||
|
|
||||||
|
@Argument(value="-Xoverride-clang-options", valueDescription = "<arg1,arg2,...>", description = "Explicit list of Clang options")
|
||||||
|
var clangOptions: Array<String>? = null
|
||||||
|
|
||||||
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> =
|
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> =
|
||||||
super.configureAnalysisFlags(collector).also {
|
super.configureAnalysisFlags(collector).also {
|
||||||
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
|
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
|
||||||
|
|||||||
+5
-1
@@ -18,6 +18,9 @@ internal class BitcodeCompiler(val context: Context) {
|
|||||||
private val optimize = context.shouldOptimize()
|
private val optimize = context.shouldOptimize()
|
||||||
private val debug = context.config.debug
|
private val debug = context.config.debug
|
||||||
|
|
||||||
|
private val overrideClangOptions =
|
||||||
|
context.configuration.getList(KonanConfigKeys.OVERRIDE_CLANG_OPTIONS)
|
||||||
|
|
||||||
private fun MutableList<String>.addNonEmpty(elements: List<String>) {
|
private fun MutableList<String>.addNonEmpty(elements: List<String>) {
|
||||||
addAll(elements.filter { it.isNotEmpty() })
|
addAll(elements.filter { it.isNotEmpty() })
|
||||||
}
|
}
|
||||||
@@ -58,7 +61,8 @@ internal class BitcodeCompiler(val context: Context) {
|
|||||||
}
|
}
|
||||||
else -> context.llvm.targetTriple
|
else -> context.llvm.targetTriple
|
||||||
}
|
}
|
||||||
val flags = mutableListOf<String>().apply {
|
val flags = overrideClangOptions.takeIf(List<String>::isNotEmpty)
|
||||||
|
?: mutableListOf<String>().apply {
|
||||||
addNonEmpty(configurables.clangFlags)
|
addNonEmpty(configurables.clangFlags)
|
||||||
addNonEmpty(listOf("-triple", targetTriple))
|
addNonEmpty(listOf("-triple", targetTriple))
|
||||||
if (configurables is ZephyrConfigurables) {
|
if (configurables is ZephyrConfigurables) {
|
||||||
|
|||||||
+2
@@ -84,6 +84,8 @@ class KonanConfigKeys {
|
|||||||
= CompilerConfigurationKey.create("optimized compilation")
|
= CompilerConfigurationKey.create("optimized compilation")
|
||||||
val OUTPUT: CompilerConfigurationKey<String>
|
val OUTPUT: CompilerConfigurationKey<String>
|
||||||
= CompilerConfigurationKey.create("program or library name")
|
= CompilerConfigurationKey.create("program or library name")
|
||||||
|
val OVERRIDE_CLANG_OPTIONS: CompilerConfigurationKey<List<String>>
|
||||||
|
= CompilerConfigurationKey.create("arguments for clang")
|
||||||
val PRINT_BITCODE: CompilerConfigurationKey<Boolean>
|
val PRINT_BITCODE: CompilerConfigurationKey<Boolean>
|
||||||
= CompilerConfigurationKey.create("print bitcode")
|
= CompilerConfigurationKey.create("print bitcode")
|
||||||
val PRINT_DESCRIPTORS: CompilerConfigurationKey<Boolean>
|
val PRINT_DESCRIPTORS: CompilerConfigurationKey<Boolean>
|
||||||
|
|||||||
Reference in New Issue
Block a user