Skip to content

Commit d1389ad

Browse files
committed
[cast-opt] Refactor some code onto SILDynamicCast and delete dead code.
NFC.
1 parent c6f7f97 commit d1389ad

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

include/swift/SIL/DynamicCasts.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ struct SILDynamicCastInst {
448448
return t->getCanonicalType();
449449
}
450450

451+
Optional<SILType> getLoweredBridgedTargetObjectType() const {
452+
CanType t = getBridgedTargetType();
453+
if (!t)
454+
return None;
455+
return SILType::getPrimitiveObjectType(t);
456+
}
457+
451458
bool isConditional() const {
452459
switch (getKind()) {
453460
case SILDynamicCastKind::CheckedCastAddrBranchInst: {

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
166166
SILInstruction *Inst = dynamicCast.getInstruction();
167167
bool isConditional = dynamicCast.isConditional();
168168
SILValue Dest = dynamicCast.getDest();
169-
CanType BridgedTargetTy = dynamicCast.getBridgedTargetType();
170169
SILBasicBlock *SuccessBB = dynamicCast.getSuccessBlock();
171170
SILBasicBlock *FailureBB = dynamicCast.getFailureBlock();
172171
auto *F = Inst->getFunction();
@@ -186,9 +185,6 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
186185
ParameterConvention::Direct_Guaranteed &&
187186
"Parameter should be @guaranteed");
188187

189-
CanType CanBridgedTy = BridgedTargetTy->getCanonicalType();
190-
SILType silBridgedTy = SILType::getPrimitiveObjectType(CanBridgedTy);
191-
192188
SILBuilderWithScope Builder(Inst, builderContext);
193189

194190
// If this is a conditional cast:
@@ -215,6 +211,8 @@ CastOptimizer::optimizeBridgedObjCToSwiftCast(SILDynamicCastInst dynamicCast) {
215211
SILValue load =
216212
Builder.createLoad(Loc, src, LoadOwnershipQualifier::Unqualified);
217213

214+
SILType silBridgedTy = *dynamicCast.getLoweredBridgedTargetObjectType();
215+
218216
// If type of the source and the expected ObjC type are equal, there is no
219217
// need to generate the conversion from ObjCTy to
220218
// _ObjectiveCBridgeable._ObjectiveCType.

0 commit comments

Comments
 (0)