cranelift: Port most of simple_preopt.rs over to the peepmatic DSL

This ports all of the identity, no-op, simplification, and canonicalization
related optimizations over from being hand-coded to the `peepmatic` DSL. This
does not handle the branch-to-branch optimizations or most of the
divide-by-constant optimizations.
This commit is contained in:
Nick Fitzgerald
2020-04-28 16:43:32 -07:00
parent 18663fede9
commit 090d1c2d32
20 changed files with 1289 additions and 488 deletions

View File

@@ -308,6 +308,30 @@ impl Function {
// function, assume it is not a leaf.
self.dfg.signatures.is_empty()
}
/// Replace the `dst` instruction's data with the `src` instruction's data
/// and then remove `src`.
///
/// `src` and its result values should not be used at all, as any uses would
/// be left dangling after calling this method.
///
/// `src` and `dst` must have the same number of resulting values, and
/// `src`'s i^th value must have the same type as `dst`'s i^th value.
pub fn transplant_inst(&mut self, dst: Inst, src: Inst) {
debug_assert_eq!(
self.dfg.inst_results(dst).len(),
self.dfg.inst_results(src).len()
);
debug_assert!(self
.dfg
.inst_results(dst)
.iter()
.zip(self.dfg.inst_results(src))
.all(|(a, b)| self.dfg.value_type(*a) == self.dfg.value_type(*b)));
self.dfg[dst] = self.dfg[src].clone();
self.layout.remove_inst(src);
}
}
/// Additional annotations for function display.