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:
Erik Eckstein
2019-12-01 15:37:01 +01:00
parent d57ee1316b
commit 8f2632939a
12 changed files with 219 additions and 3 deletions

View File

@@ -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,