Skip to content

Commit 87e4c65

Browse files
committed
[Gardening] SIL: "liferange" -> "liverange"
1 parent 03ea6a1 commit 87e4c65

18 files changed

+85
-85
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: 20 additions & 20 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
@@ -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
}
@@ -339,44 +339,44 @@ private func findInitStores(of address: Value, atIndex: Int, _ initStores: inout
339339
private struct ComputeNonEscapingLiferange : 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/RedundantLoadElimination.swift

Lines changed: 18 additions & 18 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 = Liferange(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: Liferange,_ 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:

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
116116
// ... |
117117
// bb1: // allocation block _ |
118118
// %k = alloc_ref $Klass | | "outer"
119-
// %f = ref_element_addr %o, #Outer.f | "inner" | liferange
120-
// store %k to %f | liferange |
119+
// %f = ref_element_addr %o, #Outer.f | "inner" | liverange
120+
// store %k to %f | liverange |
121121
// ... | |
122122
// destroy_value %o _| _|
123123
//
124124
// * Finding the `outerDominatingBlock` is not guaranteed to work.
125125
// In this example, the top most dominator block is `bb0`, but `bb0` has no
126-
// use points in the outer liferange. We'll get `bb3` as outerDominatingBlock.
126+
// use points in the outer liverange. We'll get `bb3` as outerDominatingBlock.
127127
// This is no problem because 1. it's an unusual case and 2. the `outerBlockRange`
128128
// is invalid in this case and we'll bail later.
129129
//
@@ -144,12 +144,12 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
144144
let domTree = context.dominatorTree
145145
let outerDominatingBlock = getDominatingBlockOfAllUsePoints(context: context, allocRef, domTree: domTree)
146146

147-
// The "inner" liferange contains all use points which are dominated by the allocation block.
147+
// The "inner" liverange contains all use points which are dominated by the allocation block.
148148
// Note that this `visit` cannot fail because otherwise our initial `isEscaping` check would have failed already.
149149
var innerRange = allocRef.visit(using: ComputeInnerLiferange(of: allocRef, domTree, context), context)!
150150
defer { innerRange.deinitialize() }
151151

152-
// The "outer" liferange contains all use points.
152+
// The "outer" liverange contains all use points.
153153
// Same here: this `visit` cannot fail.
154154
var outerBlockRange = allocRef.visit(using: ComputeOuterBlockrange(dominatedBy: outerDominatingBlock, context), context)!
155155
defer { outerBlockRange.deinitialize() }
@@ -161,9 +161,9 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
161161
return false
162162
}
163163

164-
// Check if there is a control flow edge from the inner to the outer liferange, which
165-
// would mean that the promoted object can escape to the outer liferange.
166-
// This can e.g. be the case if the inner liferange does not post dominate the outer range:
164+
// Check if there is a control flow edge from the inner to the outer liverange, which
165+
// would mean that the promoted object can escape to the outer liverange.
166+
// This can e.g. be the case if the inner liverange does not post dominate the outer range:
167167
// _
168168
// %o = alloc_ref $Outer |
169169
// cond_br %c, bb1, bb2 |
@@ -191,7 +191,7 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
191191
return false
192192
}
193193

194-
// There shouldn't be any critical exit edges from the liferange, because that would mean
194+
// There shouldn't be any critical exit edges from the liverange, because that would mean
195195
// that the promoted allocation is leaking.
196196
// Just to be on the safe side, do a check and bail if we find critical exit edges: we
197197
// cannot insert instructions on critical edges.
@@ -200,7 +200,7 @@ private func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
200200
}
201201

202202
// Do the transformation!
203-
// Insert `dealloc_stack_ref` instructions at the exit- and end-points of the inner liferange.
203+
// Insert `dealloc_stack_ref` instructions at the exit- and end-points of the inner liverange.
204204
for exitInst in innerRange.exits {
205205
if !deadEndBlocks.isDeadEnd(exitInst.parentBlock) {
206206
let builder = Builder(before: exitInst, context)

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ extension Value {
240240

241241
useToDefRange.insert(destBlock)
242242

243-
// The value needs to be destroyed at every exit of the liferange.
243+
// The value needs to be destroyed at every exit of the liverange.
244244
for exitBlock in useToDefRange.exits {
245245
let builder = Builder(before: exitBlock.instructions.first!, context)
246246
builder.createDestroyValue(operand: self)

lib/SILOptimizer/IPO/CapturePropagation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ bool CapturePropagation::optimizePartialApply(PartialApplyInst *PAI) {
555555
// refers to the callee function.
556556
if (argConv != SILArgumentConvention::Direct_Guaranteed)
557557
return false;
558-
558+
559559
// For escaping closures:
560-
// To keep things simple, we don't do a liferange analysis to insert
560+
// To keep things simple, we don't do a liverange analysis to insert
561561
// compensating destroys of the keypath.
562562
// Instead we require that the PAI is the only use of the keypath (= the
563563
// common case). This allows us to just delete the now unused keypath

lib/SILOptimizer/Mandatory/DiagnoseLifetimeIssues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static bool isOutOfLifetime(SILInstruction *inst, SSAPrunedLiveness &liveness) {
316316
//
317317
// A more sophisticated analysis would be to check if there are no
318318
// (potential) loads from the store's destination address after the store,
319-
// but within the object's liferange. But without a good alias analysis (and
319+
// but within the object's liverange. But without a good alias analysis (and
320320
// we don't want to use AliasAnalysis in a mandatory pass) it's practically
321321
// impossible that a use of the object is not a potential load. So we would
322322
// always see a potential load if the lifetime of the object goes beyond the

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ bool SILCombiner::eraseApply(FullApplySite FAS, const UserListTy &Users) {
664664
return false;
665665
// As we are extending the lifetimes of owned parameters, we have to make
666666
// sure that no dealloc_ref or dealloc_stack_ref instructions are
667-
// within this extended liferange.
667+
// within this extended liverange.
668668
// It could be that the dealloc_ref is deallocating a parameter and then
669669
// we would have a release after the dealloc.
670670
if (VLA.containsDeallocRef(Frontier))

0 commit comments

Comments
 (0)