--print target-cpus shows default target cpu, updated docs

This commit is contained in:
James Dietz 2023-04-26 21:11:14 -04:00
parent eb7a743421
commit ea17aa9141
3 changed files with 18 additions and 4 deletions

View File

@ -329,7 +329,13 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
require_inited(); require_inited();
let tm = create_informational_target_machine(sess); let tm = create_informational_target_machine(sess);
match req { match req {
PrintRequest::TargetCPUs => unsafe { llvm::LLVMRustPrintTargetCPUs(tm) }, PrintRequest::TargetCPUs => {
println!(
"Default CPU for this target:\n {}",
handle_native(sess.target.cpu.as_ref())
);
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, handle_native(sess.target.cpu.as_ref())) };
}
PrintRequest::TargetFeatures => print_target_features(sess, tm), PrintRequest::TargetFeatures => print_target_features(sess, tm),
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req), _ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
} }

View File

@ -307,7 +307,7 @@ static size_t getLongestEntryLength(ArrayRef<KV> Table) {
return MaxLen; return MaxLen;
} }
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) { extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, &Char[]) {
const TargetMachine *Target = unwrap(TM); const TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo(); const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch(); const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch();
@ -324,7 +324,14 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
MaxCPULen, "native", (int)HostCPU.size(), HostCPU.data()); MaxCPULen, "native", (int)HostCPU.size(), HostCPU.data());
} }
for (auto &CPU : CPUTable) for (auto &CPU : CPUTable)
printf(" %-*s\n", MaxCPULen, CPU.Key);
printf(" %-*s", MaxCPULen, CPU.Key);
if (CPU.Key == Target->getTargetTriple().getArch()) {
printf(" default target\n");
}
else {
printf("\n");
}
printf("\n"); printf("\n");
} }

View File

@ -574,7 +574,8 @@ change in the future.
This instructs `rustc` to generate code specifically for a particular processor. This instructs `rustc` to generate code specifically for a particular processor.
You can run `rustc --print target-cpus` to see the valid options to pass You can run `rustc --print target-cpus` to see the valid options to pass
here. Each target has a default base CPU. Special values include: and the default target CPU for the current buid target.
Each target has a default base CPU. Special values include:
* `native` can be passed to use the processor of the host machine. * `native` can be passed to use the processor of the host machine.
* `generic` refers to an LLVM target with minimal features but modern tuning. * `generic` refers to an LLVM target with minimal features but modern tuning.