@@ -41,7 +41,6 @@ import SIL
4141///
4242let objectOutliner = FunctionPass ( name: " object-outliner " ) {
4343 ( function: Function , context: FunctionPassContext ) in
44-
4544 for inst in function. instructions {
4645 if let ari = inst as? AllocRefInstBase {
4746 if let globalValue = optimizeObjectAllocation ( allocRef: ari, context) {
@@ -155,7 +154,7 @@ private func findInitStores(of object: Value,
155154 return false
156155 }
157156 default :
158- if !isValidUseOfObject( use. instruction ) {
157+ if !isValidUseOfObject( use) {
159158 return false
160159 }
161160 }
@@ -182,6 +181,18 @@ private func findStores(toTailAddress tailAddr: Value, tailElementIndex: Int, st
182181 if !findStores( inUsesOf: tea, index: tailElementIndex * numTupleElements + tupleIdx, stores: & stores) {
183182 return false
184183 }
184+ case let atp as AddressToPointerInst :
185+ if !findStores( toTailAddress: atp, tailElementIndex: tailElementIndex, stores: & stores) {
186+ return false
187+ }
188+ case let mdi as MarkDependenceInst :
189+ if !findStores( toTailAddress: mdi, tailElementIndex: tailElementIndex, stores: & stores) {
190+ return false
191+ }
192+ case let pta as PointerToAddressInst :
193+ if !findStores( toTailAddress: pta, tailElementIndex: tailElementIndex, stores: & stores) {
194+ return false
195+ }
185196 case let store as StoreInst :
186197 if store. source. type. isTuple {
187198 // This kind of SIL is never generated because tuples are stored with separated stores to tuple_element_addr.
@@ -192,7 +203,7 @@ private func findStores(toTailAddress tailAddr: Value, tailElementIndex: Int, st
192203 return false
193204 }
194205 default :
195- if !isValidUseOfObject( use. instruction ) {
206+ if !isValidUseOfObject( use) {
196207 return false
197208 }
198209 }
@@ -206,7 +217,7 @@ private func findStores(inUsesOf address: Value, index: Int, stores: inout [Stor
206217 if !handleStore( store, index: index, stores: & stores) {
207218 return false
208219 }
209- } else if !isValidUseOfObject( use. instruction ) {
220+ } else if !isValidUseOfObject( use) {
210221 return false
211222 }
212223 }
@@ -223,7 +234,8 @@ private func handleStore(_ store: StoreInst, index: Int, stores: inout [StoreIns
223234 return false
224235}
225236
226- private func isValidUseOfObject( _ inst: Instruction ) -> Bool {
237+ private func isValidUseOfObject( _ use: Operand ) -> Bool {
238+ let inst = use. instruction
227239 switch inst {
228240 case is DebugValueInst ,
229241 is LoadInst ,
@@ -235,6 +247,17 @@ private func isValidUseOfObject(_ inst: Instruction) -> Bool {
235247 is EndCOWMutationInst :
236248 return true
237249
250+ case let mdi as MarkDependenceInst :
251+ if ( use == mdi. baseOperand) {
252+ return true ;
253+ }
254+ for mdiUse in mdi. uses {
255+ if !isValidUseOfObject( mdiUse) {
256+ return false
257+ }
258+ }
259+ return true
260+
238261 case is StructElementAddrInst ,
239262 is AddressToPointerInst ,
240263 is StructInst ,
@@ -246,9 +269,12 @@ private func isValidUseOfObject(_ inst: Instruction) -> Bool {
246269 is UpcastInst ,
247270 is BeginDeallocRefInst ,
248271 is RefTailAddrInst ,
249- is RefElementAddrInst :
250- for use in ( inst as! SingleValueInstruction ) . uses {
251- if !isValidUseOfObject( use. instruction) {
272+ is RefElementAddrInst ,
273+ is StructInst ,
274+ is PointerToAddressInst ,
275+ is IndexAddrInst :
276+ for instUse in ( inst as! SingleValueInstruction ) . uses {
277+ if !isValidUseOfObject( instUse) {
252278 return false
253279 }
254280 }
0 commit comments