mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SwiftCompilerSources: add the InstructionRange.insert(borrowScopeOf:) utility
Adds the instruction range of a borrow-scope by transitively visiting all (potential) re-borrows.
This commit is contained in:
@@ -532,3 +532,25 @@ extension GlobalVariable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension InstructionRange {
|
||||
/// Adds the instruction range of a borrow-scope by transitively visiting all (potential) re-borrows.
|
||||
mutating func insert(borrowScopeOf borrow: BorrowIntroducingInstruction, _ context: some Context) {
|
||||
var worklist = ValueWorklist(context)
|
||||
defer { worklist.deinitialize() }
|
||||
|
||||
worklist.pushIfNotVisited(borrow)
|
||||
while let value = worklist.pop() {
|
||||
for use in value.uses {
|
||||
switch use.instruction {
|
||||
case let endBorrow as EndBorrowInst:
|
||||
self.insert(endBorrow)
|
||||
case let branch as BranchInst:
|
||||
worklist.pushIfNotVisited(branch.getArgument(for: use))
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user