Skip to content

Commit 55f303a

Browse files
authored
Merge pull request #5439 from gottesmm/delete_dead_code_from_typelowering
2 parents edfc64d + 5212b9e commit 55f303a

File tree

2 files changed

+3
-129
lines changed

2 files changed

+3
-129
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ class TypeLowering {
232232

233233
enum class LoweringStyle {
234234
Shallow,
235-
Deep,
236235
DeepNoEnum
237236
};
238237

@@ -259,14 +258,6 @@ class TypeLowering {
259258
emitLoweredReleaseValue(B, loc, value, LoweringStyle::Shallow);
260259
}
261260

262-
/// Emit a lowered 'release_value' operation.
263-
///
264-
/// This type must be loadable.
265-
void emitLoweredReleaseValueDeep(SILBuilder &B, SILLocation loc,
266-
SILValue value) const {
267-
emitLoweredReleaseValue(B, loc, value, LoweringStyle::Deep);
268-
}
269-
270261
/// Emit a lowered 'release_value' operation.
271262
///
272263
/// This type must be loadable.
@@ -301,14 +292,6 @@ class TypeLowering {
301292
emitLoweredRetainValue(B, loc, value, LoweringStyle::Shallow);
302293
}
303294

304-
/// Emit a lowered 'retain_value' operation.
305-
///
306-
/// This type must be loadable.
307-
void emitLoweredRetainValueDeep(SILBuilder &B, SILLocation loc,
308-
SILValue value) const {
309-
emitLoweredRetainValue(B, loc, value, LoweringStyle::Deep);
310-
}
311-
312295
/// Emit a lowered 'retain_value' operation.
313296
///
314297
/// This type must be loadable.

lib/SIL/TypeLowering.cpp

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,6 @@ namespace {
690690
case LoweringStyle::Shallow:
691691
Fn = &TypeLowering::emitReleaseValue;
692692
break;
693-
case LoweringStyle::Deep:
694-
Fn = &TypeLowering::emitLoweredReleaseValueDeep;
695-
break;
696693
case LoweringStyle::DeepNoEnum:
697694
Fn = &TypeLowering::emitLoweredReleaseValueDeepNoEnum;
698695
break;
@@ -772,98 +769,10 @@ namespace {
772769

773770
/// A lowering for loadable but non-trivial enum types.
774771
class LoadableEnumTypeLowering final : public NonTrivialLoadableTypeLowering {
775-
public:
776-
/// A non-trivial case of the enum.
777-
class NonTrivialElement {
778-
/// The non-trivial element.
779-
EnumElementDecl *element;
780-
781-
/// Its type lowering.
782-
const TypeLowering *lowering;
783-
784-
public:
785-
NonTrivialElement(EnumElementDecl *element, const TypeLowering &lowering)
786-
: element(element), lowering(&lowering) {}
787-
788-
const TypeLowering &getLowering() const { return *lowering; }
789-
EnumElementDecl *getElement() const { return element; }
790-
};
791-
792-
private:
793-
794-
using SimpleOperationTy = void (*)(SILBuilder &B, SILLocation loc, SILValue value,
795-
const TypeLowering &valueLowering,
796-
SILBasicBlock *dest);
797-
798-
/// Emit a value semantics operation for each nontrivial case of the enum.
799-
template <typename T>
800-
void ifNonTrivialElement(SILBuilder &B, SILLocation loc, SILValue value,
801-
const T &operation) const {
802-
SmallVector<std::pair<EnumElementDecl*,SILBasicBlock*>, 4> nonTrivialBBs;
803-
804-
auto &M = B.getFunction().getModule();
805-
806-
// Create all the blocks up front, so we can set up our switch_enum.
807-
auto nonTrivialElts = getNonTrivialElements(M);
808-
for (auto &elt : nonTrivialElts) {
809-
auto bb = new (M) SILBasicBlock(&B.getFunction());
810-
auto argTy = elt.getLowering().getLoweredType();
811-
new (M) SILArgument(bb, argTy);
812-
nonTrivialBBs.push_back({elt.getElement(), bb});
813-
}
814-
815-
// If we are appending to the end of a block being constructed, then we
816-
// create a new basic block to continue cons'ing up code. If we're
817-
// emitting this operation into the middle of existing code, we split the
818-
// block.
819-
SILBasicBlock *doneBB = B.splitBlockForFallthrough();
820-
B.createSwitchEnum(loc, value, doneBB, nonTrivialBBs);
821-
822-
for (size_t i = 0; i < nonTrivialBBs.size(); ++i) {
823-
SILBasicBlock *bb = nonTrivialBBs[i].second;
824-
const TypeLowering &lowering = nonTrivialElts[i].getLowering();
825-
B.emitBlock(bb);
826-
operation(B, loc, bb->getBBArgs()[0], lowering, doneBB);
827-
}
828-
829-
B.emitBlock(doneBB);
830-
}
831-
832-
/// A reference to the lazily-allocated array of non-trivial enum cases.
833-
mutable ArrayRef<NonTrivialElement> NonTrivialElements = {};
834-
835772
public:
836773
LoadableEnumTypeLowering(CanType type)
837774
: NonTrivialLoadableTypeLowering(SILType::getPrimitiveObjectType(type),
838-
IsNotReferenceCounted)
839-
{
840-
}
841-
842-
ArrayRef<NonTrivialElement> getNonTrivialElements(SILModule &M) const {
843-
SILType silTy = getLoweredType();
844-
EnumDecl *enumDecl = silTy.getEnumOrBoundGenericEnum();
845-
assert(enumDecl);
846-
847-
if (NonTrivialElements.data() == nullptr) {
848-
SmallVector<NonTrivialElement, 4> elts;
849-
850-
for (auto elt : enumDecl->getAllElements()) {
851-
if (!elt->hasArgumentType()) continue;
852-
SILType substTy = silTy.getEnumElementType(elt, M);
853-
elts.push_back(NonTrivialElement{elt,
854-
M.Types.getTypeLowering(substTy)});
855-
}
856-
857-
auto isDependent = IsDependent_t(silTy.hasTypeParameter());
858-
859-
auto buf = operator new(sizeof(NonTrivialElement) * elts.size(),
860-
M.Types, isDependent);
861-
memcpy(buf, elts.data(), sizeof(NonTrivialElement) * elts.size());
862-
NonTrivialElements = {reinterpret_cast<NonTrivialElement*>(buf),
863-
elts.size()};
864-
}
865-
return NonTrivialElements;
866-
}
775+
IsNotReferenceCounted) {}
867776

868777
void emitRetainValue(SILBuilder &B, SILLocation loc,
869778
SILValue value) const override {
@@ -873,17 +782,7 @@ namespace {
873782
void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
874783
SILValue value,
875784
LoweringStyle style) const override {
876-
if (style == LoweringStyle::Shallow ||
877-
style == LoweringStyle::DeepNoEnum) {
878-
B.createRetainValue(loc, value, Atomicity::Atomic);
879-
} else {
880-
ifNonTrivialElement(B, loc, value,
881-
[&](SILBuilder &B, SILLocation loc, SILValue child,
882-
const TypeLowering &childLowering, SILBasicBlock *dest) {
883-
childLowering.emitLoweredCopyChildValue(B, loc, child, style);
884-
B.createBranch(loc, dest);
885-
});
886-
}
785+
B.createRetainValue(loc, value, Atomicity::Atomic);
887786
}
888787

889788
void emitReleaseValue(SILBuilder &B, SILLocation loc,
@@ -897,15 +796,7 @@ namespace {
897796
assert(style != LoweringStyle::Shallow &&
898797
"This method should never be called when performing a shallow "
899798
"destroy value.");
900-
if (style == LoweringStyle::DeepNoEnum)
901-
B.emitReleaseValueAndFold(loc, value);
902-
else
903-
ifNonTrivialElement(B, loc, value,
904-
[&](SILBuilder &B, SILLocation loc, SILValue child,
905-
const TypeLowering &childLowering, SILBasicBlock *dest) {
906-
childLowering.emitLoweredDestroyChildValue(B, loc, child, style);
907-
B.createBranch(loc, dest);
908-
});
799+
B.emitReleaseValueAndFold(loc, value);
909800
}
910801
};
911802

0 commit comments

Comments
 (0)