Skip to content

Commit 9e7fa1a

Browse files
authored
Merge pull request #77918 from eeckstein/remove-dead-code
ArraySemantics: remove some unused code
2 parents ecf7ac9 + f166f4b commit 9e7fa1a

File tree

2 files changed

+0
-132
lines changed

2 files changed

+0
-132
lines changed

include/swift/SILOptimizer/Analysis/ArraySemantic.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,6 @@ class ArraySemanticsCall {
153153
/// parameter.
154154
void removeCall();
155155

156-
/// Replace a call to get_element by a value.
157-
///
158-
/// Preconditions:
159-
/// The value \p V must dominate this get_element call.
160-
/// This must be a get_element call.
161-
///
162-
/// Returns true on success, false otherwise.
163-
bool replaceByValue(SILValue V);
164-
165-
/// Replace a call to append(contentsOf: ) with a series of
166-
/// append(element: ) calls.
167-
bool replaceByAppendingValues(SILFunction *AppendFn,
168-
SILFunction *ReserveFn,
169-
const llvm::SmallVectorImpl<SILValue> &Vals,
170-
SubstitutionMap Subs);
171-
172156
/// Hoist the call to the insert point.
173157
void hoist(SILInstruction *InsertBefore, DominanceInfo *DT) {
174158
hoistOrCopy(InsertBefore, DT, false);

lib/SILOptimizer/Analysis/ArraySemantic.cpp

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -718,122 +718,6 @@ SILValue swift::ArraySemanticsCall::getArrayElementStoragePointer() const {
718718
return getArrayUninitializedInitResult(*this, 1);
719719
}
720720

721-
bool swift::ArraySemanticsCall::replaceByValue(SILValue V) {
722-
assert(getKind() == ArrayCallKind::kGetElement &&
723-
"Must be a get_element call");
724-
// We only handle loadable types.
725-
if (!V->getType().isLoadable(*SemanticsCall->getFunction()))
726-
return false;
727-
728-
if (!hasGetElementDirectResult())
729-
return false;
730-
731-
// Expect a check_subscript call or the empty dependence.
732-
auto SubscriptCheck = getSubscriptCheckArgument();
733-
ArraySemanticsCall Check(SubscriptCheck, "array.check_subscript");
734-
auto *EmptyDep = dyn_cast<StructInst>(SubscriptCheck);
735-
if (!Check && (!EmptyDep || !EmptyDep->getElements().empty()))
736-
return false;
737-
738-
// In OSSA, the InsertPt is after V's definition and not before SemanticsCall
739-
// Because we are creating copy_value in ossa, and the source may have been
740-
// taken previously. So our insert point for copy_value is immediately after
741-
// V, where we can be sure it is live.
742-
auto InsertPt = V->getFunction()->hasOwnership()
743-
? getInsertAfterPoint(V)
744-
: SemanticsCall->getIterator();
745-
assert(InsertPt.has_value());
746-
747-
SILValue CopiedVal = SILBuilderWithScope(InsertPt.value())
748-
.emitCopyValueOperation(SemanticsCall->getLoc(), V);
749-
SemanticsCall->replaceAllUsesWith(CopiedVal);
750-
751-
removeCall();
752-
return true;
753-
}
754-
755-
bool swift::ArraySemanticsCall::replaceByAppendingValues(
756-
SILFunction *AppendFn, SILFunction *ReserveFn,
757-
const SmallVectorImpl<SILValue> &Vals, SubstitutionMap Subs) {
758-
assert(getKind() == ArrayCallKind::kAppendContentsOf &&
759-
"Must be an append_contentsOf call");
760-
assert(AppendFn && "Must provide an append SILFunction");
761-
762-
auto *F = SemanticsCall->getFunction();
763-
764-
// We only handle loadable types.
765-
if (any_of(Vals, [F](SILValue V) -> bool {
766-
return !V->getType().isLoadable(*F);
767-
}))
768-
return false;
769-
770-
CanSILFunctionType AppendFnTy = AppendFn->getLoweredFunctionType();
771-
SILValue ArrRef = SemanticsCall->getArgument(1);
772-
SILBuilderWithScope Builder(SemanticsCall);
773-
auto Loc = SemanticsCall->getLoc();
774-
auto *FnRef = Builder.createFunctionRefFor(Loc, AppendFn);
775-
776-
if (Vals.size() > 1) {
777-
// Create a call to reserveCapacityForAppend() to reserve space for multiple
778-
// elements.
779-
FunctionRefBaseInst *ReserveFnRef =
780-
Builder.createFunctionRefFor(Loc, ReserveFn);
781-
SILFunctionType *ReserveFnTy =
782-
ReserveFnRef->getType().castTo<SILFunctionType>();
783-
assert(ReserveFnTy->getNumParameters() == 2);
784-
StructType *IntType =
785-
ReserveFnTy->getParameters()[0]
786-
.getArgumentType(F->getModule(), ReserveFnTy,
787-
Builder.getTypeExpansionContext())
788-
->castTo<StructType>();
789-
StructDecl *IntDecl = IntType->getDecl();
790-
VarDecl *field = IntDecl->getStoredProperties()[0];
791-
SILType BuiltinIntTy =SILType::getPrimitiveObjectType(
792-
field->getInterfaceType()->getCanonicalType());
793-
IntegerLiteralInst *CapacityLiteral =
794-
Builder.createIntegerLiteral(Loc, BuiltinIntTy, Vals.size());
795-
StructInst *Capacity = Builder.createStruct(Loc,
796-
SILType::getPrimitiveObjectType(CanType(IntType)), {CapacityLiteral});
797-
Builder.createApply(Loc, ReserveFnRef, Subs, {Capacity, ArrRef});
798-
}
799-
800-
for (SILValue V : Vals) {
801-
auto SubTy = V->getType();
802-
auto &ValLowering = Builder.getTypeLowering(SubTy);
803-
// In OSSA, the InsertPt is after V's definition and not before
804-
// SemanticsCall. Because we are creating copy_value in ossa, and the source
805-
// may have been taken previously. So our insert point for copy_value is
806-
// immediately after V, where we can be sure it is live.
807-
auto InsertPt = F->hasOwnership() ? getInsertAfterPoint(V)
808-
: SemanticsCall->getIterator();
809-
assert(InsertPt.has_value());
810-
SILValue CopiedVal = SILBuilderWithScope(InsertPt.value())
811-
.emitCopyValueOperation(V.getLoc(), V);
812-
auto *AllocStackInst = Builder.createAllocStack(Loc, SubTy);
813-
ValLowering.emitStoreOfCopy(Builder, Loc, CopiedVal, AllocStackInst,
814-
IsInitialization_t::IsInitialization);
815-
816-
SILValue Args[] = {AllocStackInst, ArrRef};
817-
Builder.createApply(Loc, FnRef, Subs, Args);
818-
Builder.createDeallocStack(Loc, AllocStackInst);
819-
if (!isConsumedParameterInCaller(
820-
AppendFnTy->getParameters()[0].getConvention())) {
821-
ValLowering.emitDestroyValue(Builder, Loc, CopiedVal);
822-
}
823-
}
824-
CanSILFunctionType AppendContentsOfFnTy =
825-
SemanticsCall->getReferencedFunctionOrNull()->getLoweredFunctionType();
826-
if (AppendContentsOfFnTy->getParameters()[0].getConvention() ==
827-
ParameterConvention::Direct_Owned) {
828-
SILValue SrcArray = SemanticsCall->getArgument(0);
829-
Builder.emitDestroyValueOperation(SemanticsCall->getLoc(), SrcArray);
830-
}
831-
832-
removeCall();
833-
834-
return true;
835-
}
836-
837721
bool swift::ArraySemanticsCall::mapInitializationStores(
838722
llvm::DenseMap<uint64_t, StoreInst *> &ElementValueMap) {
839723
if (getKind() != ArrayCallKind::kArrayUninitialized &&

0 commit comments

Comments
 (0)