Small mir-opt refactor

Hopefully-non-controversial changes from some not-ready-yet work that I'd figured I'd submit on their own.
This commit is contained in:
Scott McMurray
2021-11-26 18:18:14 -08:00
parent f7c48297ce
commit b215a32af3
4 changed files with 11 additions and 23 deletions

View File

@@ -1504,6 +1504,7 @@ impl Statement<'_> {
}
/// Changes a statement to a nop and returns the original statement.
#[must_use = "If you don't need the statement, use `make_nop` instead"]
pub fn replace_nop(&mut self) -> Self {
Statement {
source_info: self.source_info,

View File

@@ -78,6 +78,13 @@ impl SwitchTargets {
pub fn all_targets_mut(&mut self) -> &mut [BasicBlock] {
&mut self.targets
}
/// Finds the `BasicBlock` to which this `SwitchInt` will branch given the
/// specific value. This cannot fail, as it'll return the `otherwise`
/// branch if there's not a specific match for the value.
pub fn target_for_value(&self, value: u128) -> BasicBlock {
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
}
}
pub struct SwitchTargetsIter<'a> {