]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Auto merge of #104999 - saethlin:immediate-abort-inlining, r=thomcc
[rust.git] / compiler / rustc_mir_transform / src / dataflow_const_prop.rs
index 2ed8a6f161f7ff77ca4fab5878ef944e8b408840..e9027387413cfe1e97425a7992e74e33384fbfb3 100644 (file)
@@ -13,6 +13,8 @@
 
 use crate::MirPass;
 
+// These constants are somewhat random guesses and have not been optimized.
+// If `tcx.sess.mir_opt_level() >= 4`, we ignore the limits (this can become very expensive).
 const BLOCK_LIMIT: usize = 100;
 const PLACE_LIMIT: usize = 100;
 
 
 impl<'tcx> MirPass<'tcx> for DataflowConstProp {
     fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
-        sess.mir_opt_level() >= 1
+        sess.mir_opt_level() >= 3
     }
 
     #[instrument(skip_all level = "debug")]
     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
-        if body.basic_blocks.len() > BLOCK_LIMIT {
+        if tcx.sess.mir_opt_level() < 4 && body.basic_blocks.len() > BLOCK_LIMIT {
             debug!("aborted dataflow const prop due too many basic blocks");
             return;
         }
@@ -41,7 +43,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
         // `O(num_nodes * tracked_places * n)` in terms of time complexity. Since the number of
         // map nodes is strongly correlated to the number of tracked places, this becomes more or
         // less `O(n)` if we place a constant limit on the number of tracked places.
-        if map.tracked_places() > PLACE_LIMIT {
+        if tcx.sess.mir_opt_level() < 4 && map.tracked_places() > PLACE_LIMIT {
             debug!("aborted dataflow const prop due to too many tracked places");
             return;
         }
@@ -316,7 +318,7 @@ struct CollectAndPatch<'tcx, 'map> {
 
     /// For a given MIR location, this stores the values of the operands used by that location. In
     /// particular, this is before the effect, such that the operands of `_1 = _1 + _2` are
-    /// properly captured.
+    /// properly captured. (This may become UB soon, but it is currently emitted even by safe code.)
     before_effect: FxHashMap<(Location, Place<'tcx>), ScalarTy<'tcx>>,
 
     /// Stores the assigned values for assignments where the Rvalue is constant.