SIL: make var OperandArray.values available for all kind of operand sequences

This commit is contained in:
Erik Eckstein
2025-10-05 16:14:19 +02:00
parent 876fd514b0
commit c3612bafb8
7 changed files with 12 additions and 12 deletions

View File

@@ -112,7 +112,7 @@ private func constantPropagateCaptures(of partialApply: PartialApplyInst, _ cont
// Escaping closures consume their arguments. Therefore we need to destroy the removed argument values.
addCompensatingDestroys(for: constArgs, context)
}
let newArguments = nonConstArgs.map { $0.value }
let newArguments = Array(nonConstArgs.values)
rewritePartialApply(partialApply, withSpecialized: specializedCallee, arguments: newArguments, context)
}

View File

@@ -404,7 +404,7 @@ private extension Value {
case is LoadInst:
return true
case is StructInst, is TupleInst:
worklist.pushIfNotVisited(contentsOf: (v as! Instruction).operands.lazy.map { $0.value })
worklist.pushIfNotVisited(contentsOf: (v as! Instruction).operands.values)
case let ei as EnumInst:
if let payload = ei.payload {
worklist.pushIfNotVisited(payload)

View File

@@ -27,9 +27,9 @@ private extension CondBranchInst {
}
let builder = Builder(before: self, context)
if conditionValue == 0 {
builder.createBranch(to: falseBlock, arguments: Array(falseOperands.map { $0.value }))
builder.createBranch(to: falseBlock, arguments: Array(falseOperands.values))
} else {
builder.createBranch(to: trueBlock, arguments: Array(trueOperands.map { $0.value }))
builder.createBranch(to: trueBlock, arguments: Array(trueOperands.values))
}
context.erase(instruction: self)
}

View File

@@ -71,7 +71,7 @@ extension Value {
}
switch v {
case let fw as ForwardingInstruction:
worklist.pushIfNotVisited(contentsOf: fw.definedOperands.lazy.map { $0.value })
worklist.pushIfNotVisited(contentsOf: fw.definedOperands.values)
case let bf as BorrowedFromInst:
worklist.pushIfNotVisited(bf.borrowedValue)
case let bb as BeginBorrowInst:
@@ -82,7 +82,7 @@ extension Value {
} else if let termResult = TerminatorResult(arg),
let fw = termResult.terminator as? ForwardingInstruction
{
worklist.pushIfNotVisited(contentsOf: fw.definedOperands.lazy.map { $0.value })
worklist.pushIfNotVisited(contentsOf: fw.definedOperands.values)
}
default:
continue

View File

@@ -170,7 +170,7 @@ public struct Phi {
}
public var incomingValues: LazyMapSequence<LazyMapSequence<PredecessorList, Operand>, Value> {
incomingOperands.lazy.map { $0.value }
incomingOperands.values
}
public var isReborrow: Bool { value.isReborrow }

View File

@@ -104,10 +104,6 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
base: OptionalBridgedOperand(op: base.advancedBy(bounds.lowerBound).op),
count: bounds.upperBound - bounds.lowerBound)
}
public var values: LazyMapSequence<LazySequence<OperandArray>.Elements, Value> {
self.lazy.map { $0.value }
}
}
public struct UseList : CollectionLikeSequence {
@@ -143,6 +139,10 @@ public struct UseList : CollectionLikeSequence {
}
extension Sequence where Element == Operand {
public var values: LazyMapSequence<Self, Value> {
self.lazy.map { $0.value }
}
public var singleUse: Operand? {
var result: Operand? = nil
for op in self {

View File

@@ -534,7 +534,7 @@ public final class EnclosingValueIterator : IteratorProtocol {
} else if let forwardingInst = value.forwardingInstruction {
// Recurse through guaranteed forwarding non-phi instructions.
let ops = forwardingInst.forwardedOperands
worklist.pushIfNotVisited(contentsOf: ops.lazy.map { $0.value })
worklist.pushIfNotVisited(contentsOf: ops.values)
} else if value.isGuaranteedApplyResult {
let selfArgument = (value as! ApplyInst).arguments.last!
worklist.pushIfNotVisited(selfArgument)