Skip to content

Commit 708b86c

Browse files
authored
Don't panic when instructions aren't in ISLE (#9631)
Instead return a codegen error which can be more easily caught, displayed, and rendered. This is intended to help with enabling testing of Pulley in the near future where Pulley doesn't implement most instructions at this time and this should make the in-progress state of the backend a bit easier to test.
1 parent 34504fe commit 708b86c

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

cranelift/codegen/src/machinst/lower.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::machinst::{
2020
VCodeConstants, VCodeInst, ValueRegs, Writable,
2121
};
2222
use crate::settings::Flags;
23-
use crate::{trace, CodegenResult};
23+
use crate::{trace, CodegenError, CodegenResult};
2424
use alloc::vec::Vec;
2525
use cranelift_control::ControlPlane;
2626
use rustc_hash::{FxHashMap, FxHashSet};
@@ -676,18 +676,21 @@ impl<'func, I: VCodeInst> Lower<'func, I> {
676676
// or any of its outputs is used.
677677
if has_side_effect || value_needed {
678678
trace!("lowering: inst {}: {}", inst, self.f.dfg.display_inst(inst));
679-
let temp_regs = backend.lower(self, inst).unwrap_or_else(|| {
680-
let ty = if self.num_outputs(inst) > 0 {
681-
Some(self.output_ty(inst, 0))
682-
} else {
683-
None
684-
};
685-
panic!(
686-
"should be implemented in ISLE: inst = `{}`, type = `{:?}`",
687-
self.f.dfg.display_inst(inst),
688-
ty
689-
)
690-
});
679+
let temp_regs = match backend.lower(self, inst) {
680+
Some(regs) => regs,
681+
None => {
682+
let ty = if self.num_outputs(inst) > 0 {
683+
Some(self.output_ty(inst, 0))
684+
} else {
685+
None
686+
};
687+
return Err(CodegenError::Unsupported(format!(
688+
"should be implemented in ISLE: inst = `{}`, type = `{:?}`",
689+
self.f.dfg.display_inst(inst),
690+
ty
691+
)));
692+
}
693+
};
691694

692695
// The ISLE generated code emits its own registers to define the
693696
// instruction's lowered values in. However, other instructions

0 commit comments

Comments
 (0)