Revamp llvm_cpu to select the closest CPU for optimization.

This commit is contained in:
Colin Finck
2021-02-23 16:32:55 +01:00
parent 029f1ea6a6
commit 83ad3d415f
+33 -21
View File
@@ -274,34 +274,46 @@ def arch_to_rust_target_arch(arch):
# generates our target CPU value # generates our target CPU value
def llvm_cpu(d): def llvm_cpu(d):
cpu = d.getVar('PACKAGE_ARCH') # First check if TUNE_CCARGS gives us a specific CPU to build for (via -march).
target = d.getVar('TRANSLATED_TARGET_ARCH') # Translate that GCC -march flag to a Rust/LLVM CPU.
trans = {}
trans['btver2'] = "btver2"
trans['core2'] = "core2"
trans['mips32'] = "mips32"
trans['mips32r2'] = "mips32r2"
trans['nehalem'] = "nehalem"
trans['skylake'] = "skylake"
for arg in (d.getVar('TUNE_CCARGS') or '').split():
if arg.startswith('-march='):
march = arg[7:]
cpu = trans.get(march)
if cpu:
return cpu
# If we don't have -march in TUNE_CCARGS, check TRANSLATED_TARGET_ARCH.
# This must also be translated into a Rust/LLVM CPU.
trans = {} trans = {}
trans['corei7-64'] = "corei7"
trans['core2-32'] = "core2"
trans['x86-64'] = "x86-64"
trans['i686'] = "i686"
trans['i586'] = "i586" trans['i586'] = "i586"
trans['powerpc'] = "powerpc" trans['i686'] = "i686"
trans['mips'] = "mips32"
trans['mipsel'] = "mips32"
trans['mips64'] = "mips64" trans['mips64'] = "mips64"
trans['mips64el'] = "mips64" trans['mips64el'] = "mips64"
trans['riscv64'] = "generic-rv64" trans['powerpc'] = "ppc"
trans['powerpc64'] = "ppc64"
trans['riscv32'] = "generic-rv32" trans['riscv32'] = "generic-rv32"
trans['riscv64'] = "generic-rv64"
trans['x86-64'] = "x86-64"
if target in ["mips", "mipsel"]: target = d.getVar('TRANSLATED_TARGET_ARCH')
feat = frozenset(d.getVar('TUNE_FEATURES').split()) cpu = trans.get(target)
if "mips32r2" in feat: if cpu:
trans['mipsel'] = "mips32r2" return cpu
trans['mips'] = "mips32r2"
elif "mips32" in feat:
trans['mipsel'] = "mips32"
trans['mips'] = "mips32"
try: # If we still didn't get a target CPU, choose "generic".
return trans[cpu] # Further optimization can still happen via llvm_features.
except: return "generic"
return trans.get(target, "generic")
TARGET_LLVM_CPU="${@llvm_cpu(d)}" TARGET_LLVM_CPU="${@llvm_cpu(d)}"
TARGET_LLVM_FEATURES = "${@llvm_features(d)}" TARGET_LLVM_FEATURES = "${@llvm_features(d)}"