Implement JumpThreading pass.
This commit is contained in:
@@ -28,6 +28,15 @@ impl SwitchTargets {
|
||||
Self { values: smallvec![value], targets: smallvec![then, else_] }
|
||||
}
|
||||
|
||||
/// Inverse of `SwitchTargets::static_if`.
|
||||
pub fn as_static_if(&self) -> Option<(u128, BasicBlock, BasicBlock)> {
|
||||
if let &[value] = &self.values[..] && let &[then, else_] = &self.targets[..] {
|
||||
Some((value, then, else_))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the fallback target that is jumped to when none of the values match the operand.
|
||||
pub fn otherwise(&self) -> BasicBlock {
|
||||
*self.targets.last().unwrap()
|
||||
|
||||
Reference in New Issue
Block a user