diff options
5 files changed, 14 insertions, 15 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 8d57ccdba6d..353189ae1f0 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -196,7 +196,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mut bx: Bx, discr: &mir::Operand<'tcx>, switch_ty: Ty<'tcx>, - targets: &SwitchTargets<'tcx>, + targets: &SwitchTargets, ) { let discr = self.codegen_operand(&mut bx, &discr); // `switch_ty` is redundant, sanity-check that. diff --git a/compiler/rustc_middle/src/mir/terminator/mod.rs b/compiler/rustc_middle/src/mir/terminator/mod.rs index 677776106f5..e1071454e65 100644 --- a/compiler/rustc_middle/src/mir/terminator/mod.rs +++ b/compiler/rustc_middle/src/mir/terminator/mod.rs @@ -1,6 +1,7 @@ use crate::mir::interpret::Scalar; use crate::ty::{self, Ty, TyCtxt}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; +use smallvec::{smallvec, SmallVec}; use super::{ AssertMessage, BasicBlock, InlineAsmOperand, Operand, Place, SourceInfo, Successors, @@ -17,10 +18,10 @@ use std::slice; pub use super::query::*; #[derive(Debug, Clone, TyEncodable, TyDecodable, HashStable, PartialEq)] -pub struct SwitchTargets<'tcx> { +pub struct SwitchTargets { /// Possible values. The locations to branch to in each case /// are found in the corresponding indices from the `targets` vector. - values: Cow<'tcx, [u128]>, + values: SmallVec<[u128; 1]>, /// Possible branch sites. The last element of this vector is used /// for the otherwise branch, so targets.len() == values.len() + 1 @@ -34,24 +35,24 @@ pub struct SwitchTargets<'tcx> { // // However we’ve decided to keep this as-is until we figure a case // where some other approach seems to be strictly better than other. - targets: Vec<BasicBlock>, + targets: SmallVec<[BasicBlock; 2]>, } -impl<'tcx> SwitchTargets<'tcx> { +impl SwitchTargets { /// Creates switch targets from an iterator of values and target blocks. /// /// The iterator may be empty, in which case the `SwitchInt` instruction is equivalent to /// `goto otherwise;`. pub fn new(targets: impl Iterator<Item = (u128, BasicBlock)>, otherwise: BasicBlock) -> Self { - let (values, mut targets): (Vec<_>, Vec<_>) = targets.unzip(); + let (values, mut targets): (SmallVec<_>, SmallVec<_>) = targets.unzip(); targets.push(otherwise); Self { values: values.into(), targets } } /// Builds a switch targets definition that jumps to `then` if the tested value equals `value`, /// and to `else_` if not. - pub fn static_if(value: &'static [u128; 1], then: BasicBlock, else_: BasicBlock) -> Self { - Self { values: Cow::Borrowed(value), targets: vec![then, else_] } + pub fn static_if(value: u128, then: BasicBlock, else_: BasicBlock) -> Self { + Self { values: smallvec![value], targets: smallvec![then, else_] } } /// Returns the fallback target that is jumped to when none of the values match the operand. @@ -113,7 +114,7 @@ pub enum TerminatorKind<'tcx> { /// FIXME: remove this redundant information. Currently, it is relied on by pretty-printing. switch_ty: Ty<'tcx>, - targets: SwitchTargets<'tcx>, + targets: SwitchTargets, }, /// Indicates that the landing pad is finished and unwinding should @@ -295,7 +296,7 @@ impl<'tcx> TerminatorKind<'tcx> { TerminatorKind::SwitchInt { discr: cond, switch_ty: tcx.types.bool, - targets: SwitchTargets::static_if(&[0], f, t), + targets: SwitchTargets::static_if(0, f, t), } } diff --git a/compiler/rustc_mir/src/dataflow/framework/direction.rs b/compiler/rustc_mir/src/dataflow/framework/direction.rs index 72e3a876254..8a9ced91eb3 100644 --- a/compiler/rustc_mir/src/dataflow/framework/direction.rs +++ b/compiler/rustc_mir/src/dataflow/framework/direction.rs @@ -514,7 +514,7 @@ impl Direction for Forward { struct SwitchIntEdgeEffectApplier<'a, D, F> { exit_state: &'a mut D, - targets: &'a SwitchTargets<'a>, + targets: &'a SwitchTargets, propagate: F, effects_applied: bool, diff --git a/compiler/rustc_mir/src/transform/simplify_comparison_integral.rs b/compiler/rustc_mir/src/transform/simplify_comparison_integral.rs index 50f5fbb3bc2..6372f8960dd 100644 --- a/compiler/rustc_mir/src/transform/simplify_comparison_integral.rs +++ b/compiler/rustc_mir/src/transform/simplify_comparison_integral.rs @@ -227,5 +227,5 @@ struct OptimizationInfo<'tcx> { /// Either Eq or Ne op: BinOp, /// Current targets used in the switch - targets: SwitchTargets<'tcx>, + targets: SwitchTargets, } diff --git a/compiler/rustc_mir/src/util/elaborate_drops.rs b/compiler/rustc_mir/src/util/elaborate_drops.rs index 4a48b335ce9..0e2d8e5495b 100644 --- a/compiler/rustc_mir/src/util/elaborate_drops.rs +++ b/compiler/rustc_mir/src/util/elaborate_drops.rs @@ -760,8 +760,6 @@ where let elem_size = Place::from(self.new_temp(tcx.types.usize)); let len = Place::from(self.new_temp(tcx.types.usize)); - static USIZE_SWITCH_ZERO: &[u128; 1] = &[0]; - let base_block = BasicBlockData { statements: vec