about summary refs log tree commit diff
path: root/src/optimize
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-12-31 15:26:58 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2019-12-31 15:56:28 +0100
commit0cb2b6055979c28a7326c7a80c4cf3d51bfad487 (patch)
tree289e2dfd0696785e87575804fffdb1db59a431dc /src/optimize
parentb47c89de0ec4377e2cf8d0c48cb9d1952440ca65 (diff)
downloadrust-0cb2b6055979c28a7326c7a80c4cf3d51bfad487.tar.gz
rust-0cb2b6055979c28a7326c7a80c4cf3d51bfad487.zip
Don't print debug messages in release mode
Diffstat (limited to 'src/optimize')
-rw-r--r--src/optimize/mod.rs2
-rw-r--r--src/optimize/stack2reg.rs32
2 files changed, 26 insertions, 8 deletions
diff --git a/src/optimize/mod.rs b/src/optimize/mod.rs
index 64400e8886a..34f68526136 100644
--- a/src/optimize/mod.rs
+++ b/src/optimize/mod.rs
@@ -8,7 +8,7 @@ pub fn optimize_function<'tcx>(
     ctx: &mut Context,
     clif_comments: &mut crate::pretty_clif::CommentWriter,
 ) {
-    self::stack2reg::optimize_function(ctx, clif_comments, format!("{:?}", instance));
+    self::stack2reg::optimize_function(ctx, clif_comments, instance);
     #[cfg(debug_assertions)]
     crate::pretty_clif::write_clif_file(tcx, "stack2reg", instance, &ctx.func, &*clif_comments, None);
     crate::base::verify_func(tcx, &*clif_comments, &ctx.func);
diff --git a/src/optimize/stack2reg.rs b/src/optimize/stack2reg.rs
index ef0f99bf6b2..210a8c5ec16 100644
--- a/src/optimize/stack2reg.rs
+++ b/src/optimize/stack2reg.rs
@@ -143,10 +143,10 @@ impl<'a> OptimizeContext<'a> {
     }
 }
 
-pub(super) fn optimize_function(
+pub(super) fn optimize_function<T: std::fmt::Debug>(
     ctx: &mut Context,
     clif_comments: &mut crate::pretty_clif::CommentWriter,
-    name: String, // FIXME remove
+    name: T,
 ) {
     combine_stack_addr_with_load_store(&mut ctx.func);
 
@@ -156,7 +156,9 @@ pub(super) fn optimize_function(
 
     remove_unused_stack_addr_and_stack_load(&mut opt_ctx);
 
-    println!("stack slot usage: {:?}", opt_ctx.stack_slot_usage_map);
+    #[cfg(debug_assertions)] {
+        println!("stack slot usage: {:?}", opt_ctx.stack_slot_usage_map);
+    }
 
     for (stack_slot, users) in opt_ctx.stack_slot_usage_map.iter_mut() {
         if users.stack_addr.is_empty().not() {
@@ -171,6 +173,7 @@ pub(super) fn optimize_function(
 
             let potential_stores = users.potential_stores_for_load(&opt_ctx.ctx, load);
 
+            #[cfg(debug_assertions)]
             for &store in &potential_stores {
                 println!(
                     "Potential store -> load forwarding {} -> {} ({:?}, {:?})",
@@ -182,11 +185,19 @@ pub(super) fn optimize_function(
             }
 
             match *potential_stores {
-                [] => println!("[{}] [BUG?] Reading uninitialized memory", name),
+                [] => {
+                    #[cfg(debug_assertions)] {
+                        println!("[{:?}] [BUG?] Reading uninitialized memory", name);
+                    }
+                }
                 [store] if spatial_overlap(&opt_ctx.ctx.func, store, load) == SpatialOverlap::Full && temporal_order(&opt_ctx.ctx, store, load) == TemporalOrder::DefinitivelyBefore => {
                     // Only one store could have been the origin of the value.
                     let stored_value = opt_ctx.ctx.func.dfg.inst_args(store)[0];
-                    println!("Store to load forward {} -> {}", store, load);
+
+                    #[cfg(debug_assertions)] {
+                        println!("Store to load forward {} -> {}", store, load);
+                    }
+
                     users.change_load_to_alias(&mut opt_ctx.ctx.func, load, stored_value);
                 }
                 _ => {} // FIXME implement this
@@ -196,6 +207,7 @@ pub(super) fn optimize_function(
         for store in users.stack_store.clone().into_iter() {
             let potential_loads = users.potential_loads_of_store(&opt_ctx.ctx, store);
 
+            #[cfg(debug_assertions)]
             for &load in &potential_loads {
                 println!(
                     "Potential load from store {} <- {} ({:?}, {:?})",
@@ -209,7 +221,10 @@ pub(super) fn optimize_function(
             if potential_loads.is_empty() {
                 // Never loaded; can safely remove all stores and the stack slot.
                 // FIXME also remove stores when there is always a next store before a load.
-                println!("[{}] Remove dead stack store {} of {}", name, opt_ctx.ctx.func.dfg.display_inst(store, None), stack_slot.0);
+
+                #[cfg(debug_assertions)] {
+                    println!("[{:?}] Remove dead stack store {} of {}", name, opt_ctx.ctx.func.dfg.display_inst(store, None), stack_slot.0);
+                }
                 users.remove_dead_store(&mut opt_ctx.ctx.func, store);
             }
         }
@@ -219,7 +234,9 @@ pub(super) fn optimize_function(
         }
     }
 
-    println!();
+    #[cfg(debug_assertions)] {
+        println!();
+    }
 }
 
 fn combine_stack_addr_with_load_store(func: &mut Function) {
@@ -275,6 +292,7 @@ fn remove_unused_stack_addr_and_stack_load(opt_ctx: &mut OptimizeContext) {
         }
     }
 
+    #[cfg(debug_assertions)]
     for inst in stack_addr_load_insts_users.keys() {
         let mut is_recorded_stack_addr_or_stack_load = false;
         for stack_slot_users in opt_ctx.stack_slot_usage_map.values() {