Skip to content

Commit 251b423

Browse files
committed
---
yaml --- r: 327543 b: refs/heads/tensorflow c: d07593b h: refs/heads/master i: 327541: e8c3162 327539: eafae43 327535: 38da48d
1 parent 1844e82 commit 251b423

File tree

12 files changed

+85
-142
lines changed

12 files changed

+85
-142
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: bb1ae9c697f6f408ea0d85671e894b8a5b04cf53
819+
refs/heads/tensorflow: d07593b3522e9c493e7da1c6e0dfb543144ba0cc
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/include/swift/Basic/BlotSetVector.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ class BlotSetVector {
6464
iterator end() { return vector.end(); }
6565
const_iterator begin() const { return vector.begin(); }
6666
const_iterator end() const { return vector.end(); }
67-
68-
ArrayRef<Optional<ValueT>> getArray() const { return vector; }
69-
7067
llvm::iterator_range<const_iterator> getRange() const {
7168
return {begin(), end()};
7269
}

branches/tensorflow/lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,12 @@ namespace {
145145
/// the worklist before we delete them.
146146
struct SemanticARCOptVisitor
147147
: SILInstructionVisitor<SemanticARCOptVisitor, bool> {
148-
/// Our main worklist. We use this after an initial run through.
149148
SmallBlotSetVector<SILValue, 32> worklist;
150-
151-
/// A secondary work list that we use to store dead trivial instructions to
152-
/// delete after we are done processing the worklist.
153-
SmallBlotSetVector<SILInstruction *, 32> deadTrivialInsts;
154-
155149
SILFunction &F;
156150
Optional<DeadEndBlocks> TheDeadEndBlocks;
157-
151+
158152
explicit SemanticARCOptVisitor(SILFunction &F) : F(F) {}
159-
153+
160154
DeadEndBlocks &getDeadEndBlocks() {
161155
if (!TheDeadEndBlocks)
162156
TheDeadEndBlocks.emplace(&F);
@@ -173,7 +167,7 @@ struct SemanticARCOptVisitor
173167

174168
/// Add all operands of i to the worklist and then call eraseInstruction on
175169
/// i. Assumes that the instruction doesnt have users.
176-
void eraseInstructionAndAddOperandsToWorklist(SILInstruction *i) {
170+
void eraseInstructionAndAddOptsToWorklist(SILInstruction *i) {
177171
// Then copy all operands into the worklist for future processing.
178172
for (SILValue v : i->getOperandValues()) {
179173
worklist.insert(v);
@@ -190,7 +184,6 @@ struct SemanticARCOptVisitor
190184
for (SILValue result : i->getResults()) {
191185
worklist.erase(result);
192186
}
193-
deadTrivialInsts.erase(i);
194187
i->eraseFromParent();
195188
}
196189

@@ -234,7 +227,18 @@ bool SemanticARCOptVisitor::processWorklist() {
234227
// the instruction).
235228
if (auto *defInst = next->getDefiningInstruction()) {
236229
if (isInstructionTriviallyDead(defInst)) {
237-
deadTrivialInsts.insert(defInst);
230+
madeChange = true;
231+
recursivelyDeleteTriviallyDeadInstructions(
232+
defInst, true/*force*/,
233+
[&](SILInstruction *i) {
234+
for (SILValue operand : i->getOperandValues()) {
235+
worklist.insert(operand);
236+
}
237+
for (SILValue result : i->getResults()) {
238+
worklist.erase(result);
239+
}
240+
++NumEliminatedInsts;
241+
});
238242
continue;
239243
}
240244
}
@@ -247,23 +251,6 @@ bool SemanticARCOptVisitor::processWorklist() {
247251
}
248252
}
249253

250-
// Then eliminate the rest of the dead trivial insts.
251-
//
252-
// NOTE: We do not need to touch the worklist here since it is guaranteed to
253-
// be empty due to the loop above. We enforce this programatically with the
254-
// assert.
255-
assert(worklist.empty() && "Expected drained worklist so we don't have to "
256-
"remove dead insts form it");
257-
while (!deadTrivialInsts.empty()) {
258-
auto val = deadTrivialInsts.pop_back_val();
259-
if (!val)
260-
continue;
261-
recursivelyDeleteTriviallyDeadInstructions(
262-
*val, true /*force*/,
263-
[&](SILInstruction *i) { deadTrivialInsts.erase(i); });
264-
madeChange = true;
265-
}
266-
267254
return madeChange;
268255
}
269256

@@ -517,7 +504,7 @@ bool SemanticARCOptVisitor::eliminateDeadLiveRangeCopyValue(CopyValueInst *cvi)
517504
if (auto *op = cvi->getSingleUse()) {
518505
if (auto *dvi = dyn_cast<DestroyValueInst>(op->getUser())) {
519506
eraseInstruction(dvi);
520-
eraseInstructionAndAddOperandsToWorklist(cvi);
507+
eraseInstructionAndAddOptsToWorklist(cvi);
521508
NumEliminatedInsts += 2;
522509
return true;
523510
}
@@ -544,7 +531,7 @@ bool SemanticARCOptVisitor::eliminateDeadLiveRangeCopyValue(CopyValueInst *cvi)
544531
eraseInstruction(destroys.pop_back_val());
545532
++NumEliminatedInsts;
546533
}
547-
eraseInstructionAndAddOperandsToWorklist(cvi);
534+
eraseInstructionAndAddOptsToWorklist(cvi);
548535
++NumEliminatedInsts;
549536
return true;
550537
}
@@ -751,9 +738,8 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
751738
if (!isDeadLiveRange(li, destroyValues))
752739
return false;
753740

754-
// Then check if our address is ever written to. If it is, then we cannot use
755-
// the load_borrow because the stored value may be released during the loaded
756-
// value's live range.
741+
// Then check if our address is ever written to. If it is, then we
742+
// can not use the load_borrow.
757743
if (isWrittenTo(li))
758744
return false;
759745

branches/tensorflow/lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ bool SILPerformanceInliner::isProfitableToInline(
262262
assert(Callee);
263263
bool IsGeneric = AI.hasSubstitutions();
264264

265-
assert(EnableSILInliningOfGenerics || !IsGeneric);
266-
267265
// Start with a base benefit.
268266
int BaseBenefit = RemovedCallBenefit;
269267

@@ -555,17 +553,26 @@ static Optional<bool> shouldInlineGeneric(FullApplySite AI) {
555553
if (Callee->getInlineStrategy() == AlwaysInline || Callee->isTransparent())
556554
return true;
557555

558-
// All other generic functions should not be inlined if this kind of inlining
559-
// is disabled.
560-
if (!EnableSILInliningOfGenerics)
561-
return false;
562-
563556
// If all substitutions are concrete, then there is no need to perform the
564557
// generic inlining. Let the generic specializer create a specialized
565558
// function and then decide if it is beneficial to inline it.
566559
if (!AI.getSubstitutionMap().hasArchetypes())
567560
return false;
568561

562+
if (Callee->getLoweredFunctionType()->getCoroutineKind() !=
563+
SILCoroutineKind::None) {
564+
// Co-routines are so expensive (e.g. Array.subscript.read) that we always
565+
// enable inlining them in a generic context. Though the final inlining
566+
// decision is done by the usual heuristics. Therefore we return None and
567+
// not true.
568+
return None;
569+
}
570+
571+
// All other generic functions should not be inlined if this kind of inlining
572+
// is disabled.
573+
if (!EnableSILInliningOfGenerics)
574+
return false;
575+
569576
// It is not clear yet if this function should be decided or not.
570577
return None;
571578
}

branches/tensorflow/lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -767,20 +767,16 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
767767
return nullptr;
768768
}
769769

770-
if (!EnableSILInliningOfGenerics && AI.hasSubstitutions()) {
771-
// Inlining of generics is not allowed unless it is an @inline(__always)
772-
// or transparent function.
773-
if (Callee->getInlineStrategy() != AlwaysInline && !Callee->isTransparent())
774-
return nullptr;
775-
}
776-
777770
// We cannot inline function with layout constraints on its generic types
778771
// if the corresponding substitution type does not have the same constraints.
779772
// The reason for this restriction is that we'd need to be able to express
780773
// in SIL something like casting a value of generic type T into a value of
781774
// generic type T: _LayoutConstraint, which is impossible currently.
782-
if (EnableSILInliningOfGenerics && AI.hasSubstitutions()) {
783-
if (!isCallerAndCalleeLayoutConstraintsCompatible(AI))
775+
if (AI.hasSubstitutions()) {
776+
if (!isCallerAndCalleeLayoutConstraintsCompatible(AI) &&
777+
// TODO: revisit why we can make an exception for inline-always
778+
// functions. Some tests depend on it.
779+
Callee->getInlineStrategy() != AlwaysInline && !Callee->isTransparent())
784780
return nullptr;
785781
}
786782

branches/tensorflow/stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,8 +2011,6 @@ void swift::gatherWrittenGenericArgs(
20112011
const TypeContextDescriptor *description,
20122012
SmallVectorImpl<const Metadata *> &allGenericArgs,
20132013
Demangler &BorrowFrom) {
2014-
if (!description)
2015-
return;
20162014
auto generics = description->getGenericContext();
20172015
if (!generics)
20182016
return;

branches/tensorflow/test/Generics/Inputs/generic-nested-in-extension-on-objc-class.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.

branches/tensorflow/test/Generics/generic-nested-in-extension-on-objc-class.swift

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -parse-as-library -O -emit-sil %s | %FileCheck %s
2+
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
3+
4+
@inline(never)
5+
func useit<T>(_ t: T) {
6+
print(t)
7+
}
8+
9+
// Check that we inline the Array.subscript.read coroutine
10+
11+
// CHECK-LABEL: sil @{{.*}}testit
12+
// CHECK-NOT: begin_apply
13+
// CHECK-NOT: end_apply
14+
// CHECK: } // end sil function {{.*}}testit
15+
public func testit<T>(_ a: [T]) {
16+
for t in a {
17+
useit(t)
18+
}
19+
}
20+
21+
// Check that we inline the ManagedBufferPointer.header.read coroutine
22+
23+
public final class MyBuffer<Element> {
24+
typealias Manager = ManagedBufferPointer<Int, Element>
25+
26+
// CHECK-LABEL: sil @{{.*}}MyBuffer{{.*}}countSivg
27+
// CHECK-NOT: begin_apply
28+
// CHECK-NOT: end_apply
29+
// CHECK: } // end sil function {{.*}}MyBuffer{{.*}}countSivg
30+
public var count: Int {
31+
return Manager(unsafeBufferObject: self).header
32+
}
33+
}
34+

branches/tensorflow/test/SILOptimizer/pound_assert.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend -enable-experimental-static-assert -emit-sil %s -verify
2-
// RUN: %target-swift-frontend -enable-experimental-static-assert -enable-ownership-stripping-after-serialization -emit-sil %s -verify
32

43
// REQUIRES: optimized_stdlib
54
// REQUIRES: asserts
@@ -68,6 +67,18 @@ func test_loops() {
6867
#assert(infiniteLoop() == 1)
6968
}
7069

70+
// NOTE: We currently hit the limit of 512 on a debug_value in the prelude of
71+
// this function. TODO: What is the right thing to do here?
72+
func recursive(a: Int) -> Int { // expected-note {{limit exceeded here}}
73+
return a == 0 ? 0 : recursive(a: a-1)
74+
}
75+
76+
func test_recursive() {
77+
// expected-error @+2 {{#assert condition not constant}}
78+
// expected-note @+1 {{exceeded instruction limit: 512 when evaluating the expression at compile time}}
79+
#assert(recursive(a: 20000) > 42)
80+
}
81+
7182
func conditional(_ x: Int) -> Int {
7283
if x < 0 {
7384
return 0

branches/tensorflow/test/SILOptimizer/pound_assert_test_recursive.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

branches/tensorflow/test/SILOptimizer/semantic-arc-opts.sil

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -838,21 +838,3 @@ bb0(%0 : @guaranteed $NativeObjectPair):
838838
apply %func(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> MyNever
839839
unreachable
840840
}
841-
842-
// Just make sure that we do not crash on this. We should be able to eliminate
843-
// everything here.
844-
//
845-
// CHECK-LABEL: sil [ossa] @copy_value_with_debug_user : $@convention(thin) (@guaranteed NativeObjectPair) -> () {
846-
// CHECK: bb0
847-
// CHECK-NEXT: tuple
848-
// CHECK-NEXT: return
849-
// CHECK-NEXT: } // end sil function 'copy_value_with_debug_user'
850-
sil [ossa] @copy_value_with_debug_user : $@convention(thin) (@guaranteed NativeObjectPair) -> () {
851-
bb0(%0 : @guaranteed $NativeObjectPair):
852-
%1 = struct_extract %0 : $NativeObjectPair, #NativeObjectPair.obj1
853-
%2 = copy_value %1 : $Builtin.NativeObject
854-
debug_value %2 : $Builtin.NativeObject, let, name "myField"
855-
destroy_value %2 : $Builtin.NativeObject
856-
%9999 = tuple()
857-
return %9999 : $()
858-
}

0 commit comments

Comments
 (0)