@@ -5053,21 +5053,21 @@ impl Function {
50535053 }
50545054
50555055 for block in self . rpo ( ) {
5056- let mut dead_stores : HashSet < InsnId > = HashSet :: new ( ) ;
5056+ // TODO: Probably convert this to a vec of tuples? Time complexity is worse but constant factors are better
50575057 let mut active_stores: HashMap < StoreHeap , InsnId > = HashMap :: new ( ) ;
5058- let mut insns = std:: mem:: take ( & mut self . blocks [ block. 0 ] . insns ) ;
5059- // TODO: Figure out if we should make the pass run backwards and do it all in one sweep
5060- // Or if we should do it from top to bottom for readability, but require a second pass
5061- for i in ( 0 ..insns . len ( ) ) . rev ( ) {
5062- let insn_id = insns [ i ] ;
5058+ let insns = std:: mem:: take ( & mut self . blocks [ block. 0 ] . insns ) ;
5059+ let mut new_insns = vec ! [ ] ;
5060+ for insn_id_ref in insns . iter ( ) . rev ( ) {
5061+ // TODO: This is ugly, clean this up
5062+ let insn_id = * insn_id_ref ;
50635063 match self . find ( insn_id) {
50645064 Insn :: StoreField { recv, offset, .. } => {
50655065 let key = StoreHeap { object : self . chase_insn ( recv) , offset } ;
50665066 // If an older store is being tracked, then there have
50675067 // been no usees between stores and the first store is
5068- // dead.
5068+ // dead and should not be emitted .
50695069 if active_stores. contains_key ( & key) {
5070- dead_stores . insert ( insn_id ) ;
5070+ continue
50715071 }
50725072 // Otherwise, we have a new store to begin tracking.
50735073 // Because we don't have type based alias analysis, we
@@ -5107,18 +5107,21 @@ impl Function {
51075107 } ,
51085108 insn => {
51095109 // If the instruction can read memory, we cannot assume
5110- // entries of active_stores are not loaded.
5111- if insn. effects_of ( ) . includes ( Effect :: write ( abstract_heaps:: Memory ) ) {
5110+ // entries of active_stores are not loaded. This is because we use
5111+ // extended basic blocks and we should probably change this to be
5112+ // standard basic blocks.
5113+ if insn. effects_of ( ) . includes ( Effect :: read ( abstract_heaps:: Memory ) ) {
5114+ active_stores. clear ( ) ;
5115+ }
5116+ else if insn. effects_of ( ) . includes ( effects:: Control ) {
51125117 active_stores. clear ( ) ;
51135118 }
51145119 }
5115-
51165120 }
5121+ new_insns. push ( insn_id) ;
51175122 }
5118- // TODO: Figure out how to remove extraneous write barriers
5119- // Prune away any dead stores
5120- insns. retain ( |i| !dead_stores. contains ( i) ) ;
5121- self . blocks [ block. 0 ] . insns = insns;
5123+ new_insns. reverse ( ) ;
5124+ self . blocks [ block. 0 ] . insns = new_insns;
51225125 }
51235126 }
51245127
0 commit comments