@@ -4604,12 +4604,19 @@ impl Function {
46044604 self . infer_types ( ) ;
46054605 }
46064606
4607+ // struct Heap {
4608+ // fn load(obj, offset)
4609+ // fn kill(obj, offset)
4610+ // fn store(obj, offset, val)
4611+ // }
4612+
46074613 fn optimize_load_store ( & mut self ) {
46084614 // TODO: Add specific tests for load_store
46094615 // TODO: Add dead store elimination
46104616 // The key for the hashmap should be type and offset, with a value of value
46114617 // This lets us to index in with both load and store fields since insn_ids are probably always going to be different and we can't easily match on that
46124618 // So... how do we match against and store the enum label without all the data?? not sure yet :/
4619+ eprintln ! ( "{}" , FunctionPrinter :: with_snapshot( self ) ) ;
46134620 let mut compile_time_heap: HashMap < ( InsnId , i32 ) , InsnId > = HashMap :: new ( ) ;
46144621 for block in self . rpo ( ) {
46154622 let old_insns = std:: mem:: take ( & mut self . blocks [ block. 0 ] . insns ) ;
@@ -4618,18 +4625,23 @@ impl Function {
46184625 let replacement_insn: InsnId = match self . find ( insn_id) {
46194626 Insn :: StoreField { recv, offset, val, .. } => {
46204627 let key = ( recv, offset) ;
4621-
4628+ eprintln ! ( "hi jane" ) ;
46224629 let heap_entry = compile_time_heap. get ( & key) . copied ( ) ;
4630+ eprintln ! ( "{heap_entry:?}" ) ;
46234631 // TODO(Jacob): Switch from actual to partial equality
46244632 if Some ( val) == heap_entry {
4633+ eprintln ! ( "Matched value {val}, {heap_entry:?}" ) ;
46254634 // TODO(Jacob): Add TBAA to avoid removing so many entries
4626- compile_time_heap. retain ( |( _, off) , _| * off == offset) ;
4635+ eprintln ! ( "Erasing aliasing offsets {offset}" ) ;
4636+ compile_time_heap. retain ( |( _, off) , _| * off != offset) ;
46274637 // If the value is already stored, short circuit and don't add an instruction to the block
46284638 continue
46294639 }
46304640 // TODO(Jacob): Add TBAA to avoid removing so many entries
4631- compile_time_heap. retain ( |( _, off) , _| * off == offset) ;
4641+ eprintln ! ( "Erasing aliasing offsets {offset}" ) ;
4642+ compile_time_heap. retain ( |( _, off) , _| * off != offset) ;
46324643 compile_time_heap. insert ( key, val) ;
4644+ eprintln ! ( "Inserted into heap {key:?}, {val}" ) ;
46334645 insn_id
46344646 } ,
46354647 Insn :: LoadField { recv, offset, .. } => {
@@ -4650,6 +4662,7 @@ impl Function {
46504662 insn => {
46514663 // If an instruction affects memory and we haven't modeled it, the compile_time_heap is invalidated
46524664 if insn. effects_of ( ) . includes ( Effect :: write ( abstract_heaps:: Memory ) ) {
4665+ eprintln ! ( "Clearing... {insn:?}" ) ;
46534666 compile_time_heap. clear ( ) ;
46544667 }
46554668 insn_id
@@ -5477,6 +5490,8 @@ impl Function {
54775490 || ident_equal!( $name, optimize_getivar)
54785491 || ident_equal!( $name, optimize_c_calls) {
54795492 Counter :: compile_hir_strength_reduce_time_ns
5493+ } else if ident_equal!( $name, optimize_load_store) {
5494+ Counter :: compile_hir_optimize_load_store_time_ns
54805495 } else if ident_equal!( $name, fold_constants) {
54815496 Counter :: compile_hir_fold_constants_time_ns
54825497 } else if ident_equal!( $name, clean_cfg) {
0 commit comments