File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
SwiftCompilerSources/Sources/Optimizer/Utilities Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -349,6 +349,16 @@ extension SingleValueInstruction {
349349 }
350350}
351351
352+ extension MultipleValueInstruction {
353+ /// Replaces all uses with the result of `replacement` and then erases the instruction.
354+ func replace( with replacement: MultipleValueInstruction , _ context: some MutatingContext ) {
355+ for (origResult, newResult) in zip ( self . results, replacement. results) {
356+ origResult. uses. replaceAll ( with: newResult, context)
357+ }
358+ context. erase ( instruction: self )
359+ }
360+ }
361+
352362extension Instruction {
353363 var isTriviallyDead : Bool {
354364 if results. contains ( where: { !$0. uses. isEmpty } ) {
@@ -1004,3 +1014,20 @@ extension StoreInst: CopyLikeInstruction {
10041014 private var load : LoadInst { source as! LoadInst }
10051015}
10061016
1017+ func eraseIfDead( functions: [ Function ] , _ context: ModulePassContext ) {
1018+ var toDelete = functions
1019+ while true {
1020+ var remaining = [ Function] ( )
1021+ for fn in toDelete {
1022+ if !fn. isPossiblyUsedExternally && !fn. isReferencedInModule {
1023+ context. erase ( function: fn)
1024+ } else {
1025+ remaining. append ( fn)
1026+ }
1027+ }
1028+ if remaining. count == toDelete. count {
1029+ return
1030+ }
1031+ toDelete = remaining
1032+ }
1033+ }
You can’t perform that action at this time.
0 commit comments