Skip to content

Commit 6c35258

Browse files
committed
Swift SIL: rename parent accessors to parentX, e.g. Instruction.parentBlock
It makes it easier to read
1 parent 0812484 commit 6c35258

22 files changed

+77
-77
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/BasicBlockRange.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct BasicBlockRange : CustomStringConvertible, NoReflectionChildren {
110110

111111
/// Returns true if the range is valid and that's iff the begin block dominates all blocks of the range.
112112
var isValid: Bool {
113-
let entry = begin.function.entryBlock
113+
let entry = begin.parentFunction.entryBlock
114114
return begin == entry ||
115115
// If any block in the range is not dominated by `begin`, the range propagates back to the entry block.
116116
!inclusiveRangeContains(entry)

SwiftCompilerSources/Sources/Optimizer/DataStructures/FunctionUses.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct FunctionUses {
9393
result += "<unknown uses>\n"
9494
}
9595
for inst in self {
96-
result += "@\(inst.function.name): \(inst)\n"
96+
result += "@\(inst.parentFunction.name): \(inst)\n"
9797

9898
}
9999
result += "]"

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
5050

5151
init(begin beginInst: Instruction, _ context: PassContext) {
5252
self.begin = beginInst
53-
self.blockRange = BasicBlockRange(begin: beginInst.block, context)
53+
self.blockRange = BasicBlockRange(begin: beginInst.parentBlock, context)
5454
self.insertedInsts = InstructionSet(context)
5555
}
5656

5757
/// Insert a potential end instruction.
5858
mutating func insert(_ inst: Instruction) {
5959
insertedInsts.insert(inst)
60-
blockRange.insert(inst.block)
60+
blockRange.insert(inst.parentBlock)
6161
}
6262

6363
/// Insert a sequence of potential end instructions.
@@ -69,7 +69,7 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
6969

7070
/// Returns true if the exclusive range contains `inst`.
7171
func contains(_ inst: Instruction) -> Bool {
72-
let block = inst.block
72+
let block = inst.parentBlock
7373
if !blockRange.inclusiveRangeContains(block) { return false }
7474
var inRange = false
7575
if blockRange.contains(block) {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeEscapeEffects.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
144144
}
145145

146146
// If the function never returns, the argument can not escape to another arg/return.
147-
guard let returnInst = arg.function.returnInstruction else {
147+
guard let returnInst = arg.parentFunction.returnInstruction else {
148148
return false
149149
}
150150

@@ -189,7 +189,7 @@ private func isOperandOfRecursiveCall(_ op: Operand) -> Bool {
189189
let inst = op.instruction
190190
if let applySite = inst as? FullApplySite,
191191
let callee = applySite.referencedFunction,
192-
callee == inst.function,
192+
callee == inst.parentFunction,
193193
let argIdx = applySite.argumentIndex(of: op),
194194
op.value == callee.arguments[argIdx] {
195195
return true
@@ -256,7 +256,7 @@ func isExclusiveEscapeToArgument(fromArgument: Argument, fromPath: SmallProjecti
256256
}
257257
let visitor = IsExclusiveArgumentEscapeVisitor(fromArgument: fromArgument, fromPath: fromPath,
258258
toArgumentIndex: toArgumentIndex, toPath: toPath)
259-
let toArg = fromArgument.function.arguments[toArgumentIndex]
259+
let toArg = fromArgument.parentFunction.arguments[toArgumentIndex]
260260
return !toArg.at(toPath).isEscapingWhenWalkingDown(using: visitor, context)
261261
}
262262

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private struct ArgumentEscapingWalker : ValueDefUseWalker, AddressDefUseWalker {
417417

418418
mutating func leafUse(address: Operand, path: UnusedWalkingPath) -> WalkResult {
419419
let inst = address.instruction
420-
let function = inst.function
420+
let function = inst.parentFunction
421421
switch inst {
422422
case let copy as CopyAddrInst:
423423
if address == copy.sourceOperand &&

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ObjCBridgingOptimization.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ private func optimizeNonOptionalBridging(_ apply: ApplyInst,
144144

145145
let originalObjCValue = originalObjCValueSwitch.enumOp
146146
let optionalReplacement = originalObjCValue.copy(at: originalObjCValueSwitch,
147-
andMakeAvailableIn: bridgeToObjcCall.block, context)
147+
andMakeAvailableIn: bridgeToObjcCall.parentBlock,
148+
context)
148149
let builder = Builder(at: bridgeToObjcCall, context)
149150

150151
// We know that it's the some-case.
@@ -183,7 +184,7 @@ private func optimizeNonOptionalBridging(_ apply: ApplyInst,
183184
// Creates a `switch_enum` on `originalObjCValue` and in the nil-case return a bridged
184185
// empty value.
185186
// Create the needed blocks of the `switch_enum` CFG diamond.
186-
let origBlock = bridgeToSwiftCall.block
187+
let origBlock = bridgeToSwiftCall.parentBlock
187188
let someBlock = context.splitBlock(at: bridgeToSwiftCall)
188189
let noneBlock = context.splitBlock(at: bridgeToSwiftCall)
189190
let continueBlock = context.splitBlock(at: bridgeToSwiftCall)
@@ -217,7 +218,7 @@ private func optimizeNonOptionalBridging(_ apply: ApplyInst,
217218
let s = continueBlock.addBlockArgument(type: objCType, ownership: .owned, context)
218219

219220
// Now replace the bridged value with the original value in the destination block.
220-
let replacement = s.makeAvailable(in: bridgeToObjcCall.block, context)
221+
let replacement = s.makeAvailable(in: bridgeToObjcCall.parentBlock, context)
221222
bridgeToObjcCall.uses.replaceAll(with: replacement, context)
222223
context.erase(instruction: bridgeToObjcCall)
223224
return true
@@ -315,9 +316,9 @@ private func isOptionalBridging(of value: Value, isBridging: (Value) -> ApplyIns
315316
} else {
316317
// The none-case
317318
if noneSwitch != nil { return nil }
318-
guard let singlePred = enumInst.block.singlePredecessor,
319+
guard let singlePred = enumInst.parentBlock.singlePredecessor,
319320
let se = singlePred.terminator as? SwitchEnumInst,
320-
se.getUniqueSuccessor(forCaseIndex: enumInst.caseIndex) === enumInst.block else {
321+
se.getUniqueSuccessor(forCaseIndex: enumInst.caseIndex) === enumInst.parentBlock else {
321322
return nil
322323
}
323324
noneSwitch = se
@@ -335,9 +336,9 @@ private func isOptionalBridging(of value: Value, isBridging: (Value) -> ApplyIns
335336
/// the payload block argument of the `switch_enum`.
336337
private func isPayloadOfSwitchEnum(_ value: Value) -> (SwitchEnumInst, case: Int)? {
337338
if let payloadArg = value as? BlockArgument,
338-
let pred = payloadArg.block.singlePredecessor,
339+
let pred = payloadArg.parentBlock.singlePredecessor,
339340
let se = pred.terminator as? SwitchEnumInst,
340-
let caseIdx = se.getUniqueCase(forSuccessor: payloadArg.block) {
341+
let caseIdx = se.getUniqueCase(forSuccessor: payloadArg.parentBlock) {
341342
return (se, caseIdx)
342343
}
343344
return nil

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let stackPromotion = FunctionPass(name: "stack-promotion", {
4646
var changed = false
4747
for inst in function.instructions {
4848
if let ar = inst as? AllocRefInstBase {
49-
if deadEndBlocks.isDeadEnd(ar.block) {
49+
if deadEndBlocks.isDeadEnd(ar.parentBlock) {
5050
// Don't stack promote any allocation inside a code region which ends up
5151
// in a no-return block. Such allocations may missing their final release.
5252
// We would insert the deallocation too early, which may result in a
@@ -170,7 +170,7 @@ func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
170170
// Do the transformation!
171171
// Insert `dealloc_stack_ref` instructions at the exit- and end-points of the inner liferange.
172172
for exitInst in innerRange.exits {
173-
if !deadEndBlocks.isDeadEnd(exitInst.block) {
173+
if !deadEndBlocks.isDeadEnd(exitInst.parentBlock) {
174174
let builder = Builder(at: exitInst, context)
175175
builder.createDeallocStackRef(allocRef)
176176
}
@@ -197,15 +197,15 @@ private func getDominatingBlockOfAllUsePoints(context: PassContext,
197197
var result: BasicBlock
198198
let domTree: DominatorTree
199199
mutating func visitUse(operand: Operand, path: EscapePath) -> UseResult {
200-
let defBlock = operand.value.definingBlock
200+
let defBlock = operand.value.parentBlock
201201
if defBlock.dominates(result, domTree) {
202202
result = defBlock
203203
}
204204
return .continueWalk
205205
}
206206
}
207207

208-
return value.visit(using: FindDominatingBlock(result: value.block, domTree: domTree), context)!
208+
return value.visit(using: FindDominatingBlock(result: value.parentBlock, domTree: domTree), context)!
209209
}
210210

211211

@@ -229,13 +229,13 @@ func computeInnerAndOuterLiferanges(instruction: SingleValueInstruction, in domB
229229

230230
mutating func visitUse(operand: Operand, path: EscapePath) -> UseResult {
231231
let user = operand.instruction
232-
if innerRange.blockRange.begin.dominates(user.block, domTree) {
232+
if innerRange.blockRange.begin.dominates(user.parentBlock, domTree) {
233233
innerRange.insert(user)
234234
}
235-
outerBlockRange.insert(user.block)
235+
outerBlockRange.insert(user.parentBlock)
236236

237237
let val = operand.value
238-
let defBlock = val.definingBlock
238+
let defBlock = val.parentBlock
239239

240240
// Also insert the operand's definition. Otherwise we would miss allocation
241241
// instructions (for which the `visitUse` closure is not called).

SwiftCompilerSources/Sources/Optimizer/InstructionPasses/SimplifyStrongRetainRelease.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ private func isNotReferenceCounted(value: Value, context: PassContext) -> Bool {
8383
// Note that the `simplifyGlobalValuePass` pass is deleting balanced
8484
// retains/releases, which doesn't require a Swift 5.1 minimum deployment
8585
// target.
86-
return gvi.function.isSwift51RuntimeAvailable
86+
return gvi.parentFunction.isSwift51RuntimeAvailable
8787
case let rptr as RawPointerToRefInst:
8888
// Like `global_value` but for the empty collection singletons from the
8989
// stdlib, e.g. the empty Array singleton.
90-
if rptr.function.isSwift51RuntimeAvailable {
90+
if rptr.parentFunction.isSwift51RuntimeAvailable {
9191
// The pattern generated for empty collection singletons is:
9292
// %0 = global_addr @_swiftEmptyArrayStorage
9393
// %1 = address_to_pointer %0

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private struct StackProtectionOptimization {
244244
}
245245

246246
while let arg = worklist.pop() {
247-
let f = arg.function
247+
let f = arg.parentFunction
248248
let uses = functionUses.getUses(of: f)
249249
if uses.hasUnknownUses && enableMoveInout {
250250
return NeedInsertMoves.yes
@@ -271,9 +271,9 @@ private struct StackProtectionOptimization {
271271
// It's an indirect argument.
272272
switch callerArg.accessBase.isStackAllocated {
273273
case .yes:
274-
if !callerArg.function.needsStackProtection {
275-
log("alloc_stack in caller: \(callerArg.function.name) -- \(callerArg)")
276-
newFunctions.push(callerArg.function)
274+
if !callerArg.parentFunction.needsStackProtection {
275+
log("alloc_stack in caller: \(callerArg.parentFunction.name) -- \(callerArg)")
276+
newFunctions.push(callerArg.parentFunction)
277277
}
278278
case .no:
279279
break
@@ -291,10 +291,10 @@ private struct StackProtectionOptimization {
291291
if foundUnknownRoots && enableMoveInout {
292292
return NeedInsertMoves.yes
293293
}
294-
if foundStackAlloc && !obj.function.needsStackProtection {
294+
if foundStackAlloc && !obj.parentFunction.needsStackProtection {
295295
// The object is created by an `alloc_ref [stack]`.
296-
log("object in caller: \(obj.function.name) -- \(obj)")
297-
newFunctions.push(obj.function)
296+
log("object in caller: \(obj.parentFunction.name) -- \(obj)")
297+
newFunctions.push(obj.parentFunction)
298298
}
299299
case .unknown:
300300
if enableMoveInout {
@@ -308,10 +308,10 @@ private struct StackProtectionOptimization {
308308
if foundUnknownRoots && enableMoveInout {
309309
return NeedInsertMoves.yes
310310
}
311-
if foundStackAlloc && !callerArg.function.needsStackProtection {
311+
if foundStackAlloc && !callerArg.parentFunction.needsStackProtection {
312312
// The object is created by an `alloc_ref [stack]`.
313-
log("object arg in caller: \(callerArg.function.name) -- \(callerArg)")
314-
newFunctions.push(callerArg.function)
313+
log("object arg in caller: \(callerArg.parentFunction.name) -- \(callerArg)")
314+
newFunctions.push(callerArg.parentFunction)
315315
}
316316
}
317317
}
@@ -330,7 +330,7 @@ private struct StackProtectionOptimization {
330330
return
331331
}
332332

333-
let function = argument.function
333+
let function = argument.parentFunction
334334
let entryBlock = function.entryBlock
335335
let loc = entryBlock.instructions.first!.location.autoGenerated
336336
let builder = Builder(atBeginOf: entryBlock, location: loc, context)
@@ -376,9 +376,9 @@ private struct StackProtectionOptimization {
376376
}
377377

378378
builder.createCopyAddr(from: beginAccess, to: temporary, takeSource: true, initializeDest: true)
379-
log("move object protection in \(beginAccess.function.name): \(beginAccess)")
379+
log("move object protection in \(beginAccess.parentFunction.name): \(beginAccess)")
380380

381-
beginAccess.function.setNeedsStackProtection(context)
381+
beginAccess.parentFunction.setNeedsStackProtection(context)
382382

383383
// Access scopes are not necessarily properly nested, which can result in
384384
// not properly nested stack allocations.

SwiftCompilerSources/Sources/Optimizer/PassManager/PassContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ extension Builder {
164164
if let nextInst = insPnt.next {
165165
self.init(insertAt: .before(nextInst), location: location, passContext: context._bridged)
166166
} else {
167-
self.init(insertAt: .atEndOf(insPnt.block), location: location, passContext: context._bridged)
167+
self.init(insertAt: .atEndOf(insPnt.parentBlock), location: location, passContext: context._bridged)
168168
}
169169
}
170170

SwiftCompilerSources/Sources/Optimizer/TestPasses/AccessDumper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ private func checkAliasInfo(forArgumentsOf apply: ApplyInst, expectDistinct: Boo
9191
}
9292

9393
print("in function")
94-
print(apply.function)
94+
print(apply.parentFunction)
9595
fatalError()
9696
}

SwiftCompilerSources/Sources/Optimizer/TestPasses/RangeDumper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private func verify(_ blockRange: BasicBlockRange, _ context: PassContext) {
8888
inInclusiveRange.insert(b)
8989
}
9090

91-
for b in blockRange.begin.function.blocks {
91+
for b in blockRange.begin.parentFunction.blocks {
9292
assert(blockRange.contains(b) == inRange.contains(b))
9393
assert(blockRange.inclusiveRangeContains(b) == inInclusiveRange.contains(b))
9494
}

SwiftCompilerSources/Sources/Optimizer/TestPasses/TestInstructionIteration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ private func handle(instruction: Instruction, _ context: PassContext) {
5555
if let sl = instruction as? StringLiteralInst {
5656
switch sl.string {
5757
case "delete_strings":
58-
deleteAllInstructions(ofType: StringLiteralInst.self, in: instruction.block, context)
58+
deleteAllInstructions(ofType: StringLiteralInst.self, in: instruction.parentBlock, context)
5959
case "delete_ints":
60-
deleteAllInstructions(ofType: IntegerLiteralInst.self, in: instruction.block, context)
60+
deleteAllInstructions(ofType: IntegerLiteralInst.self, in: instruction.parentBlock, context)
6161
case "delete_branches":
62-
deleteAllInstructions(ofType: BranchInst.self, in: instruction.block, context)
62+
deleteAllInstructions(ofType: BranchInst.self, in: instruction.parentBlock, context)
6363
case "split_block":
6464
_ = context.splitBlock(at: instruction)
6565
default:

SwiftCompilerSources/Sources/Optimizer/Utilities/AccessUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enum AccessBase : CustomStringConvertible, Hashable {
8686
case let arg as FunctionArgument : self = .argument(arg)
8787
case let ga as GlobalAddrInst : self = .global(ga.global)
8888
case let mvr as MultipleValueInstructionResult:
89-
if let ba = mvr.instruction as? BeginApplyInst, baseAddress.type.isAddress {
89+
if let ba = mvr.parentInstruction as? BeginApplyInst, baseAddress.type.isAddress {
9090
self = .yield(ba)
9191
} else {
9292
self = .unidentified

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
734734
case is AllocBoxInst:
735735
return cachedWalkDown(addressOrValue: def, path: path.with(knownType: nil))
736736
case let arg as BlockArgument:
737-
let block = arg.block
737+
let block = arg.parentBlock
738738
switch block.singlePredecessor!.terminator {
739739
case let ta as TryApplyInst:
740740
if block != ta.normalBlock { return isEscaping }

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension Builder {
2222
static func insert(after inst: Instruction, location: Location,
2323
_ context: PassContext, insertFunc: (Builder) -> ()) {
2424
if inst is TermInst {
25-
for succ in inst.block.successors {
25+
for succ in inst.parentBlock.successors {
2626
assert(succ.hasSinglePredecessor,
2727
"the terminator instruction must not have critical successors")
2828
let builder = Builder(at: succ.instructions.first!, location: location,
@@ -47,7 +47,7 @@ extension Value {
4747
assert(uses.isEmpty)
4848
assert(ownership == .owned)
4949

50-
let beginBlock = definingBlock
50+
let beginBlock = parentBlock
5151
var useToDefRange = BasicBlockRange(begin: beginBlock, context)
5252
defer { useToDefRange.deinitialize() }
5353

SwiftCompilerSources/Sources/Optimizer/Utilities/WalkUtils.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ extension ValueDefUseWalker {
374374
let payload = succBlock.arguments.first {
375375
return walkDownUses(ofValue: payload, path: path)
376376
} else if path.popIfMatches(.anyValueFields, index: nil) != nil {
377-
for succBlock in se.block.successors {
377+
for succBlock in se.parentBlock.successors {
378378
if let payload = succBlock.arguments.first,
379379
walkDownUses(ofValue: payload, path: path) == .abortWalk {
380380
return .abortWalk
@@ -597,7 +597,7 @@ extension ValueUseDefWalker {
597597
case let ued as UncheckedEnumDataInst:
598598
return walkUp(value: ued.operand, path: path.push(.enumCase, index: ued.caseIndex))
599599
case let mvr as MultipleValueInstructionResult:
600-
let instruction = mvr.instruction
600+
let instruction = mvr.parentInstruction
601601
if let ds = instruction as? DestructureStructInst {
602602
return walkUp(value: ds.operand, path: path.push(.structField, index: mvr.index))
603603
} else if let dt = instruction as? DestructureTupleInst {
@@ -625,7 +625,7 @@ extension ValueUseDefWalker {
625625
return .continueWalk
626626
}
627627

628-
let block = arg.block
628+
let block = arg.parentBlock
629629
if let pred = block.singlePredecessor,
630630
let se = pred.terminator as? SwitchEnumInst,
631631
let caseIdx = se.getUniqueCase(forSuccessor: block) {

0 commit comments

Comments
 (0)