Skip to content

Commit 63cb683

Browse files
committed
SIL: improve some Location APIs
* rename `var autoGenerated` -> `var asAutoGenerated` * add `var asCleanup` * add `func withScope`
1 parent 4212c61 commit 63cb683

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceScopeFixup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ extension ExtendableScope {
842842
}
843843
defer { unusedEnds.deinitialize() }
844844
for end in range.ends {
845-
let location = end.location.autoGenerated
845+
let location = end.location.asAutoGenerated
846846
switch end {
847847
case is BranchInst:
848848
assert(end.parentBlock.singleSuccessor!.terminator is ReturnInst,
@@ -868,7 +868,7 @@ extension ExtendableScope {
868868
}
869869
}
870870
for exitInst in range.exits {
871-
let location = exitInst.location.autoGenerated
871+
let location = exitInst.location.asAutoGenerated
872872
let builder = Builder(before: exitInst, location: location, context)
873873
range.insert(createEndInstruction(builder, context))
874874
}

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private struct StackProtectionOptimization {
332332

333333
let function = argument.parentFunction
334334
let entryBlock = function.entryBlock
335-
let loc = entryBlock.instructions.first!.location.autoGenerated
335+
let loc = entryBlock.instructions.first!.location.asAutoGenerated
336336
let builder = Builder(atBeginOf: entryBlock, location: loc, context)
337337
let temporary = builder.createAllocStack(argument.type)
338338
argument.uses.replaceAll(with: temporary, context)
@@ -342,7 +342,7 @@ private struct StackProtectionOptimization {
342342
for block in function.blocks {
343343
let terminator = block.terminator
344344
if terminator.isFunctionExiting {
345-
let exitBuilder = Builder(before: terminator, location: terminator.location.autoGenerated, context)
345+
let exitBuilder = Builder(before: terminator, location: terminator.location.asAutoGenerated, context)
346346
exitBuilder.createCopyAddr(from: temporary, to: argument, takeSource: true, initializeDest: true)
347347
exitBuilder.createDeallocStack(temporary)
348348
}
@@ -362,13 +362,13 @@ private struct StackProtectionOptimization {
362362
return
363363
}
364364

365-
let builder = Builder(after: beginAccess, location: beginAccess.location.autoGenerated, context)
365+
let builder = Builder(after: beginAccess, location: beginAccess.location.asAutoGenerated, context)
366366
let temporary = builder.createAllocStack(beginAccess.type)
367367

368368
beginAccess.uses.ignoreUsers(ofType: EndAccessInst.self).replaceAll(with: temporary, context)
369369

370370
for endAccess in beginAccess.endInstructions {
371-
let endBuilder = Builder(before: endAccess, location: endAccess.location.autoGenerated, context)
371+
let endBuilder = Builder(before: endAccess, location: endAccess.location.asAutoGenerated, context)
372372
endBuilder.createCopyAddr(from: temporary, to: beginAccess, takeSource: true, initializeDest: true)
373373
endBuilder.createDeallocStack(temporary)
374374
}

SwiftCompilerSources/Sources/Optimizer/Utilities/FunctionSignatureTransforms.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private func createSpecializedFunction(
8888
hasSelfParameter: hasSelfParameter,
8989
fromOriginal: originalFunction)
9090

91-
let thunkLoc = originalFunction.entryBlock.instructions.first!.location.autoGenerated
91+
let thunkLoc = originalFunction.entryBlock.instructions.first!.location.asAutoGenerated
9292

9393
context.moveFunctionBody(from: originalFunction, to: specializedFunction)
9494
// originalFunction is now empty and used as the thunk.

SwiftCompilerSources/Sources/SIL/Location.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ public struct Location: ProvidingSourceLocation, Equatable, CustomStringConverti
5858
}
5959

6060
/// Keeps the debug scope but marks it as auto-generated.
61-
public var autoGenerated: Location {
61+
public var asAutoGenerated: Location {
6262
Location(bridged: bridged.getAutogeneratedLocation())
6363
}
6464

65+
public var asCleanup: Location {
66+
Location(bridged: bridged.getCleanupLocation())
67+
}
68+
69+
public func withScope(of other: Location) -> Location {
70+
Location(bridged: bridged.withScopeOf(other.bridged))
71+
}
72+
6573
public var hasValidLineNumber: Bool { bridged.hasValidLineNumber() }
6674
public var isAutoGenerated: Bool { bridged.isAutoGenerated() }
6775
public var isInlined: Bool { bridged.isInlined() }

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ struct BridgedLocation {
404404

405405
BridgedOwnedString getDebugDescription() const;
406406
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getAutogeneratedLocation() const;
407+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation getCleanupLocation() const;
408+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedLocation withScopeOf(BridgedLocation other) const;
407409
BRIDGED_INLINE bool hasValidLineNumber() const;
408410
BRIDGED_INLINE bool isAutoGenerated() const;
409411
BRIDGED_INLINE bool isInlined() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,12 @@ const swift::SILDebugLocation &BridgedLocation::getLoc() const {
621621
BridgedLocation BridgedLocation::getAutogeneratedLocation() const {
622622
return getLoc().getAutogeneratedLocation();
623623
}
624+
BridgedLocation BridgedLocation::getCleanupLocation() const {
625+
return getLoc().getCleanupLocation();
626+
}
627+
BridgedLocation BridgedLocation::withScopeOf(BridgedLocation other) const {
628+
return swift::SILDebugLocation(getLoc().getLocation(), other.getLoc().getScope());
629+
}
624630
bool BridgedLocation::hasValidLineNumber() const {
625631
return getLoc().hasValidLineNumber();
626632
}

include/swift/SIL/SILLocation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,11 @@ class SILDebugLocation {
776776
return autoGenLoc;
777777
}
778778

779+
SILDebugLocation getCleanupLocation() const {
780+
SILDebugLocation cleanupLoc(CleanupLocation(location), getScope());
781+
return cleanupLoc;
782+
}
783+
779784
bool isEqualTo(SILDebugLocation rhs) const {
780785
return getLocation() == rhs.getLocation() && getScope() == rhs.getScope();
781786
}

0 commit comments

Comments
 (0)