本文整理汇总了C++中SILGenFunction::emitManagedLoadCopy方法的典型用法代码示例。如果您正苦于以下问题:C++ SILGenFunction::emitManagedLoadCopy方法的具体用法?C++ SILGenFunction::emitManagedLoadCopy怎么用?C++ SILGenFunction::emitManagedLoadCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SILGenFunction
的用法示例。
在下文中一共展示了SILGenFunction::emitManagedLoadCopy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: emitBuiltinReinterpretCast
/// Specialized emitter for Builtin.reinterpretCast.
static ManagedValue emitBuiltinReinterpretCast(SILGenFunction &SGF,
SILLocation loc,
SubstitutionMap substitutions,
ArrayRef<ManagedValue> args,
SGFContext C) {
assert(args.size() == 1 && "reinterpretCast should be given one argument");
assert(substitutions.getReplacementTypes().size() == 2 &&
"reinterpretCast should have two subs");
auto &fromTL = SGF.getTypeLowering(substitutions.getReplacementTypes()[0]);
auto &toTL = SGF.getTypeLowering(substitutions.getReplacementTypes()[1]);
// If casting between address types, cast the address.
if (fromTL.isAddress() || toTL.isAddress()) {
SILValue fromAddr;
// If the from value is not an address, move it to a buffer.
if (!fromTL.isAddress()) {
fromAddr = SGF.emitTemporaryAllocation(loc, args[0].getValue()->getType());
fromTL.emitStore(SGF.B, loc, args[0].getValue(), fromAddr,
StoreOwnershipQualifier::Init);
} else {
fromAddr = args[0].getValue();
}
auto toAddr = SGF.B.createUncheckedAddrCast(loc, fromAddr,
toTL.getLoweredType().getAddressType());
// Load and retain the destination value if it's loadable. Leave the cleanup
// on the original value since we don't know anything about it's type.
if (!toTL.isAddress()) {
return SGF.emitManagedLoadCopy(loc, toAddr, toTL);
}
// Leave the cleanup on the original value.
if (toTL.isTrivial())
return ManagedValue::forUnmanaged(toAddr);
// Initialize the +1 result buffer without taking the incoming value. The
// source and destination cleanups will be independent.
return SGF.B.bufferForExpr(
loc, toTL.getLoweredType(), toTL, C,
[&](SILValue bufferAddr) {
SGF.B.createCopyAddr(loc, toAddr, bufferAddr, IsNotTake,
IsInitialization);
});
}
// Create the appropriate bitcast based on the source and dest types.
ManagedValue in = args[0];
SILType resultTy = toTL.getLoweredType();
if (resultTy.isTrivial(SGF.F))
return SGF.B.createUncheckedTrivialBitCast(loc, in, resultTy);
// If we can perform a ref cast, just return.
if (auto refCast = SGF.B.tryCreateUncheckedRefCast(loc, in, resultTy))
return refCast;
// Otherwise leave the original cleanup and retain the cast value.
SILValue out = SGF.B.createUncheckedBitwiseCast(loc, in.getValue(), resultTy);
return SGF.emitManagedRetain(loc, out, toTL);
}
示例2: emitBuiltinReinterpretCast
/// Specialized emitter for Builtin.reinterpretCast.
static ManagedValue emitBuiltinReinterpretCast(SILGenFunction &gen,
SILLocation loc,
SubstitutionList substitutions,
ArrayRef<ManagedValue> args,
CanFunctionType formalApplyType,
SGFContext C) {
assert(args.size() == 1 && "reinterpretCast should be given one argument");
assert(substitutions.size() == 2 && "reinterpretCast should have two subs");
auto &fromTL = gen.getTypeLowering(substitutions[0].getReplacement());
auto &toTL = gen.getTypeLowering(substitutions[1].getReplacement());
// If casting between address-only types, cast the address.
if (!fromTL.isLoadable() || !toTL.isLoadable()) {
SILValue fromAddr;
// If the from value is loadable, move it to a buffer.
if (fromTL.isLoadable()) {
fromAddr = gen.emitTemporaryAllocation(loc, args[0].getValue()->getType());
fromTL.emitStore(gen.B, loc, args[0].getValue(), fromAddr,
StoreOwnershipQualifier::Init);
} else {
fromAddr = args[0].getValue();
}
auto toAddr = gen.B.createUncheckedAddrCast(loc, fromAddr,
toTL.getLoweredType().getAddressType());
// Load and retain the destination value if it's loadable. Leave the cleanup
// on the original value since we don't know anything about it's type.
if (toTL.isLoadable()) {
return gen.emitManagedLoadCopy(loc, toAddr, toTL);
}
// Leave the cleanup on the original value.
if (toTL.isTrivial())
return ManagedValue::forUnmanaged(toAddr);
// Initialize the +1 result buffer without taking the incoming value. The
// source and destination cleanups will be independent.
return gen.B.bufferForExpr(
loc, toTL.getLoweredType(), toTL, C,
[&](SILValue bufferAddr) {
gen.B.createCopyAddr(loc, toAddr, bufferAddr, IsNotTake,
IsInitialization);
});
}
// Create the appropriate bitcast based on the source and dest types.
auto &in = args[0];
SILValue out = gen.B.createUncheckedBitCast(loc, in.getValue(),
toTL.getLoweredType());
// If the cast reduces to unchecked_ref_cast, then the source and dest
// have identical cleanup, so just forward the cleanup as an optimization.
if (isa<UncheckedRefCastInst>(out))
return ManagedValue(out, in.getCleanup());
// Otherwise leave the original cleanup and retain the cast value.
return gen.emitManagedRetain(loc, out, toTL);
}