Skip to content

Commit 4cf63a9

Browse files
Merge pull request #73576 from nate-chandler/gardening/20240510/1
[Gardening] SIL: Spelling of live range.
2 parents c159715 + 7bfd711 commit 4cf63a9

19 files changed

+119
-119
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SIL
2020
/// One or more "potential" end instructions can be inserted.
2121
/// Though, not all inserted instructions end up as "end" instructions.
2222
///
23-
/// `InstructionRange` is useful for calculating the liferange of values.
23+
/// `InstructionRange` is useful for calculating the liverange of values.
2424
///
2525
/// The `InstructionRange` is similar to a `BasicBlockRange`, but defines the range
2626
/// in a "finer" granularity, i.e. on instructions instead of blocks.

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/AllocVectorLowering.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import SIL
1919
/// are initialized, a statically initialized global is created where the initializer is a
2020
/// `vector` instruction.
2121
///
22-
/// TODO: liferange computation is done very ad-hoc and should be eventually done by inspecting
22+
/// TODO: liverange computation is done very ad-hoc and should be eventually done by inspecting
2323
/// forwarding instructions.
2424
let allocVectorLowering = FunctionPass(name: "alloc-vector-lowering") {
2525
(function: Function, context: FunctionPassContext) in
@@ -190,7 +190,7 @@ private extension StructInst {
190190
/// Lowers the allocateVector builtin either to an stack-allocated vector (`alloc_vector`)
191191
/// or to a statically initialized global.
192192
private func lower(allocVectorBuiltin: BuiltinInst, _ context: FunctionPassContext) {
193-
let visitor = ComputeNonEscapingLiferange(of: allocVectorBuiltin, context)
193+
let visitor = ComputeNonEscapingLiverange(of: allocVectorBuiltin, context)
194194

195195
guard let result = allocVectorBuiltin.visit(using: visitor, context) else {
196196
if allocVectorBuiltin.parentFunction.isTransparent {
@@ -203,9 +203,9 @@ private func lower(allocVectorBuiltin: BuiltinInst, _ context: FunctionPassConte
203203
case .storeToGlobal(let storeInst):
204204
createOutlinedGlobal(for: allocVectorBuiltin, storeToGlobal: storeInst, context)
205205

206-
case .liferange(var liferange):
207-
defer { liferange.deinitialize() }
208-
createStackAllocatedVector(for: allocVectorBuiltin, liferange: liferange, context)
206+
case .liverange(var liverange):
207+
defer { liverange.deinitialize() }
208+
createStackAllocatedVector(for: allocVectorBuiltin, liverange: liverange, context)
209209

210210
case .invalid:
211211
context.diagnosticEngine.diagnose(allocVectorBuiltin.location.sourceLoc, .lifetime_value_outside_scope)
@@ -255,7 +255,7 @@ private func createOutlinedGlobal(
255255

256256
private func createStackAllocatedVector(
257257
for allocVectorBuiltin: BuiltinInst,
258-
liferange: InstructionRange,
258+
liverange: InstructionRange,
259259
_ context: FunctionPassContext
260260
) {
261261
let builder = Builder(before: allocVectorBuiltin, context)
@@ -267,7 +267,7 @@ private func createStackAllocatedVector(
267267
allocVectorBuiltin.uses.replaceAll(with: rawVectorPointer, context)
268268
context.erase(instruction: allocVectorBuiltin)
269269

270-
for endInst in liferange.ends {
270+
for endInst in liverange.ends {
271271
let builder = Builder(after: endInst, context)
272272
builder.createDeallocStack(allocVec)
273273
}
@@ -336,47 +336,47 @@ private func findInitStores(of address: Value, atIndex: Int, _ initStores: inout
336336

337337
// This is very experimental and not ideal at all.
338338
// TODO: replace this with DiagnoseLifetimeDependence from https://github.com/apple/swift/pull/68682
339-
private struct ComputeNonEscapingLiferange : EscapeVisitorWithResult {
339+
private struct ComputeNonEscapingLiverange : EscapeVisitorWithResult {
340340

341341
enum Result {
342-
case liferange(InstructionRange)
342+
case liverange(InstructionRange)
343343
case storeToGlobal(StoreInst)
344344
case invalid
345345
}
346346

347-
var liferange: InstructionRange
347+
var liverange: InstructionRange
348348
var storeToGlobal: StoreInst? = nil
349349
let domTree: DominatorTree
350350

351351
init(of instruction: Instruction, _ context: FunctionPassContext) {
352-
self.liferange = InstructionRange(begin: instruction, context)
352+
self.liverange = InstructionRange(begin: instruction, context)
353353
self.domTree = context.dominatorTree
354354
}
355355

356356
var result: Result {
357357
if let storeToGlobal = storeToGlobal {
358358
defer {
359-
var lr = liferange
359+
var lr = liverange
360360
lr.deinitialize()
361361
}
362-
precondition(liferange.inclusiveRangeContains(storeToGlobal))
363-
if liferange.inclusiveRangeContains(storeToGlobal.next!) ||
364-
liferange.ends.contains(where: { $0 != storeToGlobal }) ||
362+
precondition(liverange.inclusiveRangeContains(storeToGlobal))
363+
if liverange.inclusiveRangeContains(storeToGlobal.next!) ||
364+
liverange.ends.contains(where: { $0 != storeToGlobal }) ||
365365
!storeToGlobal.isInitializingGlobal
366366
{
367367
return .invalid
368368
}
369369
return .storeToGlobal(storeToGlobal)
370370
}
371-
return .liferange(liferange)
371+
return .liverange(liverange)
372372
}
373373

374374
mutating func cleanupOnAbort() {
375-
liferange.deinitialize()
375+
liverange.deinitialize()
376376
}
377377

378378
mutating func visitDef(def: Value, path: EscapePath) -> DefResult {
379-
if def.definingInstruction == liferange.begin {
379+
if def.definingInstruction == liverange.begin {
380380
return .walkDown
381381
}
382382
switch def {
@@ -392,12 +392,12 @@ private struct ComputeNonEscapingLiferange : EscapeVisitorWithResult {
392392

393393
mutating func visitUse(operand: Operand, path: EscapePath) -> UseResult {
394394
let user = operand.instruction
395-
let beginBlockOfRange = liferange.blockRange.begin
395+
let beginBlockOfRange = liverange.blockRange.begin
396396
let dominates = beginBlockOfRange.dominates(user.parentBlock, domTree)
397397
switch user {
398398
case let store as StoreInst:
399399
if dominates {
400-
liferange.insert(store)
400+
liverange.insert(store)
401401
}
402402
let accessPath = store.destination.accessPath
403403
if case .global = accessPath.base {
@@ -412,7 +412,7 @@ private struct ComputeNonEscapingLiferange : EscapeVisitorWithResult {
412412
return .continueWalk
413413
case let apply as ApplyInst:
414414
if dominates {
415-
liferange.insert(user)
415+
liverange.insert(user)
416416
}
417417
if !apply.isEscapable {
418418
return .abort
@@ -422,7 +422,7 @@ private struct ComputeNonEscapingLiferange : EscapeVisitorWithResult {
422422
return .continueWalk
423423
default:
424424
if dominates {
425-
liferange.insert(user)
425+
liverange.insert(user)
426426
}
427427
return .continueWalk
428428
}

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ private func gatherCallSites(in caller: Function, _ context: FunctionPassContext
192192

193193
private func updateCallSites(for rootClosure: SingleValueInstruction, in callSiteMap: inout CallSiteMap,
194194
convertedAndReabstractedClosures: inout InstructionSet, _ context: FunctionPassContext) {
195-
var rootClosurePossibleLifeRange = InstructionRange(begin: rootClosure, context)
195+
var rootClosurePossibleLiveRange = InstructionRange(begin: rootClosure, context)
196196
defer {
197-
rootClosurePossibleLifeRange.deinitialize()
197+
rootClosurePossibleLiveRange.deinitialize()
198198
}
199199

200200
var rootClosureApplies = OperandWorklist(context)
@@ -218,7 +218,7 @@ private func updateCallSites(for rootClosure: SingleValueInstruction, in callSit
218218

219219
let (foundUnexpectedUse, haveUsedReabstraction) =
220220
handleNonApplies(for: rootClosure, rootClosureApplies: &rootClosureApplies,
221-
rootClosurePossibleLifeRange: &rootClosurePossibleLifeRange, context);
221+
rootClosurePossibleLiveRange: &rootClosurePossibleLiveRange, context);
222222

223223

224224
if foundUnexpectedUse {
@@ -227,12 +227,12 @@ private func updateCallSites(for rootClosure: SingleValueInstruction, in callSit
227227

228228
let intermediateClosureArgDescriptorData =
229229
handleApplies(for: rootClosure, callSiteMap: &callSiteMap, rootClosureApplies: &rootClosureApplies,
230-
rootClosurePossibleLifeRange: &rootClosurePossibleLifeRange,
230+
rootClosurePossibleLiveRange: &rootClosurePossibleLiveRange,
231231
convertedAndReabstractedClosures: &convertedAndReabstractedClosures,
232232
haveUsedReabstraction: haveUsedReabstraction, context)
233233

234234
finalizeCallSites(for: rootClosure, in: &callSiteMap,
235-
rootClosurePossibleLifeRange: rootClosurePossibleLifeRange,
235+
rootClosurePossibleLiveRange: rootClosurePossibleLiveRange,
236236
intermediateClosureArgDescriptorData: intermediateClosureArgDescriptorData, context)
237237
}
238238

@@ -244,7 +244,7 @@ private func updateCallSites(for rootClosure: SingleValueInstruction, in callSit
244244
/// how to handle. If true, then `rootClosure` should not be specialized against.
245245
private func handleNonApplies(for rootClosure: SingleValueInstruction,
246246
rootClosureApplies: inout OperandWorklist,
247-
rootClosurePossibleLifeRange: inout InstructionRange,
247+
rootClosurePossibleLiveRange: inout InstructionRange,
248248
_ context: FunctionPassContext)
249249
-> (foundUnexpectedUse: Bool, haveUsedReabstraction: Bool)
250250
{
@@ -295,12 +295,12 @@ private func handleNonApplies(for rootClosure: SingleValueInstruction,
295295
case let cfi as ConvertFunctionInst:
296296
rootClosureConversionsAndReabstractions.pushIfNotVisited(contentsOf: cfi.uses)
297297
possibleMarkDependenceBases.insert(cfi)
298-
rootClosurePossibleLifeRange.insert(use.instruction)
298+
rootClosurePossibleLiveRange.insert(use.instruction)
299299

300300
case let cvt as ConvertEscapeToNoEscapeInst:
301301
rootClosureConversionsAndReabstractions.pushIfNotVisited(contentsOf: cvt.uses)
302302
possibleMarkDependenceBases.insert(cvt)
303-
rootClosurePossibleLifeRange.insert(use.instruction)
303+
rootClosurePossibleLiveRange.insert(use.instruction)
304304

305305
case let pai as PartialApplyInst:
306306
if !pai.isPullbackInResultOfAutodiffVJP,
@@ -311,7 +311,7 @@ private func handleNonApplies(for rootClosure: SingleValueInstruction,
311311
{
312312
rootClosureConversionsAndReabstractions.pushIfNotVisited(contentsOf: pai.uses)
313313
possibleMarkDependenceBases.insert(pai)
314-
rootClosurePossibleLifeRange.insert(use.instruction)
314+
rootClosurePossibleLiveRange.insert(use.instruction)
315315
haveUsedReabstraction = true
316316
} else {
317317
rootClosureApplies.pushIfNotVisited(use)
@@ -320,15 +320,15 @@ private func handleNonApplies(for rootClosure: SingleValueInstruction,
320320
case let mv as MoveValueInst:
321321
rootClosureConversionsAndReabstractions.pushIfNotVisited(contentsOf: mv.uses)
322322
possibleMarkDependenceBases.insert(mv)
323-
rootClosurePossibleLifeRange.insert(use.instruction)
323+
rootClosurePossibleLiveRange.insert(use.instruction)
324324

325325
// Uses of a copy of root-closure do not count as
326326
// uses of the root-closure
327327
case is CopyValueInst:
328-
rootClosurePossibleLifeRange.insert(use.instruction)
328+
rootClosurePossibleLiveRange.insert(use.instruction)
329329

330330
case is DestroyValueInst:
331-
rootClosurePossibleLifeRange.insert(use.instruction)
331+
rootClosurePossibleLiveRange.insert(use.instruction)
332332

333333
case let mdi as MarkDependenceInst:
334334
if possibleMarkDependenceBases.contains(mdi.base),
@@ -337,7 +337,7 @@ private func handleNonApplies(for rootClosure: SingleValueInstruction,
337337
mdi.value.type.isThickFunction
338338
{
339339
rootClosureConversionsAndReabstractions.pushIfNotVisited(contentsOf: mdi.uses)
340-
rootClosurePossibleLifeRange.insert(use.instruction)
340+
rootClosurePossibleLiveRange.insert(use.instruction)
341341
}
342342

343343
default:
@@ -354,14 +354,14 @@ private typealias IntermediateClosureArgDescriptorDatum = (applySite: SingleValu
354354

355355
private func handleApplies(for rootClosure: SingleValueInstruction, callSiteMap: inout CallSiteMap,
356356
rootClosureApplies: inout OperandWorklist,
357-
rootClosurePossibleLifeRange: inout InstructionRange,
357+
rootClosurePossibleLiveRange: inout InstructionRange,
358358
convertedAndReabstractedClosures: inout InstructionSet, haveUsedReabstraction: Bool,
359359
_ context: FunctionPassContext) -> [IntermediateClosureArgDescriptorDatum]
360360
{
361361
var intermediateClosureArgDescriptorData: [IntermediateClosureArgDescriptorDatum] = []
362362

363363
while let use = rootClosureApplies.pop() {
364-
rootClosurePossibleLifeRange.insert(use.instruction)
364+
rootClosurePossibleLiveRange.insert(use.instruction)
365365

366366
// TODO [extend to general swift]: Handle full apply sites
367367
guard let pai = use.instruction as? PartialApplyInst else {
@@ -479,11 +479,11 @@ private func handleApplies(for rootClosure: SingleValueInstruction, callSiteMap:
479479
/// Finalizes the call sites for a given root closure by adding a corresponding `ClosureArgDescriptor`
480480
/// to all call sites where the closure is ultimately passed as an argument.
481481
private func finalizeCallSites(for rootClosure: SingleValueInstruction, in callSiteMap: inout CallSiteMap,
482-
rootClosurePossibleLifeRange: InstructionRange,
482+
rootClosurePossibleLiveRange: InstructionRange,
483483
intermediateClosureArgDescriptorData: [IntermediateClosureArgDescriptorDatum],
484484
_ context: FunctionPassContext)
485485
{
486-
let closureInfo = ClosureInfo(closure: rootClosure, lifetimeFrontier: Array(rootClosurePossibleLifeRange.ends))
486+
let closureInfo = ClosureInfo(closure: rootClosure, lifetimeFrontier: Array(rootClosurePossibleLiveRange.ends))
487487

488488
for (applySite, closureArgumentIndex, parameterInfo) in intermediateClosureArgDescriptorData {
489489
guard var callSite = callSiteMap[applySite] else {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/RedundantLoadElimination.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,38 +161,38 @@ private extension LoadInst {
161161
_ context: FunctionPassContext
162162
) -> DataflowResult {
163163

164-
var liferange = Liferange(endBlock: self.parentBlock, context)
165-
defer { liferange.deinitialize() }
166-
liferange.pushPredecessors(of: self.parentBlock)
164+
var liverange = Liverange(endBlock: self.parentBlock, context)
165+
defer { liverange.deinitialize() }
166+
liverange.pushPredecessors(of: self.parentBlock)
167167

168-
while let block = liferange.pop() {
168+
while let block = liverange.pop() {
169169
switch scanner.scan(instructions: block.instructions.reversed(),
170170
in: block,
171171
complexityBudget: &complexityBudget)
172172
{
173173
case .overwritten:
174174
return DataflowResult(notRedundantWith: scanner.potentiallyRedundantSubpath)
175175
case .available:
176-
liferange.add(beginBlock: block)
176+
liverange.add(beginBlock: block)
177177
case .transparent:
178-
liferange.pushPredecessors(of: block)
178+
liverange.pushPredecessors(of: block)
179179
}
180180
}
181-
if !self.canReplaceWithoutInsertingCopies(liferange: liferange, context) {
181+
if !self.canReplaceWithoutInsertingCopies(liverange: liverange, context) {
182182
return DataflowResult(notRedundantWith: scanner.potentiallyRedundantSubpath)
183183
}
184184
return .redundant(scanner.availableValues)
185185
}
186186

187-
func canReplaceWithoutInsertingCopies(liferange: Liferange,_ context: FunctionPassContext) -> Bool {
187+
func canReplaceWithoutInsertingCopies(liverange: Liverange,_ context: FunctionPassContext) -> Bool {
188188
switch self.loadOwnership {
189189
case .trivial, .unqualified:
190190
return true
191191

192192
case .copy, .take:
193193
let deadEndBlocks = context.deadEndBlocks
194194

195-
// The liferange of the value has an "exit", i.e. a path which doesn't lead to the load,
195+
// The liverange of the value has an "exit", i.e. a path which doesn't lead to the load,
196196
// it means that we would have to insert a destroy on that exit to satisfy ownership rules.
197197
// But an inserted destroy also means that we would need to insert copies of the value which
198198
// were not there originally. For example:
@@ -201,9 +201,9 @@ private extension LoadInst {
201201
// cond_br bb1, bb2
202202
// bb1:
203203
// %2 = load [take] %addr
204-
// bb2: // liferange exit
204+
// bb2: // liverange exit
205205
//
206-
// TODO: we could extend OSSA to transfer ownership to support liferange exits without copying. E.g.:
206+
// TODO: we could extend OSSA to transfer ownership to support liverange exits without copying. E.g.:
207207
//
208208
// %b = store_and_borrow %1 to [init] %addr // %b is borrowed from %addr
209209
// cond_br bb1, bb2
@@ -213,18 +213,18 @@ private extension LoadInst {
213213
// bb2:
214214
// end_borrow %b
215215
//
216-
if liferange.hasExits(deadEndBlocks) {
216+
if liverange.hasExits(deadEndBlocks) {
217217
return false
218218
}
219219

220-
// Handle a corner case: if the load is in an infinite loop, the liferange doesn't have an exit,
220+
// Handle a corner case: if the load is in an infinite loop, the liverange doesn't have an exit,
221221
// but we still would need to insert a copy. For example:
222222
//
223223
// store %1 to [init] %addr
224224
// br bb1
225225
// bb1:
226226
// %2 = load [copy] %addr // would need to insert a copy here
227-
// br bb1 // no exit from the liferange
227+
// br bb1 // no exit from the liverange
228228
//
229229
// For simplicity, we don't handle this in OSSA.
230230
if deadEndBlocks.isDeadEnd(parentBlock) {
@@ -508,8 +508,8 @@ private struct InstructionScanner {
508508
break
509509
}
510510
if load.loadOwnership == .take {
511-
// In case of `take`, don't allow reading instructions in the liferange.
512-
// Otherwise we cannot shrink the memory liferange afterwards.
511+
// In case of `take`, don't allow reading instructions in the liverange.
512+
// Otherwise we cannot shrink the memory liverange afterwards.
513513
if instruction.mayReadOrWrite(address: load.address, aliasAnalysis) {
514514
return .overwritten
515515
}
@@ -522,9 +522,9 @@ private struct InstructionScanner {
522522
}
523523
}
524524

525-
/// Represents the liferange (in terms of basic blocks) of the loaded value.
525+
/// Represents the liverange (in terms of basic blocks) of the loaded value.
526526
///
527-
/// In contrast to a BlockRange, this liferange has multiple begin blocks (containing the
527+
/// In contrast to a BlockRange, this liverange has multiple begin blocks (containing the
528528
/// available values) and a single end block (containing the original load). For example:
529529
///
530530
/// bb1:
@@ -536,7 +536,7 @@ private struct InstructionScanner {
536536
/// bb3:
537537
/// %3 = load %addr // end block
538538
///
539-
private struct Liferange {
539+
private struct Liverange {
540540
private var worklist: BasicBlockWorklist
541541
private var containingBlocks: Stack<BasicBlock> // doesn't include the end-block
542542
private var beginBlocks: BasicBlockSet

0 commit comments

Comments
 (0)