Skip to content

Commit b6ececb

Browse files
authored
Merge pull request swiftlang#61395 from atrick/rename-bitcast
Rename SILBuilder::createUncheckedBitCast
2 parents 3f02037 + 5f7f6e4 commit b6ececb

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,13 +2118,20 @@ class SILBuilder {
21182118
SingleValueInstruction *
21192119
createUncheckedReinterpretCast(SILLocation Loc, SILValue Op, SILType Ty);
21202120

2121-
/// Create an appropriate cast instruction based on result type.
2121+
/// Create an appropriate cast instruction based on result type. This cast
2122+
/// forwards ownership from the operand to the result.
21222123
///
2123-
/// NOTE: This assumes that the input and the result cast are layout
2124-
/// compatible. Reduces to createUncheckedReinterpretCast when ownership is
2125-
/// disabled.
2126-
SingleValueInstruction *createUncheckedBitCast(SILLocation Loc, SILValue Op,
2127-
SILType Ty);
2124+
/// WARNING: Because it forwards ownership, this cast is only valid with the
2125+
/// source and destination types are layout equivalent. The destination type
2126+
/// must include all the same references in the same positions.
2127+
///
2128+
/// Note: Forwarding casts do not exist outside of OSSA. When ownership is
2129+
/// disabled, this reduces to createUncheckedReinterpretCast, which may
2130+
/// fall-back to unchecked_bitwise_cast. It is the caller's responsibility to
2131+
/// emit the correct retains and releases.
2132+
SingleValueInstruction *createUncheckedForwardingCast(SILLocation Loc,
2133+
SILValue Op,
2134+
SILType Ty);
21282135

21292136
//===--------------------------------------------------------------------===//
21302137
// Runtime failure

lib/SIL/IR/SILBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ SILBuilder::createUncheckedReinterpretCast(SILLocation Loc, SILValue Op,
174174

175175
// Create the appropriate cast instruction based on result type.
176176
SingleValueInstruction *
177-
SILBuilder::createUncheckedBitCast(SILLocation Loc, SILValue Op, SILType Ty) {
177+
SILBuilder::createUncheckedForwardingCast(SILLocation Loc, SILValue Op,
178+
SILType Ty) {
178179
// Without ownership, delegate to unchecked reinterpret cast.
179180
if (!hasOwnership())
180181
return createUncheckedReinterpretCast(Loc, Op, Ty);

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
169169
Args.push_back(UAC);
170170
} else if (OldOpType.getASTType() != NewOpType.getASTType()) {
171171
auto URC =
172-
Builder.createUncheckedBitCast(AI.getLoc(), Op, NewOpType);
172+
Builder.createUncheckedForwardingCast(AI.getLoc(), Op, NewOpType);
173173
Args.push_back(URC);
174174
} else {
175175
Args.push_back(Op);
@@ -221,8 +221,8 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
221221
for (auto e = newOpResultTypes.end(); newRetI != e;
222222
++oldRetI, ++newRetI, ++origArgI) {
223223
auto arg = normalBB->createPhiArgument(*newRetI, (*origArgI)->getOwnershipKind());
224-
auto converted = Builder.createUncheckedBitCast(AI.getLoc(),
225-
arg, *oldRetI);
224+
auto converted =
225+
Builder.createUncheckedForwardingCast(AI.getLoc(), arg, *oldRetI);
226226
branchArgs.push_back(converted);
227227
}
228228

@@ -246,7 +246,8 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI,
246246
SILInstruction *result = NAI;
247247

248248
if (oldResultTy != newResultTy) {
249-
result = Builder.createUncheckedBitCast(AI.getLoc(), NAI, oldResultTy);
249+
result =
250+
Builder.createUncheckedForwardingCast(AI.getLoc(), NAI, oldResultTy);
250251
}
251252

252253
return result;

lib/SILOptimizer/Transforms/EagerSpecializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void EagerDispatch::emitDispatchTo(SILFunction *NewFunc) {
438438
auto GenResultTy = GenericFunc->mapTypeIntoContext(resultTy);
439439

440440
SILValue CastResult =
441-
Builder.createUncheckedBitCast(Loc, Result, GenResultTy);
441+
Builder.createUncheckedForwardingCast(Loc, Result, GenResultTy);
442442

443443
addReturnValue(Builder.getInsertionBB(), OldReturnBB, CastResult);
444444
}
@@ -640,7 +640,7 @@ SILValue EagerDispatch::emitArgumentCast(CanSILFunctionType CalleeSubstFnTy,
640640
if (CastTy.isAddress())
641641
return Builder.createUncheckedAddrCast(Loc, OrigArg, CastTy);
642642

643-
return Builder.createUncheckedBitCast(Loc, OrigArg, CastTy);
643+
return Builder.createUncheckedForwardingCast(Loc, OrigArg, CastTy);
644644
}
645645

646646
/// Converts each generic function argument into a SILValue that can be passed

0 commit comments

Comments
 (0)