Skip to content

Commit 899386d

Browse files
authored
---
yaml --- r: 349095 b: refs/heads/master c: 7032e65 h: refs/heads/master i: 349093: 72e1905 349091: 8a23159 349087: b44ac4d
1 parent e1914fc commit 899386d

File tree

9 files changed

+156
-19
lines changed

9 files changed

+156
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d90117bb8a7e953e080fbb3f6d22e5502e7aa51b
2+
refs/heads/master: 7032e652eec8206f2597d57014855b284071576e
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/benchmark/scripts/run_smoke_bench

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def main():
9393
argparser.add_argument(
9494
'-num-samples', type=int,
9595
help='The (minimum) number of samples to run', default=3)
96+
argparser.add_argument(
97+
'-num-reruns', type=int,
98+
help="The number of re-runs until it's assumed to be a real change",
99+
default=8)
96100
argparser.add_argument(
97101
'-platform', type=str,
98102
help='The benchmark build platform', default='macosx')
@@ -120,7 +124,7 @@ def test_opt_levels(args):
120124
if test_performance(opt_level, args.oldbuilddir[0],
121125
args.newbuilddir[0],
122126
float(args.threshold) / 100, args.num_samples,
123-
output_file):
127+
args.num_reruns, output_file):
124128
changes = True
125129

126130
# There is no point in reporting code size for Onone.
@@ -171,7 +175,7 @@ def merge(results, other_results):
171175

172176

