Skip to content

Commit 3959d47

Browse files
authored
Rollup merge of rust-lang#111203 - Kobzol:remark-print-kind, r=tmiasko
Output LLVM optimization remark kind in `-Cremark` output Since rust-lang#90833, the optimization remark kind has not been printed. Therefore it wasn't possible to easily determine from the log (in a programmatic way) which remark kind was produced. I think that the most interesting remarks are the missed ones, which can lead users to some code optimization. Maybe we could also change the format closer to the "old" one: ``` note: optimization remark for tailcallelim at /checkout/src/libcore/num/mod.rs:1:0: marked this call a tail call candidate ``` I wanted to programatically parse the remarks so that they could work e.g. with https://github.com/OfekShilon/optview2. However, now that I think about it, probably the proper solution is to tell rustc to output them to YAML and then use the YAML as input for the opt remark visualization tools. The flag for enabling this does not seem to work though (rust-lang#96705 (comment)). Still I think that it's good to output the remark kind anyway, it's an important piece of information. r? ``@tmiasko``
2 parents 5a98d2d + 00ac29d commit 3959d47

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

compiler/rustc_codegen_llvm/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ codegen_llvm_prepare_thin_lto_module_with_llvm_err = failed to prepare thin LTO
8282
codegen_llvm_parse_bitcode = failed to parse bitcode for LTO module
8383
codegen_llvm_parse_bitcode_with_llvm_err = failed to parse bitcode for LTO module: {$llvm_err}
8484
85-
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name}: {$message}
85+
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}
8686
codegen_llvm_from_llvm_diag = {$message}
8787
8888
codegen_llvm_write_bytecode = failed to write bytecode to {$path}: {$err}

compiler/rustc_codegen_llvm/src/back/write.rs

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_span::symbol::sym;
3131
use rustc_span::InnerSpan;
3232
use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo};
3333

34+
use crate::llvm::diagnostic::OptimizationDiagnosticKind;
3435
use libc::{c_char, c_int, c_uint, c_void, size_t};
3536
use std::ffi::CString;
3637
use std::fs;
@@ -363,6 +364,15 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
363364
line: opt.line,
364365
column: opt.column,
365366
pass_name: &opt.pass_name,
367+
kind: match opt.kind {
368+
OptimizationDiagnosticKind::OptimizationRemark => "success",
369+
OptimizationDiagnosticKind::OptimizationMissed
370+
| OptimizationDiagnosticKind::OptimizationFailure => "missed",
371+
OptimizationDiagnosticKind::OptimizationAnalysis
372+
| OptimizationDiagnosticKind::OptimizationAnalysisFPCommute
373+
| OptimizationDiagnosticKind::OptimizationAnalysisAliasing => "analysis",
374+
OptimizationDiagnosticKind::OptimizationRemarkOther => "other",
375+
},
366376
message: &opt.message,
367377
});
368378
}

compiler/rustc_codegen_llvm/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub(crate) struct FromLlvmOptimizationDiag<'a> {
196196
pub line: std::ffi::c_uint,
197197
pub column: std::ffi::c_uint,
198198
pub pass_name: &'a str,
199+
pub kind: &'a str,
199200
pub message: &'a str,
200201
}
201202

tests/ui/optimization-remark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// [merge1] compile-flags: -Cremark=all -Cremark=giraffe
1414
// [merge2] compile-flags: -Cremark=inline -Cremark=giraffe
1515
//
16-
// error-pattern: inline: 'f' not inlined into 'g'
16+
// error-pattern: inline (missed): 'f' not inlined into 'g'
1717
// dont-check-compiler-stderr
1818

1919
#[no_mangle]

0 commit comments

Comments
 (0)