Skip to content

Commit 9aa596a

Browse files
committed
moved default CPU message inline
1 parent ea17aa9 commit 9aa596a

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ extern "C" {
22492249

22502250
pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
22512251

2252-
pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
2252+
pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine, cpu: *const c_char);
22532253
pub fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
22542254
pub fn LLVMRustGetTargetFeature(
22552255
T: &TargetMachine,

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,9 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
330330
let tm = create_informational_target_machine(sess);
331331
match req {
332332
PrintRequest::TargetCPUs => {
333-
println!(
334-
"Default CPU for this target:\n {}",
335-
handle_native(sess.target.cpu.as_ref())
336-
);
337-
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, handle_native(sess.target.cpu.as_ref())) };
333+
let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref()))
334+
.expect("failed to convert to cstring");
335+
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };
338336
}
339337
PrintRequest::TargetFeatures => print_target_features(sess, tm),
340338
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static size_t getLongestEntryLength(ArrayRef<KV> Table) {
307307
return MaxLen;
308308
}
309309

310-
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, &Char[]) {
310+
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, const char* TargetCPU) {
311311
const TargetMachine *Target = unwrap(TM);
312312
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
313313
const Triple::ArchType HostArch = Triple(sys::getDefaultTargetTriple()).getArch();
@@ -323,16 +323,14 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM, &Char[]) {
323323
printf(" %-*s - Select the CPU of the current host (currently %.*s).\n",
324324
MaxCPULen, "native", (int)HostCPU.size(), HostCPU.data());
325325
}
326-
for (auto &CPU : CPUTable)
327-
326+
for (auto &CPU : CPUTable) {
328327
printf(" %-*s", MaxCPULen, CPU.Key);
329-
if (CPU.Key == Target->getTargetTriple().getArch()) {
330-
printf(" default target\n");
331-
}
332-
else {
333-
printf("\n");
328+
// Compare cpu against current target to label the default
329+
if (strcmp(CPU.Key, TargetCPU) == 0) {
330+
printf(" - this is the default target cpu for the current target");
334331
}
335-
printf("\n");
332+
printf("\n");
333+
}
336334
}
337335

338336
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {

0 commit comments

Comments
 (0)