Add compiler option that allows to pass arguments to Clang

It is useful for compiler exploration and tuning.
This commit is contained in:
Sergey Bogolepov
2019-12-02 18:10:30 +07:00
committed by Sergey Bogolepov
parent 78ec094ce5
commit b508b6f1af
4 changed files with 11 additions and 1 deletions
@@ -152,6 +152,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
put(DEBUG, arguments.debug)
put(LIGHT_DEBUG, arguments.lightDebug)
put(STATIC_FRAMEWORK, selectFrameworkType(configuration, arguments, outputKind))
put(OVERRIDE_CLANG_OPTIONS, arguments.clangOptions.toNonNullList())
put(PRINT_IR, arguments.printIr)
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")
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> =
super.configureAnalysisFlags(collector).also {
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
@@ -18,6 +18,9 @@ internal class BitcodeCompiler(val context: Context) {
private val optimize = context.shouldOptimize()
private val debug = context.config.debug
private val overrideClangOptions =
context.configuration.getList(KonanConfigKeys.OVERRIDE_CLANG_OPTIONS)
private fun MutableList<String>.addNonEmpty(elements: List<String>) {
addAll(elements.filter { it.isNotEmpty() })
}
@@ -58,7 +61,8 @@ internal class BitcodeCompiler(val context: Context) {
}
else -> context.llvm.targetTriple
}
val flags = mutableListOf<String>().apply {
val flags = overrideClangOptions.takeIf(List<String>::isNotEmpty)
?: mutableListOf<String>().apply {
addNonEmpty(configurables.clangFlags)
addNonEmpty(listOf("-triple", targetTriple))
if (configurables is ZephyrConfigurables) {
@@ -84,6 +84,8 @@ class KonanConfigKeys {
= CompilerConfigurationKey.create("optimized compilation")
val OUTPUT: CompilerConfigurationKey<String>
= CompilerConfigurationKey.create("program or library name")
val OVERRIDE_CLANG_OPTIONS: CompilerConfigurationKey<List<String>>
= CompilerConfigurationKey.create("arguments for clang")
val PRINT_BITCODE: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("print bitcode")
val PRINT_DESCRIPTORS: CompilerConfigurationKey<Boolean>