|
12 | 12 |
|
13 | 13 | #include "SILGenBuilder.h"
|
14 | 14 | #include "ArgumentSource.h"
|
| 15 | +#include "Cleanup.h" |
15 | 16 | #include "RValue.h"
|
16 | 17 | #include "SILGenFunction.h"
|
17 | 18 | #include "Scope.h"
|
@@ -450,6 +451,9 @@ static ManagedValue createInputFunctionArgument(SILGenBuilder &B, SILType type,
|
450 | 451 | case SILArgumentConvention::Direct_Unowned:
|
451 | 452 | // Unowned parameters are only guaranteed at the instant of the call, so we
|
452 | 453 | // must retain them even if we're in a context that can accept a +0 value.
|
| 454 | + // |
| 455 | + // NOTE: If we have a trivial value, the copy will do nothing, so this is |
| 456 | + // just a convenient way to avoid writing conditional code. |
453 | 457 | return ManagedValue::forUnmanaged(arg).copy(SGF, loc);
|
454 | 458 |
|
455 | 459 | case SILArgumentConvention::Direct_Owned:
|
@@ -882,3 +886,38 @@ ManagedValue SILGenBuilder::createMarkDependence(SILLocation loc,
|
882 | 886 | base.forward(getSILGenFunction()));
|
883 | 887 | return cloner.clone(mdi);
|
884 | 888 | }
|
| 889 | + |
| 890 | +ManagedValue SILGenBuilder::createBeginBorrow(SILLocation loc, |
| 891 | + ManagedValue value, |
| 892 | + bool isLexical) { |
| 893 | + auto *newValue = |
| 894 | + SILBuilder::createBeginBorrow(loc, value.getValue(), isLexical); |
| 895 | + SGF.emitManagedBorrowedRValueWithCleanup(newValue); |
| 896 | + return ManagedValue::forUnmanaged(newValue); |
| 897 | +} |
| 898 | + |
| 899 | +ManagedValue SILGenBuilder::createMoveValue(SILLocation loc, |
| 900 | + ManagedValue value) { |
| 901 | + assert(value.isPlusOne(SGF) && "Must be +1 to be moved!"); |
| 902 | + CleanupCloner cloner(*this, value); |
| 903 | + auto *mdi = createMoveValue(loc, value.forward(getSILGenFunction())); |
| 904 | + return cloner.clone(mdi); |
| 905 | +} |
| 906 | + |
| 907 | +ManagedValue |
| 908 | +SILGenBuilder::createOwnedMoveOnlyWrapperToCopyableValue(SILLocation loc, |
| 909 | + ManagedValue value) { |
| 910 | + assert(value.isPlusOne(SGF) && "Argument must be at +1!"); |
| 911 | + CleanupCloner cloner(*this, value); |
| 912 | + auto *mdi = createOwnedMoveOnlyWrapperToCopyableValue( |
| 913 | + loc, value.forward(getSILGenFunction())); |
| 914 | + return cloner.clone(mdi); |
| 915 | +} |
| 916 | + |
| 917 | +ManagedValue SILGenBuilder::createGuaranteedMoveOnlyWrapperToCopyableValue( |
| 918 | + SILLocation loc, ManagedValue value) { |
| 919 | + auto *mdi = |
| 920 | + createGuaranteedMoveOnlyWrapperToCopyableValue(loc, value.getValue()); |
| 921 | + assert(mdi->getOperand()->getType().isObject() && "Expected an object?!"); |
| 922 | + return ManagedValue::forUnmanaged(mdi); |
| 923 | +} |
0 commit comments