Skip to content

Commit 35d62a4

Browse files
committed
Introduce end_cow_mutation_addr instruction
1 parent ceb3264 commit 35d62a4

26 files changed

+97
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/TestPasses/MemBehaviorDumper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private extension Instruction {
6363
is BeginAccessInst,
6464
is EndAccessInst,
6565
is EndCOWMutationInst,
66+
is EndCOWMutationAddrInst,
6667
is CopyValueInst,
6768
is DestroyValueInst,
6869
is StrongReleaseInst,

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ extension AddressUseVisitor {
131131
is DestroyAddrInst, is DeallocStackInst,
132132
is DeinitExistentialAddrInst,
133133
is IsUniqueInst, is MarkFunctionEscapeInst,
134-
is PackElementSetInst:
134+
is PackElementSetInst, is EndCOWMutationAddrInst:
135135
return leafAddressUse(of: operand)
136136

137137
case is LoadInst, is LoadUnownedInst, is LoadWeakInst, is ValueMetatypeInst, is ExistentialMetatypeInst,

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ public struct Builder {
575575
return notifyNew(endMutation.getAs(EndCOWMutationInst.self))
576576
}
577577

578+
public func createEndCOWMutationAddr(address: Value) -> EndCOWMutationAddrInst {
579+
let endMutation = bridged.createEndCOWMutationAddr(address.bridged)
580+
return notifyNew(endMutation.getAs(EndCOWMutationAddrInst.self))
581+
}
582+
578583
public func createMarkDependence(value: Value, base: Value, kind: MarkDependenceKind) -> MarkDependenceInst {
579584
let markDependence = bridged.createMarkDependence(value.bridged, base.bridged,
580585
BridgedInstruction.MarkDependenceKind(rawValue: kind.rawValue)!)

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,10 @@ final public class EndCOWMutationInst : SingleValueInstruction, UnaryInstruction
12261226
public var doKeepUnique: Bool { bridged.EndCOWMutationInst_doKeepUnique() }
12271227
}
12281228

1229+
final public class EndCOWMutationAddrInst : Instruction, UnaryInstruction {
1230+
public var address: Value { operand.value }
1231+
}
1232+
12291233
final public
12301234
class ClassifyBridgeObjectInst : SingleValueInstruction, UnaryInstruction {}
12311235

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public func registerSILClasses() {
215215
register(MoveValueInst.self)
216216
register(DropDeinitInst.self)
217217
register(EndCOWMutationInst.self)
218+
register(EndCOWMutationAddrInst.self)
218219
register(ClassifyBridgeObjectInst.self)
219220
register(PartialApplyInst.self)
220221
register(ApplyInst.self)

docs/SIL/Instructions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,22 @@ not replace this reference with a not uniquely reference object.
21462146

21472147
For details see [Copy-on-Write Representation](SIL.md#Copy-on-Write-Representation).
21482148

2149+
### end_cow_mutation_addr
2150+
2151+
```
2152+
sil-instruction ::= 'end_cow_mutation_addr' sil-operand
2153+
2154+
end_cow_mutation_addr %0 : $*T
2155+
// %0 must be of an address $*T type
2156+
```
2157+
2158+
This instruction marks the end of mutation of an address. The address could be
2159+
an opaque archetype, a struct, tuple or enum type and the end_cow_mutation_addr
2160+
will apply to all members contained within it.
2161+
It is currently only generated in cases where we maybe deriving a MutableSpan from
2162+
`%0` since it is not possible to schedule an `end_cow_mutation` in the standard
2163+
library automatically for Array.mutableSpan etc.
2164+
21492165
### destroy_not_escaped_closure
21502166

21512167
```

include/swift/SIL/AddressWalker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ TransitiveAddressWalker<Impl>::walk(SILValue projectedAddress) {
229229
isa<PackElementSetInst>(user) || isa<PackElementGetInst>(user) ||
230230
isa<DeinitExistentialAddrInst>(user) || isa<LoadBorrowInst>(user) ||
231231
isa<TupleAddrConstructorInst>(user) || isa<DeallocPackInst>(user) ||
232-
isa<MergeIsolationRegionInst>(user)) {
232+
isa<MergeIsolationRegionInst>(user) || isa<EndCOWMutationAddrInst>(user)) {
233233
callVisitUse(op);
234234
continue;
235235
}

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,7 @@ struct BridgedBuilder{
12801280
BridgedASTType::MetatypeRepresentation representation) const;
12811281
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEndCOWMutation(BridgedValue instance,
12821282
bool keepUnique) const;
1283+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createEndCOWMutationAddr(BridgedValue instance) const;
12831284
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createMarkDependence(
12841285
BridgedValue value, BridgedValue base, BridgedInstruction::MarkDependenceKind dependenceKind) const;
12851286

include/swift/SIL/SILBridgingImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,6 +2498,12 @@ BridgedInstruction BridgedBuilder::createEndCOWMutation(BridgedValue instance, b
24982498
keepUnique)};
24992499
}
25002500

2501+
BridgedInstruction
2502+
BridgedBuilder::createEndCOWMutationAddr(BridgedValue instance) const {
2503+
return {unbridged().createEndCOWMutationAddr(regularLoc(),
2504+
instance.getSILValue())};
2505+
}
2506+
25012507
BridgedInstruction BridgedBuilder::createMarkDependence(BridgedValue value, BridgedValue base, BridgedInstruction::MarkDependenceKind kind) const {
25022508
return {unbridged().createMarkDependence(regularLoc(), value.getSILValue(), base.getSILValue(), swift::MarkDependenceKind(kind))};
25032509
}

include/swift/SIL/SILBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,11 @@ class SILBuilder {
23832383
return insert(new (getModule()) EndCOWMutationInst(getSILDebugLocation(Loc),
23842384
operand, keepUnique));
23852385
}
2386+
EndCOWMutationAddrInst *createEndCOWMutationAddr(SILLocation Loc,
2387+
SILValue operand) {
2388+
return insert(new (getModule()) EndCOWMutationAddrInst(
2389+
getSILDebugLocation(Loc), operand));
2390+
}
23862391
DestroyNotEscapedClosureInst *createDestroyNotEscapedClosure(SILLocation Loc,
23872392
SILValue operand,
23882393
unsigned VerificationType) {

0 commit comments

Comments
 (0)