SwiftCompilerSources: move SIL-related Context APIs from Optimizer to the SIL module

This commit is contained in:
Erik Eckstein
2025-07-28 10:38:45 +02:00
parent 319f49ad9f
commit 41a6b8e257
20 changed files with 361 additions and 430 deletions

View File

@@ -27,6 +27,10 @@ public struct Operand : CustomStringConvertible, NoReflectionChildren, Equatable
public var value: Value { bridged.getValue().value }
public func set(to value: Value, _ context: some MutatingContext) {
instruction.setOperand(at: index, to: value, context)
}
public static func ==(lhs: Operand, rhs: Operand) -> Bool {
return lhs.bridged.op == rhs.bridged.op
}
@@ -45,6 +49,12 @@ public struct Operand : CustomStringConvertible, NoReflectionChildren, Equatable
public func canAccept(ownership: Ownership) -> Bool { bridged.canAcceptOwnership(ownership._bridged) }
public func changeOwnership(from: Ownership, to: Ownership, _ context: some MutatingContext) {
context.notifyInstructionsChanged()
bridged.changeOwnership(from._bridged, to._bridged)
context.notifyInstructionChanged(instruction)
}
public var description: String { "operand #\(index) of \(instruction)" }
}
@@ -185,6 +195,12 @@ extension Sequence where Element == Operand {
public func users<I: Instruction>(ofType: I.Type) -> LazyMapSequence<LazyFilterSequence<Self>, I> {
self.lazy.filter{ $0.instruction is I }.lazy.map { $0.instruction as! I }
}
public func replaceAll(with replacement: Value, _ context: some MutatingContext) {
for use in self {
use.set(to: replacement, context)
}
}
}
extension Value {