@@ -413,6 +413,7 @@ pub enum FunctionProcessingStage<'a, S: Settings<'a>> {
413
413
tree : LiftedBlockTree < ' a > ,
414
414
} ,
415
415
PlainDag ( Dag < ' a > ) ,
416
+ ConstCollapsedDag ( Dag < ' a > ) ,
416
417
ConstDedupDag ( Dag < ' a > ) ,
417
418
DanglingOptDag ( Dag < ' a > ) ,
418
419
BlocklessDag ( BlocklessDag < ' a > ) ,
@@ -455,6 +456,15 @@ impl<'a, S: Settings<'a>> FunctionProcessingStage<'a, S> {
455
456
FunctionProcessingStage :: PlainDag ( dag)
456
457
}
457
458
FunctionProcessingStage :: PlainDag ( mut dag) => {
459
+ // Optimization pass: collapse constants into instructions that use them, if possible.
460
+ let constants_collapsed =
461
+ dag:: const_collapse:: constant_collapse ( settings, & mut dag) ;
462
+ if let Some ( stats) = stats {
463
+ stats. constants_deduplicated += constants_collapsed;
464
+ }
465
+ FunctionProcessingStage :: ConstCollapsedDag ( dag)
466
+ }
467
+ FunctionProcessingStage :: ConstCollapsedDag ( mut dag) => {
458
468
// Optimization pass: deduplicate const definitions in the DAG.
459
469
let constants_deduplicated = dag:: const_dedup:: deduplicate_constants ( & mut dag) ;
460
470
if let Some ( stats) = stats {
@@ -692,6 +702,8 @@ fn pack_bytes_into_words(bytes: &[u8], mut alignment: u32) -> Vec<MemoryEntry> {
692
702
pub struct Statistics {
693
703
/// Number of register copies saved by the "smart" register allocation.
694
704
pub register_copies_saved : usize ,
705
+ /// Number of constants collapsed into instructions.
706
+ pub constants_collapsed : usize ,
695
707
/// Number of constants deduplicated in the DAG.
696
708
pub constants_deduplicated : usize ,
697
709
/// Number of dangling nodes removed from the DAG.
@@ -706,8 +718,9 @@ impl Display for Statistics {
706
718
fn fmt ( & self , f : & mut Formatter ) -> std:: fmt:: Result {
707
719
write ! (
708
720
f,
709
- "Optimization statistics:\n - {} register copies saved\n - {} constants deduplicated\n - {} dangling nodes removed\n - {} block outputs removed\n - {} useless jumps removed" ,
721
+ "Optimization statistics:\n - {} register copies saved\n - {} constants collapsed \n - {} constants deduplicated\n - {} dangling nodes removed\n - {} block outputs removed\n - {} useless jumps removed" ,
710
722
self . register_copies_saved,
723
+ self . constants_collapsed,
711
724
self . constants_deduplicated,
712
725
self . dangling_nodes_removed,
713
726
self . block_outputs_removed,
0 commit comments