lib/SILGen/SILGenLValue.cpp
ManagedValue SILGenFunction::emitLoad(SILLocation loc, SILValue addr,
                                      const TypeLowering &rvalueTL,
                                      SGFContext C, IsTake_t isTake,
                                      bool isGuaranteedValid) {
  // Get the lowering for the address type.  We can avoid a re-lookup
  // in the very common case of this being equivalent to the r-value
  // type.
  auto &addrTL =
    (addr->getType() == rvalueTL.getLoweredType().getAddressType()
       ? rvalueTL : getTypeLowering(addr->getType()));

  // Never do a +0 load together with a take.
  bool isPlusZeroOk = (isTake == IsNotTake &&
                       (isGuaranteedValid ? C.isGuaranteedPlusZeroOk()
                                          : C.isImmediatePlusZeroOk()));

  if (rvalueTL.isAddressOnly() && silConv.useLoweredAddresses()) {
    // If the client is cool with a +0 rvalue, the decl has an address-only
    // type, and there are no conversions, then we can return this as a +0
    // address RValue.
    if (isPlusZeroOk && rvalueTL.getLoweredType() == addrTL.getLoweredType())
      return ManagedValue::forUnmanaged(addr);
        
    // Copy the address-only value.
    return B.bufferForExpr(
        loc, rvalueTL.getLoweredType(), rvalueTL, C,
        [&](SILValue newAddr) {
          emitSemanticLoadInto(loc, addr, addrTL, newAddr, rvalueTL,
                               isTake, IsInitialization);
        });
  }

  // Ok, this is something loadable.  If this is a non-take access at plus zero,
  // we can perform a +0 load of the address instead of materializing a +1
  // value.
  if (isPlusZeroOk && addrTL.getLoweredType() == rvalueTL.getLoweredType()) {
    return B.createLoadBorrow(loc, ManagedValue::forUnmanaged(addr));
  }

  // Load the loadable value, and retain it if we aren't taking it.
  SILValue loadedV = emitSemanticLoad(loc, addr, addrTL, rvalueTL, isTake);
  return emitManagedRValueWithCleanup(loadedV);
}
/// Load an r-value out of the given address.
///
/// \param rvalueTL - the type lowering for the type-of-rvalue
///   of the address
/// \param isGuaranteedValid - true if the value in this address
///   is guaranteed to be valid for the duration of the current
///   evaluation (see SGFContext::AllowGuaranteedPlusZero)
Load an r-value out of the given address.
\param rvalueTL - the type lowering for the type-of-rvalue
of the address
\param isGuaranteedValid - true if the value in this address
is guaranteed to be valid for the duration of the current
evaluation
Load an r - value out of the given address . \ param rvalueTL - the type lowering for the type - of - rvalue of the address \ param isGuaranteedValid - true if the value in this address is guaranteed to be valid for the duration of the current evaluation
ManagedValue SILGenFunction::emitLoad(SILLocation loc, SILValue addr,
                                      const TypeLowering &rvalueTL,
                                      SGFContext C, IsTake_t isTake,
                                      bool isGuaranteedValid) {
  auto &addrTL =
    (addr->getType() == rvalueTL.getLoweredType().getAddressType()
       ? rvalueTL : getTypeLowering(addr->getType()));
  bool isPlusZeroOk = (isTake == IsNotTake &&
                       (isGuaranteedValid ? C.isGuaranteedPlusZeroOk()
                                          : C.isImmediatePlusZeroOk()));
  if (rvalueTL.isAddressOnly() && silConv.useLoweredAddresses()) {
    if (isPlusZeroOk && rvalueTL.getLoweredType() == addrTL.getLoweredType())
      return ManagedValue::forUnmanaged(addr);
    return B.bufferForExpr(
        loc, rvalueTL.getLoweredType(), rvalueTL, C,
        [&](SILValue newAddr) {
          emitSemanticLoadInto(loc, addr, addrTL, newAddr, rvalueTL,
                               isTake, IsInitialization);
        });
  }
  if (isPlusZeroOk && addrTL.getLoweredType() == rvalueTL.getLoweredType()) {
    return B.createLoadBorrow(loc, ManagedValue::forUnmanaged(addr));
  }
  SILValue loadedV = emitSemanticLoad(loc, addr, addrTL, rvalueTL, isTake);
  return emitManagedRValueWithCleanup(loadedV);
}
ManagedValue SILGenFunction :: emitLoad ( SILLocation loc , SILValue addr , const TypeLowering & rvalueTL , SGFContext C , IsTake_t isTake , bool isGuaranteedValid ) { auto & addrTL = ( addr -> getType ( ) == rvalueTL . getLoweredType ( ) . getAddressType ( ) ? rvalueTL : getTypeLowering ( addr -> getType ( ) ) ) ; bool isPlusZeroOk = ( isTake == IsNotTake && ( isGuaranteedValid ? C . isGuaranteedPlusZeroOk ( ) : C . isImmediatePlusZeroOk ( ) ) ) ; if ( rvalueTL . isAddressOnly ( ) && silConv . useLoweredAddresses ( ) ) { if ( isPlusZeroOk && rvalueTL . getLoweredType ( ) == addrTL . getLoweredType ( ) ) return ManagedValue :: forUnmanaged ( addr ) ; return B . bufferForExpr ( loc , rvalueTL . getLoweredType ( ) , rvalueTL , C , [ & ] ( SILValue newAddr ) { emitSemanticLoadInto ( loc , addr , addrTL , newAddr , rvalueTL , isTake , IsInitialization ) ; } ) ; } if ( isPlusZeroOk && addrTL . getLoweredType ( ) == rvalueTL . getLoweredType ( ) ) { return B . createLoadBorrow ( loc , ManagedValue :: forUnmanaged ( addr ) ) ; } SILValue loadedV = emitSemanticLoad ( loc , addr , addrTL , rvalueTL , isTake ) ; return emitManagedRValueWithCleanup ( loadedV ) ; }
Load an r-value out of the given address.
Load an r - value out of the given address .
// Get the lowering for the address type.  We can avoid a re-lookup // in the very common case of this being equivalent to the r-value // type. // Never do a +0 load together with a take. // If the client is cool with a +0 rvalue, the decl has an address-only // type, and there are no conversions, then we can return this as a +0 // address RValue. // Copy the address-only value. // Ok, this is something loadable.  If this is a non-take access at plus zero, // we can perform a +0 load of the address instead of materializing a +1 // value. // Load the loadable value, and retain it if we aren't taking it.