Skip to content

Commit 3086e44

Browse files
committed
Only call build_value_labels_ranges when necessary
1 parent d4187e6 commit 3086e44

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

src/base.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
7373
let local_map = fx.local_map;
7474
let cold_blocks = fx.cold_blocks;
7575

76-
crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &context.func, &clif_comments, None);
76+
crate::pretty_clif::write_clif_file(
77+
cx.tcx,
78+
"unopt",
79+
None,
80+
instance,
81+
&context,
82+
&clif_comments,
83+
);
7784

7885
// Verify function
7986
verify_func(tcx, &clif_comments, &context.func);
@@ -101,20 +108,14 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
101108
);
102109

103110
// Write optimized function to file for debugging
104-
{
105-
let value_ranges = context
106-
.build_value_labels_ranges(cx.module.isa())
107-
.expect("value location ranges");
108-
109-
crate::pretty_clif::write_clif_file(
110-
cx.tcx,
111-
"opt",
112-
instance,
113-
&context.func,
114-
&clif_comments,
115-
Some(&value_ranges),
116-
);
117-
}
111+
crate::pretty_clif::write_clif_file(
112+
cx.tcx,
113+
"opt",
114+
Some(cx.module.isa()),
115+
instance,
116+
&context,
117+
&clif_comments,
118+
);
118119

119120
// Define debuginfo for function
120121
let isa = cx.module.isa();

src/optimize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ pub(crate) fn optimize_function<'tcx>(
1818
return; // FIXME classify optimizations over opt levels
1919
}
2020
self::stack2reg::optimize_function(ctx, clif_comments);
21-
crate::pretty_clif::write_clif_file(tcx, "stack2reg", instance, &ctx.func, &*clif_comments, None);
21+
crate::pretty_clif::write_clif_file(tcx, "stack2reg", None, instance, &ctx, &*clif_comments);
2222
crate::base::verify_func(tcx, &*clif_comments, &ctx.func);
2323
}

src/pretty_clif.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,22 @@ impl<B: Backend + 'static> FunctionCx<'_, '_, B> {
203203
pub(crate) fn write_clif_file<'tcx>(
204204
tcx: TyCtxt<'tcx>,
205205
postfix: &str,
206+
isa: Option<&dyn cranelift_codegen::isa::TargetIsa>,
206207
instance: Instance<'tcx>,
207-
func: &cranelift_codegen::ir::Function,
208+
context: &cranelift_codegen::Context,
208209
mut clif_comments: &CommentWriter,
209-
value_ranges: Option<&cranelift_codegen::ValueLabelsRanges>,
210210
) {
211+
use std::io::Write;
212+
211213
if !cfg!(debug_assertions) && !tcx.sess.opts.output_types.contains_key(&OutputType::LlvmAssembly) {
212214
return;
213215
}
214216

215-
use std::io::Write;
217+
let value_ranges = isa.map(|isa| {
218+
context
219+
.build_value_labels_ranges(isa)
220+
.expect("value location ranges")
221+
});
216222

217223
let symbol_name = tcx.symbol_name(instance).name.as_str();
218224
let clif_file_name = format!(
@@ -227,12 +233,12 @@ pub(crate) fn write_clif_file<'tcx>(
227233
cranelift_codegen::write::decorate_function(
228234
&mut clif_comments,
229235
&mut clif,
230-
&func,
236+
&context.func,
231237
&DisplayFunctionAnnotations {
232238
isa: Some(&*crate::build_isa(
233239
tcx.sess, true, /* PIC doesn't matter here */
234240
)),
235-
value_ranges,
241+
value_ranges: value_ranges.as_ref(),
236242
},
237243
)
238244
.unwrap();

0 commit comments

Comments
 (0)