From 6f67d4cf8f55982ae9a24f161c5a7f87b09a474c Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 14 Sep 2023 14:11:16 +0800 Subject: [PATCH] artiq: Specify target CPU when creating LLVM target options We can try to optimize for the host and Cortex-A9 chips; The RISC-V ISAs do not target specific chips, so we will fallback to using the generic CPU. --- nac3artiq/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index db0d22b..7c7dfe2 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -688,6 +688,15 @@ impl Nac3 { } } + /// Returns the [String] representing the target CPU used for compiling to [isa]. + fn get_llvm_target_cpu(isa: Isa) -> String { + match isa { + Isa::Host => TargetMachine::get_host_cpu_name().to_string(), + Isa::RiscV32G | Isa::RiscV32IMA => "generic-rv32".to_string(), + Isa::CortexA9 => "cortex-a9".to_string(), + } + } + /// Returns the [String] representing the target features used for compiling to [isa]. fn get_llvm_target_features(isa: Isa) -> String { match isa { @@ -703,7 +712,7 @@ impl Nac3 { fn get_llvm_target_options(isa: Isa) -> CodeGenTargetMachineOptions { CodeGenTargetMachineOptions { triple: Nac3::get_llvm_target_triple(isa).as_str().to_string_lossy().into_owned(), - cpu: String::default(), + cpu: Nac3::get_llvm_target_cpu(isa), features: Nac3::get_llvm_target_features(isa), reloc_mode: RelocMode::PIC, ..CodeGenTargetMachineOptions::from_host()