Polished documentation, removed not-so-useful-anymore traces, and added some doc comments in mir/transform/const_prop.rs
This commit is contained in:
parent
05d7a60ff8
commit
16ebaf9273
@ -446,6 +446,7 @@ fn use_ecx<F, T>(&mut self, f: F) -> Option<T>
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the value, if any, of evaluating `c`.
|
||||
fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
|
||||
// FIXME we need to revisit this for #67176
|
||||
if c.needs_subst() {
|
||||
@ -486,11 +487,14 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the value, if any, of evaluating `place`.
|
||||
fn eval_place(&mut self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
||||
trace!("eval_place(place={:?})", place);
|
||||
self.use_ecx(|this| this.ecx.eval_place_to_op(place, None))
|
||||
}
|
||||
|
||||
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
|
||||
/// or `eval_place`, depending on the variant of `Operand` used.
|
||||
fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
|
||||
match *op {
|
||||
Operand::Constant(ref c) => self.eval_constant(c, source_info),
|
||||
@ -649,6 +653,7 @@ fn const_prop(
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a new `Operand::Constant` from a `Scalar` value
|
||||
fn operand_from_scalar(&self, scalar: Scalar, ty: Ty<'tcx>, span: Span) -> Operand<'tcx> {
|
||||
Operand::Constant(Box::new(Constant {
|
||||
span,
|
||||
@ -694,6 +699,7 @@ fn replace_with_const(
|
||||
// Found a value represented as a pair. For now only do cont-prop if type of
|
||||
// Rvalue is also a pair with two scalars. The more general case is more
|
||||
// complicated to implement so we'll do it later.
|
||||
// FIXME: implement the general case stated above ^.
|
||||
let ty = &value.layout.ty.kind;
|
||||
// Only do it for tuples
|
||||
if let ty::Tuple(substs) = ty {
|
||||
@ -730,6 +736,7 @@ fn replace_with_const(
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if and only if this `op` should be const-propagated into.
|
||||
fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
|
||||
let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level;
|
||||
|
||||
@ -771,14 +778,14 @@ enum ConstPropMode {
|
||||
|
||||
struct CanConstProp {
|
||||
can_const_prop: IndexVec<Local, ConstPropMode>,
|
||||
// false at the beginning, once set, there are not allowed to be any more assignments
|
||||
// False at the beginning. Once set, no more assignments are allowed to that local.
|
||||
found_assignment: BitSet<Local>,
|
||||
// Cache of locals' information
|
||||
local_kinds: IndexVec<Local, LocalKind>,
|
||||
}
|
||||
|
||||
impl CanConstProp {
|
||||
/// returns true if `local` can be propagated
|
||||
/// Returns true if `local` can be propagated
|
||||
fn check(body: &Body<'_>) -> IndexVec<Local, ConstPropMode> {
|
||||
let mut cpv = CanConstProp {
|
||||
can_const_prop: IndexVec::from_elem(ConstPropMode::FullConstProp, &body.local_decls),
|
||||
@ -789,8 +796,8 @@ fn check(body: &Body<'_>) -> IndexVec<Local, ConstPropMode> {
|
||||
),
|
||||
};
|
||||
for (local, val) in cpv.can_const_prop.iter_enumerated_mut() {
|
||||
// cannot use args at all
|
||||
// cannot use locals because if x < y { y - x } else { x - y } would
|
||||
// Cannot use args at all
|
||||
// Cannot use locals because if x < y { y - x } else { x - y } would
|
||||
// lint for x != y
|
||||
// FIXME(oli-obk): lint variables until they are used in a condition
|
||||
// FIXME(oli-obk): lint if return value is constant
|
||||
@ -936,7 +943,7 @@ fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Loca
|
||||
let expected = ScalarMaybeUndef::from(Scalar::from_bool(*expected));
|
||||
let value_const = self.ecx.read_scalar(value).unwrap();
|
||||
if expected != value_const {
|
||||
// poison all places this operand references so that further code
|
||||
// Poison all places this operand references so that further code
|
||||
// doesn't use the invalid value
|
||||
match cond {
|
||||
Operand::Move(ref place) | Operand::Copy(ref place) => {
|
||||
@ -1002,7 +1009,7 @@ fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Loca
|
||||
}
|
||||
}
|
||||
}
|
||||
//none of these have Operands to const-propagate
|
||||
// None of these have Operands to const-propagate
|
||||
TerminatorKind::Goto { .. }
|
||||
| TerminatorKind::Resume
|
||||
| TerminatorKind::Abort
|
||||
|
Loading…
Reference in New Issue
Block a user