ManagedValue SILGenBuilder::createStore(SILLocation loc, ManagedValue value, SILValue address, StoreOwnershipQualifier qualifier) { SILModule &M = SGF.F.getModule(); CleanupCloner cloner(*this, value); if (value.getType().isTrivial(M) || value.getOwnershipKind() == ValueOwnershipKind::Any) qualifier = StoreOwnershipQualifier::Trivial; createStore(loc, value.forward(SGF), address, qualifier); return cloner.clone(address); }
void SILGenBuilder::createStoreBorrowOrTrivial(SILLocation loc, ManagedValue value, SILValue address) { if (value.getOwnershipKind() == ValueOwnershipKind::Any) { createStore(loc, value, address, StoreOwnershipQualifier::Trivial); return; } createStoreBorrow(loc, value, address); }
ManagedValue Scope::popPreservingValue(ManagedValue mv) { // If we have a value, make sure that it is an object. The reason why is // that we want to make sure that we are not forwarding a cleanup for a // stack location that will be destroyed by this scope. assert(mv && mv.getType().isObject() && (mv.getType().isTrivial(cleanups.SGF.getModule()) || mv.getOwnershipKind() == ValueOwnershipKind::Trivial || mv.hasCleanup())); CleanupCloner cloner(cleanups.SGF, mv); SILValue value = mv.forward(cleanups.SGF); pop(); return cloner.clone(value); }
ManagedValue SILGenBuilder::createMarkUninitialized(ValueDecl *decl, ManagedValue operand, MarkUninitializedInst::Kind muKind) { // We either have an owned or trivial value. SILValue value = createMarkUninitialized(decl, operand.forward(SGF), muKind); assert(value->getType().isObject() && "Expected only objects here"); // If we have a trivial value, just return without a cleanup. if (operand.getOwnershipKind() != ValueOwnershipKind::Owned) { return ManagedValue::forUnmanaged(value); } // Otherwise, recreate the cleanup. return SGF.emitManagedRValueWithCleanup(value); }
ManagedValue SILGenBuilder::createCopyValue(SILLocation loc, ManagedValue originalValue, const TypeLowering &lowering) { if (lowering.isTrivial()) return originalValue; SILType ty = originalValue.getType(); assert(!ty.isAddress() && "Can not perform a copy value of an address typed " "value"); if (ty.isObject() && originalValue.getOwnershipKind() == ValueOwnershipKind::Any) { return originalValue; } SILValue result = lowering.emitCopyValue(*this, loc, originalValue.getValue()); return SGF.emitManagedRValueWithCleanup(result, lowering); }
ManagedValue SILGenBuilder::createFormalAccessCopyValue(SILLocation loc, ManagedValue originalValue) { SILType ty = originalValue.getType(); const auto &lowering = SGF.getTypeLowering(ty); if (lowering.isTrivial()) return originalValue; assert(!lowering.isAddressOnly() && "cannot perform a copy value of an " "address only type"); if (ty.isObject() && originalValue.getOwnershipKind() == ValueOwnershipKind::Any) { return originalValue; } SILValue result = lowering.emitCopyValue(*this, loc, originalValue.getValue()); return SGF.emitFormalAccessManagedRValueWithCleanup(loc, result); }
void SILGenBuilder::createStoreBorrow(SILLocation loc, ManagedValue value, SILValue address) { assert(value.getOwnershipKind() == ValueOwnershipKind::Guaranteed); createStoreBorrow(loc, value.getValue(), address); }