Skip to content

Revert "SILOptimizer: Replace Array.append(contentsOf: with Array.append(elem…" #6103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions benchmark/single-source/ArrayAppend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,4 @@ public func run_ArrayAppendRepeatCol(_ N: Int) {
}
}

// Concatenate a single element array
@inline(never)
public func run_ArrayConcat(_ N: Int) {
for _ in 0..<N {
for _ in 0..<10 {
var nums = [Int]()
for _ in 0..<40000 {
nums += [1]
}
}
}
}

5 changes: 1 addition & 4 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,7 @@ class ASTContext {

/// Retrieve the declaration of Swift.==(Int, Int) -> Bool.
FuncDecl *getEqualIntDecl() const;

/// Retrieve the declaration of Array.append(element:)
FuncDecl *getArrayAppendElementDecl() const;


/// Retrieve the declaration of Swift._unimplementedInitializer.
FuncDecl *getUnimplementedInitializerDecl(LazyResolver *resolver) const;

Expand Down
12 changes: 1 addition & 11 deletions include/swift/SILOptimizer/Analysis/ArraySemantic.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ enum class ArrayCallKind {
// The following two semantic function kinds return the result @owned
// instead of operating on self passed as parameter.
kArrayInit,
kArrayUninitialized,
// The following semantic function kinds have a self parameter,
// and are mutating
kAppendContentsOf,
kAppendElement
kArrayUninitialized
};

/// Wrapper around array semantic calls.
Expand Down Expand Up @@ -135,12 +131,6 @@ class ArraySemanticsCall {
/// Returns true on success, false otherwise.
bool replaceByValue(SILValue V);

/// Replace a call to append(contentsOf: ) with a series of
/// append(element: ) calls.
bool replaceByAppendingValues(SILModule &M, SILFunction *AppendFn,
llvm::SmallVectorImpl<SILValue> &Vals,
ArrayRef<Substitution> Subs);

/// Hoist the call to the insert point.
void hoist(SILInstruction *InsertBefore, DominanceInfo *DT) {
hoistOrCopy(InsertBefore, DT, false);
Expand Down
52 changes: 0 additions & 52 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ struct ASTContext::Implementation {
/// func ==(Int, Int) -> Bool
FuncDecl *EqualIntDecl = nullptr;

/// func append(Element) -> void
FuncDecl *ArrayAppendElementDecl = nullptr;

/// func _unimplementedInitializer(className: StaticString).
FuncDecl *UnimplementedInitializerDecl = nullptr;

Expand Down Expand Up @@ -891,55 +888,6 @@ FuncDecl *ASTContext::getEqualIntDecl() const {
return nullptr;
}

FuncDecl *ASTContext::getArrayAppendElementDecl() const {
if (Impl.ArrayAppendElementDecl)
return Impl.ArrayAppendElementDecl;

auto AppendFunctions = getArrayDecl()->lookupDirect(getIdentifier("append"));

for (auto CandidateFn : AppendFunctions) {
auto FnDecl = dyn_cast<FuncDecl>(CandidateFn);
auto Attrs = FnDecl->getAttrs();
for (auto *A : Attrs.getAttributes<SemanticsAttr, false>()) {
if (A->Value != "array.append_element")
continue;

#ifndef NDEBUG
auto ParamLists = FnDecl->getParameterLists();
assert(ParamLists.size() == 2 && "Should have two parameter lists");
assert(ParamLists[0]->size() == 1 &&
"First parameter list should have one parameter");
auto SelfInOutTy = ParamLists[0]->get(0)->getType()->getAs<InOutType>();
assert(SelfInOutTy && "Self parameter should be an inout Type");
auto SelfGenericStructTy =
SelfInOutTy->getObjectType()->getAs<BoundGenericStructType>();
assert(SelfGenericStructTy &&
"Self parameter should be a BoundGenericStructType Type");
assert(SelfGenericStructTy->getDecl() == getArrayDecl() &&
"Self parameter should be an Array");

assert(ParamLists[1]->size() == 1 &&
"Second parameter list should have one parameter");
auto ElementType = ParamLists[1]
->get(0)
->getType()
->getAs<ArchetypeType>();
assert(ElementType &&
"First parameter replacement should be a Archetype");
assert(ElementType->getName() == getIdentifier("Element") &&
"The Archetype's name should be \"Element\"");

assert(FnDecl->getResultInterfaceType()->isVoid() &&
"The return type should be void");
#endif
Impl.ArrayAppendElementDecl = FnDecl;
return FnDecl;
}
}

return NULL;
}

FuncDecl *
ASTContext::getUnimplementedInitializerDecl(LazyResolver *resolver) const {
if (Impl.UnimplementedInitializerDecl)
Expand Down
43 changes: 1 addition & 42 deletions lib/SILOptimizer/Analysis/ArraySemantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ ArrayCallKind swift::ArraySemanticsCall::getKind() const {
.Case("array.get_element_address",
ArrayCallKind::kGetElementAddress)
.Case("array.mutate_unknown", ArrayCallKind::kMutateUnknown)
.Case("array.withUnsafeMutableBufferPointer",
ArrayCallKind::kWithUnsafeMutableBufferPointer)
.Case("array.append_contentsOf", ArrayCallKind::kAppendContentsOf)
.Case("array.append_element", ArrayCallKind::kAppendElement)
.Case("array.withUnsafeMutableBufferPointer", ArrayCallKind::kWithUnsafeMutableBufferPointer)
.Default(ArrayCallKind::kNone);
if (Tmp != ArrayCallKind::kNone) {
assert(Kind == ArrayCallKind::kNone && "Multiple array semantic "
Expand Down Expand Up @@ -685,41 +682,3 @@ bool swift::ArraySemanticsCall::replaceByValue(SILValue V) {
removeCall();
return true;
}

bool swift::ArraySemanticsCall::replaceByAppendingValues(
SILModule &M, SILFunction *AppendFn, SmallVectorImpl<SILValue> &Vals,
ArrayRef<Substitution> Subs) {
assert(getKind() == ArrayCallKind::kAppendContentsOf &&
"Must be an append_contentsOf call");
assert(AppendFn && "Must provide an append SILFunction");

// We only handle loadable types.
if (any_of(Vals, [&M](SILValue V) -> bool {
return !V->getType().isLoadable(M);
}))
return false;

auto ArrRef = SemanticsCall->getArgument(1);
SILBuilderWithScope Builder(SemanticsCall);
auto Loc = SemanticsCall->getLoc();
auto *FnRef = Builder.createFunctionRef(Loc, AppendFn);
auto FnTy = FnRef->getType();

for (auto &V : Vals) {
auto SubTy = V->getType();
auto &ValLowering = Builder.getModule().getTypeLowering(SubTy);
auto CopiedVal = ValLowering.emitCopyValue(Builder, Loc, V);
auto *AllocStackInst = Builder.createAllocStack(Loc, SubTy);
Builder.createStore(Loc, CopiedVal, AllocStackInst,
StoreOwnershipQualifier::Unqualified);
SILValue Args[] = {AllocStackInst, ArrRef};
Builder.createApply(Loc, FnRef, FnTy.substGenericArgs(M, Subs),
FnTy.castTo<SILFunctionType>()->getSILResult(), Subs,
Args, false);
Builder.createDeallocStack(Loc, AllocStackInst);
}

removeCall();

return true;
}
4 changes: 0 additions & 4 deletions lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,6 @@ static bool isNonMutatingArraySemanticCall(SILInstruction *Inst) {
case ArrayCallKind::kWithUnsafeMutableBufferPointer:
case ArrayCallKind::kArrayInit:
case ArrayCallKind::kArrayUninitialized:
case ArrayCallKind::kAppendContentsOf:
case ArrayCallKind::kAppendElement:
return false;
}

Expand Down Expand Up @@ -827,8 +825,6 @@ static bool mayChangeArrayValueToNonUniqueState(ArraySemanticsCall &Call) {
case ArrayCallKind::kWithUnsafeMutableBufferPointer:
case ArrayCallKind::kArrayInit:
case ArrayCallKind::kArrayUninitialized:
case ArrayCallKind::kAppendContentsOf:
case ArrayCallKind::kAppendElement:
return true;
}

Expand Down
Loading