173177
def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
174-
output_file):
178+
num_reruns, output_file):
175179
"""Detect performance changes in benchmarks.
176180
177181
Start fast with few samples per benchmark and gradually spend more time
@@ -185,7 +189,7 @@ def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
185189
tests = TestComparator(results[0], results[1], threshold)
186190
changed = tests.decreased + tests.increased
187191

188-
while len(changed) > 0 and unchanged_length_count < 10:
192+
while len(changed) > 0 and unchanged_length_count < num_reruns:
189193
i += 1
190194
if VERBOSE:
191195
log(' test again: ' + str([test.name for test in changed]))

trunk/include/swift/SIL/MemoryLifetime.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222

2323
namespace swift {
2424

25+
void printBitsAsArray(llvm::raw_ostream &OS, const SmallBitVector &bits);
26+
27+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
28+
const SmallBitVector &bits) {
29+
printBitsAsArray(OS, bits);
30+
return OS;
31+
}
32+
33+
void dumpBits(const SmallBitVector &bits);
34+
2535
/// The MemoryLocations utility provides functions to analyze memory locations.
2636
///
2737
/// Memory locations are limited to addresses which are guaranteed to

trunk/lib/IRGen/GenCast.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,12 @@ void irgen::emitScalarExistentialDowncast(IRGenFunction &IGF,
638638
bool checkSuperclassConstraint = false;
639639
if (hasSuperclassConstraint) {
640640
Type srcSuperclassType = srcInstanceType;
641-
if (srcSuperclassType->isExistentialType())
641+
if (srcSuperclassType->isExistentialType()) {
642642
srcSuperclassType = srcSuperclassType->getSuperclass();
643+
// Look for an AnyObject superclass (getSuperclass() returns nil).
644+
if (!srcSuperclassType && srcInstanceType->isClassExistentialType())
645+
checkSuperclassConstraint = true;
646+
}
643647
if (srcSuperclassType) {
644648
checkSuperclassConstraint =
645649
!destInstanceType->getSuperclass()->isExactSuperclassOf(

trunk/lib/SIL/MemoryLifetime.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,28 @@ llvm::cl::opt<bool> DontAbortOnMemoryLifetimeErrors(
2828
llvm::cl::desc("Don't abort compliation if the memory lifetime checker "
2929
"detects an error."));
3030

31-
namespace swift {
32-
namespace {
33-
34-
//===----------------------------------------------------------------------===//
35-
// Utility functions
36-
//===----------------------------------------------------------------------===//
37-
3831
/// Debug dump a location bit vector.
39-
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
40-
const SmallBitVector &bits) {
32+
void swift::printBitsAsArray(llvm::raw_ostream &OS, const SmallBitVector &bits) {
4133
const char *separator = "";
4234
OS << '[';
4335
for (int idx = bits.find_first(); idx >= 0; idx = bits.find_next(idx)) {
4436
OS << separator << idx;
4537
separator = ",";
4638
}
4739
OS << ']';
48-
return OS;
4940
}
5041

42+
void swift::dumpBits(const SmallBitVector &bits) {
43+
llvm::dbgs() << bits << '\n';
44+
}
45+
46+
namespace swift {
47+
namespace {
48+
49+
//===----------------------------------------------------------------------===//
50+
// Utility functions
51+
//===----------------------------------------------------------------------===//
52+
5153
/// Enlarge the bitset if needed to set the bit with \p idx.
5254
static void setBitAndResize(SmallBitVector &bits, unsigned idx) {
5355
if (bits.size() <= idx)
@@ -240,10 +242,6 @@ void MemoryLocations::dump() const {
240242
}
241243
}
242244

243-
void MemoryLocations::dumpBits(const Bits &bits) {
244-
llvm::errs() << bits << '\n';
245-
}
246-
247245
void MemoryLocations::clear() {
248246
locations.clear();
249247
addr2LocIdx.clear();

trunk/lib/SILOptimizer/Transforms/DeadStoreElimination.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "swift/SIL/Projection.h"
6161
#include "swift/SIL/SILArgument.h"
6262
#include "swift/SIL/SILBuilder.h"
63+
#include "swift/SIL/MemoryLifetime.h"
6364
#include "swift/SILOptimizer/Analysis/AliasAnalysis.h"
6465
#include "swift/SILOptimizer/Analysis/PostOrderAnalysis.h"
6566
#include "swift/SILOptimizer/PassManager/Passes.h"
@@ -269,6 +270,8 @@ class BlockState {
269270
init(LocationNum, Optimistic);
270271
}
271272

273+
void dump();
274+
272275
/// Initialize the bitvectors for the current basic block.
273276
void init(unsigned LocationNum, bool Optimistic);
274277

@@ -448,6 +451,8 @@ enum class ProcessKind {
448451
llvm::SpecificBumpPtrAllocator<BlockState> &BPA)
449452
: Mod(M), F(F), PM(PM), AA(AA), TE(TE), EAFI(EAFI), BPA(BPA) {}
450453

454+
void dump();
455+
451456
/// Entry point for dead store elimination.
452457
bool run();
453458

@@ -481,6 +486,12 @@ enum class ProcessKind {
481486

482487
} // end anonymous namespace
483488

489+
void BlockState::dump() {
490+
llvm::dbgs() << " block " << BB->getDebugID() << ": in=" << BBWriteSetIn
491+
<< ", out=" << BBWriteSetOut << ", mid=" << BBWriteSetMid
492+
<< ", gen=" << BBGenSet << ", kill=" << BBKillSet << '\n';
493+
}
494+
484495
void BlockState::init(unsigned LocationNum, bool Optimistic) {
485496
// For function that requires just 1 iteration of the data flow to converge
486497
// we set the initial state of BBWriteSetIn to 0.
@@ -513,6 +524,21 @@ void BlockState::init(unsigned LocationNum, bool Optimistic) {
513524
BBDeallocateLocation.resize(LocationNum, false);
514525
}
515526

527+
#if __has_attribute(used)
528+
__attribute((used))
529+
#endif
530+
void DSEContext::dump() {
531+
llvm::dbgs() << "Locations:\n";
532+
unsigned idx = 0;
533+
for (const LSLocation &loc : LocationVault) {
534+
llvm::dbgs() << " #" << idx << ": " << loc.getBase();
535+
++idx;
536+
}
537+
for (SILBasicBlock &BB : *F) {
538+
getBlockState(&BB)->dump();
539+
}
540+
}
541+
516542
unsigned DSEContext::getLocationBit(const LSLocation &Loc) {
517543
// Return the bit position of the given Loc in the LocationVault. The bit
518544
// position is then used to set/reset the bitvector kept by each BlockState.
@@ -691,6 +717,10 @@ void DSEContext::mergeSuccessorLiveIns(SILBasicBlock *BB) {
691717
// dead for block with no successor.
692718
BlockState *C = getBlockState(BB);
693719
if (BB->succ_empty()) {
720+
if (isa<UnreachableInst>(BB->getTerminator())) {
721+
C->BBWriteSetOut.set();
722+
return;
723+
}
694724
C->BBWriteSetOut |= C->BBDeallocateLocation;
695725
return;
696726
}

trunk/test/IRGen/casts.sil

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,51 @@ entry(%a : $OA):
359359
%b = unconditional_checked_cast %a : $OA to $OB
360360
return %b : $OB
361361
}
362+
363+
protocol P {}
364+
protocol PAnyObject: AnyObject {}
365+
class C {}
366+
sil_vtable C {}
367+
368+
// CHECK-LABEL: define{{.*}} @cast_protocol_composition_with_anyobject
369+
// CHECK: [[C:%.*]] = call swiftcc %swift.metadata_response @"$s5casts1CCMa"
370+
// CHECK: [[C_META:%.*]] = extractvalue %swift.metadata_response [[C]], 0
371+
// CHECK: call { i8*, i8** } @dynamic_cast_existential_1_superclass_conditional({{.*}}, %swift.type* [[C_META]], %swift.protocol* {{.*}}@"$s5casts1PMp"
372+
373+
sil @cast_protocol_composition_with_anyobject : $@convention(thin) (@owned P & AnyObject ) -> @owned Optional<C & P> {
374+
bb0(%0: $P & AnyObject):
375+
checked_cast_br %0 : $P & AnyObject to $C & P, bb1, bb2
376+
377+
bb1(%2 : $C & P):
378+
%3 = enum $Optional<C & P>, #Optional.some!enumelt.1, %2 : $C & P
379+
br bb3(%3 : $Optional<C & P>)
380+
381+
bb2:
382+
strong_release %0 : $P & AnyObject
383+
%6 = enum $Optional<C & P>, #Optional.none!enumelt
384+
br bb3(%6 : $Optional<C & P>)
385+
386+
bb3(%11 : $Optional<C & P>):
387+
return %11 : $Optional<C & P>
388+
}
389+
390+
// CHECK-LABEL: define{{.*}} @cast_protocol_with_anyobject
391+
// CHECK: [[C:%.*]] = call swiftcc %swift.metadata_response @"$s5casts1CCMa"
392+
// CHECK: [[C_META:%.*]] = extractvalue %swift.metadata_response [[C]], 0
393+
// CHECK: call { i8*, i8** } @dynamic_cast_existential_1_superclass_conditional({{.*}}, %swift.type* [[C_META]], %swift.protocol* {{.*}}@"$s5casts10PAnyObjectMp"
394+
sil @cast_protocol_with_anyobject : $@convention(thin) (@owned PAnyObject ) -> @owned Optional<C & PAnyObject> {
395+
bb0(%0: $PAnyObject):
396+
checked_cast_br %0 : $PAnyObject to $C & PAnyObject, bb1, bb2
397+
398+
bb1(%2 : $C & PAnyObject):
399+
%3 = enum $Optional<C & PAnyObject>, #Optional.some!enumelt.1, %2 : $C & PAnyObject
400+
br bb3(%3 : $Optional<C & PAnyObject>)
401+
402+
bb2:
403+
strong_release %0 : $PAnyObject
404+
%6 = enum $Optional<C & PAnyObject>, #Optional.none!enumelt
405+
br bb3(%6 : $Optional<C & PAnyObject>)
406+
407+
bb3(%11 : $Optional<C & PAnyObject>):
408+
return %11 : $Optional<C & PAnyObject>
409+
}

trunk/test/Interpreter/casts.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,23 @@ Casts.test("testConditionalBridgedCastFromSwiftToNSObjectDerivedClass") {
122122
}
123123
expectEqual(0, LifetimeTracked.instances)
124124
}
125+
126+
protocol Q {}
127+
class K { }
128+
class D: Q {}
129+
typealias AnyQ = Q & AnyObject
130+
typealias KQ = K & Q
131+
132+
Casts.test("testCastProtocolCompoWithAnyObjectToProtocolCompoTypeSuperclass") {
133+
let shouldBeNil = (D() as AnyQ) as? KQ
134+
expectNil(shouldBeNil)
135+
}
136+
137+
protocol QAny: AnyObject {}
138+
typealias KQAny = K & QAny
139+
class F: QAny {}
140+
141+
Casts.test("testCastProtocolWithAnyObjectToProtocolCompoTypeSuperclass") {
142+
let shouldBeNil = (F() as QAny) as? KQAny
143+
expectNil(shouldBeNil)
144+
}

trunk/test/SILOptimizer/dead_store_elim.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,29 @@ bb3:
291291
return %9999 : $()
292292
}
293293

294+
// CHECK-LABEL: sil @handle_unreachable : $@convention(thin) (@inout Builtin.Int32) -> () {
295+
// CHECK: bb0
296+
// CHECK-NEXT: integer_literal
297+
// CHECK-NEXT: cond_br
298+
// CHECK: return
299+
sil @handle_unreachable : $@convention(thin) (@inout Builtin.Int32) -> () {
300+
bb0(%0 : $*Builtin.Int32):
301+
%1 = integer_literal $Builtin.Int32, 0
302+
store %1 to %0 : $*Builtin.Int32
303+
cond_br undef, bb1, bb2
304+
305+
bb1:
306+
unreachable
307+
308+
bb2:
309+
br bb3
310+
311+
bb3:
312+
store %1 to %0 : $*Builtin.Int32
313+
%9999 = tuple()
314+
return %9999 : $()
315+
}
316+
294317
// CHECK-LABEL: sil @post_dominating_dead_store_partial : $@convention(thin) (@inout Builtin.Int32) -> () {
295318
// CHECK: bb0(
296319
// CHECK-NOT: {{ store}}

0 commit comments

Comments
 (0)