Skip to content

Commit 3bb3e4d

Browse files
committed
[NFC] Add ApplySite.parameterDependence(target:source:)
1 parent a4e3668 commit 3bb3e4d

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ private struct DiagnoseDependence {
184184
if inoutArg == sourceArg {
185185
return .continueWalk
186186
}
187-
if function.argumentConventions.getDependence(target: inoutArg.index, source: sourceArg.index) != nil {
187+
if function.argumentConventions.parameterDependence(targetArgumentIndex: inoutArg.index,
188+
sourceArgumentIndex: sourceArg.index) != nil {
188189
// The inout result depends on a lifetime that is inherited or borrowed in the caller.
189190
log(" has dependent inout argument: \(inoutArg)")
190191
return .continueWalk

SwiftCompilerSources/Sources/Optimizer/Utilities/FunctionSignatureTransforms.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private extension ArgumentConventions {
2626

2727
// Check if `argIndex` is a lifetime source in parameterDependencies
2828
for targetIndex in firstParameterIndex..<self.count {
29-
if getDependence(target: targetIndex, source: argIndex) != nil {
29+
if parameterDependence(targetArgumentIndex: targetIndex, sourceArgumentIndex: argIndex) != nil {
3030
return true
3131
}
3232
}

SwiftCompilerSources/Sources/SIL/ApplySite.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ public struct ApplyOperandConventions : Collection {
7979
calleeArgumentIndex(ofOperandIndex: operandIndex)!]
8080
}
8181

82+
public func parameterDependence(targetOperandIndex: Int, sourceOperandIndex: Int) -> LifetimeDependenceConvention? {
83+
guard let targetArgIdx = calleeArgumentIndex(ofOperandIndex: targetOperandIndex),
84+
let sourceArgIdx = calleeArgumentIndex(ofOperandIndex: sourceOperandIndex) else {
85+
return nil
86+
}
87+
return calleeArgumentConventions.parameterDependence(targetArgumentIndex: targetArgIdx,
88+
sourceArgumentIndex: sourceArgIdx)
89+
}
90+
8291
public var firstParameterOperandIndex: Int {
8392
return ApplyOperandConventions.firstArgumentIndex +
8493
calleeArgumentConventions.firstParameterIndex
@@ -247,6 +256,10 @@ extension ApplySite {
247256
: operandConventions[parameterDependencies: idx]
248257
}
249258

259+
public func parameterDependence(target: Operand, source: Operand) -> LifetimeDependenceConvention? {
260+
return operandConventions.parameterDependence(targetOperandIndex: target.index, sourceOperandIndex: source.index)
261+
}
262+
250263
public var yieldConventions: YieldConventions {
251264
YieldConventions(convention: functionConvention)
252265
}

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,16 @@ public struct ArgumentConventions : Collection, CustomStringConvertible {
318318
return convention.parameterDependencies(for: targetParamIdx)
319319
}
320320

321+
/// Return a parameter dependence of the target argument on the source argument.
322+
public func parameterDependence(targetArgumentIndex: Int, sourceArgumentIndex: Int) -> LifetimeDependenceConvention? {
323+
findDependence(source: sourceArgumentIndex, in: self[parameterDependencies: targetArgumentIndex])
324+
}
325+
321326
/// Return a dependence of the function results on the indexed parameter.
322327
public subscript(resultDependsOn argumentIndex: Int) -> LifetimeDependenceConvention? {
323328
findDependence(source: argumentIndex, in: convention.resultDependencies)
324329
}
325330

326-
/// Return a dependence of the target argument on the source argument.
327-
public func getDependence(target targetArgumentIndex: Int, source sourceArgumentIndex: Int)
328-
-> LifetimeDependenceConvention? {
329-
findDependence(source: sourceArgumentIndex, in: self[parameterDependencies: targetArgumentIndex])
330-
}
331-
332331
/// Number of SIL arguments for the function type's results
333332
/// including the error result. Use this to avoid lazy iteration
334333
/// over indirectSILResults to find the count.

0 commit comments

Comments
 (0)