Skip to content

Commit bc6200e

Browse files
committed
SwiftCompilerSources: bridge '@'_addressable dependencies
1 parent 82240bd commit bc6200e

File tree

7 files changed

+39
-7
lines changed

7 files changed

+39
-7
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceInsertion.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,16 @@ extension LifetimeDependentApply {
130130
var info = LifetimeSourceInfo()
131131
let hasScopedYield = applySite.parameterOperands.contains {
132132
if let dep = applySite.resultDependence(on: $0) {
133-
return dep == .scope
133+
return dep.isScoped
134134
}
135135
return false
136136
}
137137
if hasScopedYield {
138-
// for consistency, we you yieldAddress if any yielded value is an address.
138+
// for consistency, we use yieldAddress if any yielded value is an address.
139139
let targetKind = beginApply.yieldedValues.contains(where: { $0.type.isAddress })
140140
? TargetKind.yieldAddress : TargetKind.yield
141-
info.sources.push(LifetimeSource(targetKind: targetKind, convention: .scope, value: beginApply.token))
141+
info.sources.push(LifetimeSource(targetKind: targetKind, convention: .scope(addressable: false),
142+
value: beginApply.token))
142143
}
143144
for operand in applySite.parameterOperands {
144145
guard let dep = applySite.resultDependence(on: operand) else {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceScopeFixup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private extension LifetimeDependence.Scope {
293293
var extensions = SingleInlineArray<ScopeExtension>()
294294
let applySite = yieldedValue.definingInstruction as! BeginApplyInst
295295
for operand in applySite.parameterOperands {
296-
guard let dep = applySite.resultDependence(on: operand), dep == .scope else {
296+
guard let dep = applySite.resultDependence(on: operand), dep.isScoped else {
297297
continue
298298
}
299299
// Pass a copy of innerScopes without modifying this one.

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ extension LifetimeDependenceDefUseWalker {
905905
return leafUse(of: operand)
906906
}
907907
if let dep = apply.resultDependence(on: operand),
908-
dep == .inherit {
908+
!dep.isScoped {
909909
// Operand is nonescapable and passed as a call argument. If the
910910
// result inherits its lifetime, then consider any nonescapable
911911
// result value to be a dependent use.

SwiftCompilerSources/Sources/SIL/FunctionConvention.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,25 @@ extension FunctionConvention {
237237

238238
public enum LifetimeDependenceConvention : CustomStringConvertible {
239239
case inherit
240-
case scope
240+
case scope(addressable: Bool)
241+
242+
public var isScoped: Bool {
243+
switch self {
244+
case .inherit:
245+
return false
246+
case .scope:
247+
return true
248+
}
249+
}
250+
251+
public var isAddressable: Bool {
252+
switch self {
253+
case .inherit:
254+
return false
255+
case let .scope(addressable):
256+
return addressable
257+
}
258+
}
241259

242260
public var description: String {
243261
switch self {
@@ -294,7 +312,8 @@ extension FunctionConvention {
294312
return .inherit
295313
}
296314
if scope {
297-
return .scope
315+
let addressable = bridged.checkAddressable(bridgedIndex(parameterIndex: index))
316+
return .scope(addressable: addressable)
298317
}
299318
return nil
300319
}

include/swift/AST/LifetimeDependence.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class LifetimeDependenceInfo {
300300
&& scopeLifetimeParamIndices->contains(index);
301301
}
302302

303+
bool checkAddressable(int index) const {
304+
return hasAddressableParamIndices()
305+
&& getAddressableIndices()->contains(index);
306+
}
307+
303308
std::string getString() const;
304309
void Profile(llvm::FoldingSetNodeID &ID) const;
305310
void getConcatenatedData(SmallVectorImpl<bool> &concatenatedData) const;

include/swift/SIL/SILBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct BridgedYieldInfoArray {
156156
struct BridgedLifetimeDependenceInfo {
157157
swift::IndexSubset *_Nullable inheritLifetimeParamIndices;
158158
swift::IndexSubset *_Nullable scopeLifetimeParamIndices;
159+
swift::IndexSubset *_Nullable addressableParamIndices;
159160
SwiftUInt targetIndex;
160161
bool immortal;
161162

@@ -164,6 +165,7 @@ struct BridgedLifetimeDependenceInfo {
164165
BRIDGED_INLINE bool empty() const;
165166
BRIDGED_INLINE bool checkInherit(SwiftInt index) const;
166167
BRIDGED_INLINE bool checkScope(SwiftInt index) const;
168+
BRIDGED_INLINE bool checkAddressable(SwiftInt index) const;
167169
BRIDGED_INLINE SwiftInt getTargetIndex() const;
168170

169171
BRIDGED_INLINE BridgedOwnedString getDebugDescription() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ BridgedParameterInfo BridgedParameterInfoArray::at(SwiftInt parameterIndex) cons
146146
BridgedLifetimeDependenceInfo::BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info)
147147
: inheritLifetimeParamIndices(info.getInheritIndices()),
148148
scopeLifetimeParamIndices(info.getScopeIndices()),
149+
addressableParamIndices(info.getAddressableIndices()),
149150
targetIndex(info.getTargetIndex()), immortal(info.isImmortal()) {}
150151

151152
SwiftInt BridgedLifetimeDependenceInfoArray::count() const {
@@ -172,6 +173,10 @@ bool BridgedLifetimeDependenceInfo::checkScope(SwiftInt index) const {
172173
scopeLifetimeParamIndices->contains(index);
173174
}
174175

176+
bool BridgedLifetimeDependenceInfo::checkAddressable(SwiftInt index) const {
177+
return addressableParamIndices && addressableParamIndices->contains(index);
178+
}
179+
175180
SwiftInt BridgedLifetimeDependenceInfo::getTargetIndex() const {
176181
return targetIndex;
177182
}

0 commit comments

Comments
 (0)