mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Builtins to support copy-on-write SIL instructions
* Builtin.COWBufferForReading -> ref_element_addr [immutable] / ref_tail_addr [immutable] * Builtin.beginCOWmutation -> begin_cow_mutation * Builtin.endCOWmutation -> end_cow_mutation
This commit is contained in:
@@ -901,6 +901,60 @@ emitBuiltinIsUnique_native(SILGenFunction &SGF,
|
||||
return ManagedValue::forUnmanaged(result);
|
||||
}
|
||||
|
||||
static ManagedValue
|
||||
emitBuiltinBeginCOWMutation(SILGenFunction &SGF,
|
||||
SILLocation loc,
|
||||
SubstitutionMap subs,
|
||||
ArrayRef<ManagedValue> args,
|
||||
SGFContext C) {
|
||||
|
||||
assert(subs.getReplacementTypes().size() == 1 &&
|
||||
"BeginCOWMutation should have one sub.");
|
||||
assert(args.size() == 1 && "isUnique_native should have one arg.");
|
||||
|
||||
SILValue refAddr = args[0].getValue();
|
||||
auto *ref = SGF.B.createLoad(loc, refAddr, LoadOwnershipQualifier::Take);
|
||||
BeginCOWMutationInst *beginCOW = SGF.B.createBeginCOWMutation(loc, ref, /*isNative*/ false);
|
||||
SGF.B.createStore(loc, beginCOW->getBufferResult(), refAddr, StoreOwnershipQualifier::Init);
|
||||
return ManagedValue::forUnmanaged(beginCOW->getUniquenessResult());
|
||||
}
|
||||
|
||||
static ManagedValue
|
||||
emitBuiltinBeginCOWMutation_native(SILGenFunction &SGF,
|
||||
SILLocation loc,
|
||||
SubstitutionMap subs,
|
||||
ArrayRef<ManagedValue> args,
|
||||
SGFContext C) {
|
||||
|
||||
assert(subs.getReplacementTypes().size() == 1 &&
|
||||
"BeginCOWMutation should have one sub.");
|
||||
assert(args.size() == 1 && "isUnique_native should have one arg.");
|
||||
|
||||
SILValue refAddr = args[0].getValue();
|
||||
auto *ref = SGF.B.createLoad(loc, refAddr, LoadOwnershipQualifier::Take);
|
||||
BeginCOWMutationInst *beginCOW = SGF.B.createBeginCOWMutation(loc, ref, /*isNative*/ true);
|
||||
SGF.B.createStore(loc, beginCOW->getBufferResult(), refAddr, StoreOwnershipQualifier::Init);
|
||||
return ManagedValue::forUnmanaged(beginCOW->getUniquenessResult());
|
||||
}
|
||||
|
||||
static ManagedValue
|
||||
emitBuiltinEndCOWMutation(SILGenFunction &SGF,
|
||||
SILLocation loc,
|
||||
SubstitutionMap subs,
|
||||
ArrayRef<ManagedValue> args,
|
||||
SGFContext C) {
|
||||
|
||||
assert(subs.getReplacementTypes().size() == 1 &&
|
||||
"EndCOWMutation should have one sub.");
|
||||
assert(args.size() == 1 && "isUnique_native should have one arg.");
|
||||
|
||||
SILValue refAddr = args[0].getValue();
|
||||
auto ref = SGF.B.createLoad(loc, refAddr, LoadOwnershipQualifier::Take);
|
||||
auto endRef = SGF.B.createEndCOWMutation(loc, ref);
|
||||
SGF.B.createStore(loc, endRef, refAddr, StoreOwnershipQualifier::Init);
|
||||
return ManagedValue::forUnmanaged(SGF.emitEmptyTuple(loc));
|
||||
}
|
||||
|
||||
static ManagedValue emitBuiltinBindMemory(SILGenFunction &SGF,
|
||||
SILLocation loc,
|
||||
SubstitutionMap subs,
|
||||
|
||||
Reference in New Issue
Block a user