[K/N] Don't pass -target-cpu to clang

It is not supported by bitcode embedding on Apple platforms.
Instead, we set it in function attributes directly as Clang does.
This commit is contained in:
Sergey Bogolepov
2021-08-05 20:13:07 +07:00
committed by Space
parent 3a210f6c81
commit d64cb24643
2 changed files with 45 additions and 40 deletions
@@ -22,6 +22,7 @@ internal fun addLlvmFunctionWithDefaultAttributes(
type: LLVMTypeRef
): LLVMValueRef = LLVMAddFunction(module, name, type)!!.also {
addDefaultLlvmFunctionAttributes(context, it)
addTargetCpuAndFeaturesAttributes(context, it)
}
/**
@@ -35,6 +36,18 @@ private fun addDefaultLlvmFunctionAttributes(context: Context, llvmFunction: LLV
}
}
/**
* Set target cpu and its features to make LLVM generate correct machine code.
*/
private fun addTargetCpuAndFeaturesAttributes(context: Context, llvmFunction: LLVMValueRef) {
context.config.platform.targetCpu?.let {
LLVMAddTargetDependentFunctionAttr(llvmFunction, "target-cpu", it)
}
context.config.platform.targetCpuFeatures?.let {
LLVMAddTargetDependentFunctionAttr(llvmFunction, "target-features", it)
}
}
internal fun addLlvmAttributesForKotlinFunction(context: Context, irFunction: IrFunction, llvmFunction: LLVMValueRef) {
if (irFunction.returnType.isNothing()) {
setFunctionNoReturn(llvmFunction)