[silgen] Add {ManagedValue,RValue}::ensurePlusOne(...).

This helper function returns *this if the value is already at +1. Otherwise, if
the value is a +0 value, we copy the value. Since I am using this initially for
some experiments, I am hiding it behind the enable guaranteed normal arguments
flag.

rdar://34222540
This commit is contained in:
Michael Gottesman
2017-11-19 03:21:05 -08:00
parent be87a396a0
commit c31cd631a2
4 changed files with 24 additions and 0 deletions

View File

@@ -698,6 +698,12 @@ RValue RValue::copy(SILGenFunction &SGF, SILLocation loc) const & {
return RValue(SGF, std::move(copiedValues), type, elementsToBeAdded);
}
RValue RValue::ensurePlusOne(SILGenFunction &SGF, SILLocation loc) && {
if (SGF.getOptions().EnableGuaranteedNormalArguments && isPlusZero(SGF))
return copy(SGF, loc);
return std::move(*this);
}
RValue RValue::borrow(SILGenFunction &SGF, SILLocation loc) const & {
assert((isComplete() || isInSpecialState()) &&
"can't borrow incomplete rvalue");