@@ -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) {
@@ -85,6 +84,10 @@ private func findEndCOWMutation(of object: Value) -> EndCOWMutationInst? {
8584 if let ecm = findEndCOWMutation ( of: uci) {
8685 return ecm
8786 }
87+ case let urci as UncheckedRefCastInst :
88+ if let ecm = findEndCOWMutation ( of: urci) {
89+ return ecm
90+ }
8891 case let mv as MoveValueInst :
8992 if let ecm = findEndCOWMutation ( of: mv) {
9093 return ecm
@@ -174,6 +177,18 @@ private func findStores(toTailAddress tailAddr: Value, tailElementIndex: Int, st
174177 if !findStores( inUsesOf: tea, index: tailElementIndex * numTupleElements + tupleIdx, stores: & stores) {
175178 return false
176179 }
180+ case let atp as AddressToPointerInst :
181+ if !findStores( toTailAddress: atp, tailElementIndex: tailElementIndex, stores: & stores) {
182+ return false
183+ }
184+ case let mdi as MarkDependenceInst :
185+ if !findStores( toTailAddress: mdi, tailElementIndex: tailElementIndex, stores: & stores) {
186+ return false
187+ }
188+ case let pta as PointerToAddressInst :
189+ if !findStores( toTailAddress: pta, tailElementIndex: tailElementIndex, stores: & stores) {
190+ return false
191+ }
177192 case let store as StoreInst :
178193 if store. source. type. isTuple {
179194 // This kind of SIL is never generated because tuples are stored with separated stores to tuple_element_addr.
@@ -228,6 +243,17 @@ private func isValidUseOfObject(_ use: Operand) -> Bool {
228243 is EndCOWMutationInst :
229244 return true
230245
246+ case let mdi as MarkDependenceInst :
247+ if ( use == mdi. baseOperand) {
248+ return true ;
249+ }
250+ for mdiUse in mdi. uses {
251+ if !isValidUseOfObject( mdiUse) {
252+ return false
253+ }
254+ }
255+ return true
256+
231257 case is StructElementAddrInst ,
232258 is AddressToPointerInst ,
233259 is StructInst ,
@@ -239,9 +265,12 @@ private func isValidUseOfObject(_ use: Operand) -> Bool {
239265 is UpcastInst ,
240266 is BeginDeallocRefInst ,
241267 is RefTailAddrInst ,
242- is RefElementAddrInst :
243- for use in ( inst as! SingleValueInstruction ) . uses {
244- if !isValidUseOfObject( use) {
268+ is RefElementAddrInst ,
269+ is StructInst ,
270+ is PointerToAddressInst ,
271+ is IndexAddrInst :
272+ for instUse in ( inst as! SingleValueInstruction ) . uses {
273+ if !isValidUseOfObject( instUse) {
245274 return false
246275 }
247276 }
@@ -343,6 +372,8 @@ private func rewriteUses(of startValue: Value, _ context: FunctionPassContext) {
343372 context. erase ( instruction: endMutation)
344373 case let upCast as UpcastInst :
345374 worklist. pushIfNotVisited ( usersOf: upCast)
375+ case let urci as UncheckedRefCastInst :
376+ worklist. pushIfNotVisited ( usersOf: urci)
346377 case let moveValue as MoveValueInst :
347378 worklist. pushIfNotVisited ( usersOf: moveValue)
348379 case is DeallocRefInst , is DeallocStackRefInst :
0 commit comments