cranelift: Only emit stack maps when a function actually uses reference types

This fix avoids a small slow down in scenarios where reference types are enabled
but a given function doesn't actually use them.

Fixes #1883
This commit is contained in:
Nick Fitzgerald
2020-08-07 11:50:05 -07:00
parent 94e4bad1e0
commit 5af47dc4cd

View File

@@ -203,17 +203,22 @@ impl Context {
&mut self.tracker, &mut self.tracker,
); );
// This function runs after register allocation has taken // If there are any reference types used, encode safepoints and emit
// place, meaning values have locations assigned already. // stack maps.
if isa.flags().enable_safepoints() { //
emit_stack_maps(func, domtree, &self.liveness, &mut self.tracker, isa); // This function runs after register allocation has taken place, meaning
} else { // values have locations assigned already, which is necessary for
// Make sure no references are used. // creating the stack maps.
for val in func.dfg.values() { let safepoints_enabled = isa.flags().enable_safepoints();
let ty = func.dfg.value_type(val); for val in func.dfg.values() {
if ty.lane_type().is_ref() { let ty = func.dfg.value_type(val);
panic!("reference types were found but safepoints were not enabled."); if ty.lane_type().is_ref() {
} assert!(
safepoints_enabled,
"reference types were found but safepoints were not enabled"
);
emit_stack_maps(func, domtree, &self.liveness, &mut self.tracker, isa);
break;
} }
} }