Skip to content

Commit 1e7064e

Browse files
committed
---
yaml --- r: 293791 b: refs/heads/tensorflow c: 28adf81 h: refs/heads/master i: 293789: 20377bd 293787: 935d327 293783: 20ddc5c 293775: 50dd1eb 293759: d1893ee
1 parent e96c330 commit 1e7064e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+227
-347
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: b6d036220412d72b4a0fbbdffb1d65b937196fcb
819+
refs/heads/tensorflow: 28adf81af15ddc7a23c2e70e81f7b00a5a30bb3c
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/benchmark/single-source/Breadcrumbs.swift

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,6 @@ extension String {
4545
}
4646
}
4747

48-
let seed = 0x12345678
49-
50-
/// A linear congruential PRNG.
51-
struct LCRNG: RandomNumberGenerator {
52-
private var state: UInt64
53-
54-
init(seed: Int) {
55-
state = UInt64(truncatingIfNeeded: seed)
56-
for _ in 0..<10 { _ = next() }
57-
}
58-
59-
mutating func next() -> UInt64 {
60-
state = 2862933555777941757 &* state &+ 3037000493
61-
return state
62-
}
63-
}
64-
6548
extension Collection {
6649
/// Returns a randomly ordered array of random non-overlapping index ranges
6750
/// that cover this collection entirely.
@@ -254,7 +237,7 @@ class UTF16ToIdx: BenchmarkBase {
254237

255238
override func setUp() {
256239
super.setUp()
257-
var rng = LCRNG(seed: seed)
240+
var rng = SplitMix64(seed: 42)
258241
let range = 0 ..< inputString.utf16.count
259242
inputOffsets = Array(range.shuffled(using: &rng).prefix(count))
260243
}
@@ -286,7 +269,7 @@ class IdxToUTF16: BenchmarkBase {
286269

287270
override func setUp() {
288271
super.setUp()
289-
var rng = LCRNG(seed: seed)
272+
var rng = SplitMix64(seed: 42)
290273
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
291274
}
292275

@@ -318,7 +301,7 @@ class UTF16ToIdxRange: BenchmarkBase {
318301

319302
override func setUp() {
320303
super.setUp()
321-
var rng = LCRNG(seed: seed)
304+
var rng = SplitMix64(seed: 42)
322305
inputOffsets = (
323306
0 ..< inputString.utf16.count
324307
).randomIndexRanges(count: count, using: &rng)
@@ -352,7 +335,7 @@ class IdxToUTF16Range: BenchmarkBase {
352335

353336
override func setUp() {
354337
super.setUp()
355-
var rng = LCRNG(seed: seed)
338+
var rng = SplitMix64(seed: 42)
356339
inputIndices = self.inputString.randomIndexRanges(count: count, using: &rng)
357340
}
358341

@@ -384,7 +367,7 @@ class CopyUTF16CodeUnits: BenchmarkBase {
384367

385368
override func setUp() {
386369
super.setUp()
387-
var rng = LCRNG(seed: seed)
370+
var rng = SplitMix64(seed: 42)
388371
inputIndices = (
389372
0 ..< inputString.utf16.count
390373
).randomIndexRanges(count: count, using: &rng)
@@ -425,7 +408,7 @@ class MutatedUTF16ToIdx: BenchmarkBase {
425408

426409
override func setUp() {
427410
super.setUp()
428-
var generator = LCRNG(seed: seed)
411+
var generator = SplitMix64(seed: 42)
429412
let range = 0 ..< inputString.utf16.count
430413
inputOffsets = Array(range.shuffled(using: &generator).prefix(count))
431414
}
@@ -469,7 +452,7 @@ class MutatedIdxToUTF16: BenchmarkBase {
469452

470453
override func setUp() {
471454
super.setUp()
472-
var rng = LCRNG(seed: seed)
455+
var rng = SplitMix64(seed: 42)
473456
inputIndices = Array(inputString.indices.shuffled(using: &rng).prefix(count))
474457
}
475458

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- BucketSort.swift -------------------------------------------------===//
1+
//===--- BucketSort.swift ----------------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -9,21 +9,21 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
// This benchmark demonstrates the benefits of ExistentialSpecializer
13-
// optimization pass. It's a generic version of the classic BucketSort algorithm
14-
// adapted from an original implementation from the Swift Algorithm Club.
15-
// See https://en.wikipedia.org/wiki/Bucket_sort and
12+
// Adapted from the original implementation:
1613
// https://github.com/raywenderlich/swift-algorithm-club/tree/master/Bucket%20Sort
17-
//
18-
// It sorts an array of generic `SortableItem`s. If the type of `sortingAlgo`
19-
// is not known to the call site at line 90, the `sort` method can not be
20-
// specialized to integer array sorting, which will lead to a huge performance
21-
// loss. Since `SortingAlgorithm` and `InsertionSort` are declared to be
22-
// `public` and the lines 89-91 can not be inlined in `bucketSort` (due to
23-
// inlining heuristic limitations), compiler without ExistentialSpecializer
24-
// optimization can not achieve this feat. With ExistentialSpecializer which
25-
// enables generic specialization recursively in a call chain, we're able to
26-
// specialize line 90 for `InsertionSort` on integers.
14+
// Issue: https://github.com/raywenderlich/swift-algorithm-club/issues/863
15+
16+
// This benchmark implements the classical BucketSort algorithm described at
17+
// https://en.wikipedia.org/wiki/Bucket_sort. The implementation allows for an
18+
// array of generic type of "SortableItem" to be sorted. Unfortunately, if
19+
// ``sortingAlgo'' type is not known for the callsite in line 84, then the
20+
// ``sort'' method can not be specialized to integer array sorting, which will
21+
// lead to a huge performance loss. Since SortingAlgorithm and InsertionSort are
22+
// declared to be ``public'' and that lines 83-85 can not be inlined in
23+
// BucketSortImpl (due to inlining heuristic limitations), today swift
24+
// compiler (without ExistentialSpecializer) can not achieve this feat. With
25+
// ExistentialSpecializer which enables generic specialization recursively in a
26+
// call chain, we are able to specialize line 84 for InsertionSort on integers.
2727

2828
import TestsUtils
2929
import Foundation
@@ -32,25 +32,21 @@ public let BucketSort = BenchmarkInfo(
3232
name: "BucketSort",
3333
runFunction: run_BucketSort,
3434
tags: [.validation, .algorithm],
35-
setUpFunction: { blackHole(buckets) }
36-
)
35+
setUpFunction: { buildWorkload() },
36+
legacyFactor: 10)
3737

3838
public protocol IntegerConvertible {
3939
func convertToInt() -> Int
4040
}
41-
4241
extension Int: IntegerConvertible, SortableItem {
4342
public func convertToInt() -> Int {
4443
return self
4544
}
4645
}
47-
4846
public protocol SortableItem: IntegerConvertible, Comparable { }
49-
5047
public protocol SortingAlgorithm {
5148
func sort<T: SortableItem>(_ items: [T]) -> [T]
5249
}
53-
5450
public struct InsertionSort: SortingAlgorithm {
5551
public func sort<T: SortableItem>(_ items: [T]) -> [T] {
5652
var sortedItems = items
@@ -66,14 +62,12 @@ public struct InsertionSort: SortingAlgorithm {
6662
return sortedItems
6763
}
6864
}
69-
7065
func distribute<T>(_ item: T, bucketArray: inout [Bucket<T>]) {
7166
let val = item.convertToInt()
7267
let capacity = bucketArray.first!.capacity
7368
let index = val / capacity
7469
bucketArray[index].add(item)
7570
}
76-
7771
struct Bucket<T: SortableItem> {
7872
var items: [T]
7973
let capacity: Int
@@ -90,10 +84,7 @@ struct Bucket<T: SortableItem> {
9084
return sortingAlgo.sort(items)
9185
}
9286
}
93-
94-
func bucketSort<T>(
95-
_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]
96-
) -> [T] {
87+
func BucketSortImpl<T>(_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]) -> [T] {
9788
var copyBucketArray = bucketArray
9889
for item in items {
9990
distribute(item, bucketArray: &copyBucketArray)
@@ -104,28 +95,45 @@ func bucketSort<T>(
10495
}
10596
return sortedArray
10697
}
107-
108-
func isAscending(_ a: [Int]) -> Bool {
109-
return zip(a, a.dropFirst()).allSatisfy(<=)
98+
func isArraySorted(_ arr: [Int]) -> Bool {
99+
var idx = 0
100+
while idx < (arr.count - 1) {
101+
if arr[idx] > arr[idx+1] {
102+
return false
103+
}
104+
idx += 1
105+
}
106+
return true
110107
}
111-
108+
let NUMITEMS = 2500
109+
let MAXBUCKETSIZE = 1000
110+
let NUMBUCKETS: Int = 10
112111
let items: [Int] = {
113-
var g = SplitMix64(seed: 42)
114-
return (0..<10_000).map {_ in Int.random(in: 0..<1000, using: &g) }
112+
var array: [Int]? = [Int]()
113+
for _ in 0..<NUMITEMS {
114+
array!.append(Int.random(in: 0..<MAXBUCKETSIZE))
115+
}
116+
return array!
115117
}()
116118

117119
let buckets: [Bucket<Int>] = {
118-
let bucketCount = 10
119-
let maxValue = items.max()!.convertToInt()
120-
let maxCapacity = Int(ceil(Double(maxValue + 1) / Double(bucketCount)))
121-
return (0..<bucketCount).map { _ in Bucket<Int>(capacity: maxCapacity) }
120+
let val = (items.max()?.convertToInt())! + 1
121+
let maxCapacity = Int( ceil( Double(val) / Double(NUMBUCKETS)))
122+
var bucketArray = [Bucket<Int>]()
123+
for _ in 0..<NUMBUCKETS {
124+
bucketArray.append(Bucket<Int>(capacity: maxCapacity))
125+
}
126+
return bucketArray
122127
}()
123-
124128
@inline(never)
125129
func run_BucketSort(_ N : Int) {
126130
for _ in 0..<N {
127-
let sortedArray = bucketSort(
128-
items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
129-
CheckResults(isAscending(sortedArray))
131+
let sortedArray = BucketSortImpl(items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
132+
CheckResults(isArraySorted(sortedArray))
130133
}
131134
}
135+
@inline(never)
136+
func buildWorkload() {
137+
blackHole(items)
138+
blackHole(buckets)
139+
}

branches/tensorflow/benchmark/single-source/ObjectiveCBridging.swift

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ public let ObjectiveCBridging = [
7373
BenchmarkInfo(name: "ObjectiveCBridgeFromNSDateComponents",
7474
runFunction: run_ObjectiveCBridgeFromNSDateComponents, tags: t,
7575
setUpFunction: setup_dateComponents),
76-
BenchmarkInfo(name: "ObjectiveCBridgeASCIIStringFromFile",
77-
runFunction: run_ASCIIStringFromFile, tags: ts,
78-
setUpFunction: setup_ASCIIStringFromFile),
7976
]
8077

8178
#if _runtime(_ObjC)
@@ -712,35 +709,3 @@ public func run_ObjectiveCBridgeFromNSDateComponents(_ N: Int) {
712709
}
713710
#endif
714711
}
715-
716-
var ASCIIStringFromFile:String? = nil
717-
public func setup_ASCIIStringFromFile() {
718-
#if _runtime(_ObjC)
719-
let url:URL
720-
if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
721-
url = FileManager.default.temporaryDirectory.appendingPathComponent(
722-
"sphinx.txt"
723-
)
724-
} else {
725-
url = URL(fileURLWithPath: "/tmp/sphinx.txt")
726-
}
727-
var str = "Sphinx of black quartz judge my vow"
728-
str = Array(repeating: str, count: 100).joined()
729-
try? str.write(
730-
to: url,
731-
atomically: true,
732-
encoding: .ascii
733-
)
734-
ASCIIStringFromFile = try! String(contentsOf: url, encoding: .ascii)
735-
#endif
736-
}
737-
738-
@inline(never)
739-
public func run_ASCIIStringFromFile(_ N: Int) {
740-
#if _runtime(_ObjC)
741-
for _ in 0 ..< N {
742-
blackHole((ASCIIStringFromFile! + "").utf8.count)
743-
}
744-
#endif
745-
}
746-

branches/tensorflow/cmake/modules/StandaloneOverlay.cmake

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ endif()
1010

1111
set(CMAKE_INSTALL_PREFIX "${SWIFT_DEST_ROOT}${TOOLCHAIN_DIR}/usr")
1212

13-
set(SWIFT_STDLIB_BUILD_TYPE "Release" CACHE STRING
14-
"Build type for the Swift standard library and SDK overlays [Debug, RelWithDebInfo, Release, MinSizeRel]")
15-
set_property(CACHE SWIFT_STDLIB_BUILD_TYPE PROPERTY
16-
STRINGS "Debug" "RelWithDebInfo" "Release" "MinSizeRel")
17-
1813
# Only happens if it's called from a top-level cmake invocation.
1914
set(BUILD_STANDALONE TRUE)
15+
set(SWIFT_STDLIB_BUILD_TYPE "Release")
2016
set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES "SHARED")
2117
set(SWIFT_INSTALL_COMPONENTS "sdk-overlay" CACHE STRING "")
2218
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_OSX "10.9" CACHE STRING "")

branches/tensorflow/cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function(_compile_swift_files
260260

261261
# Force swift 4 compatibility mode for overlays.
262262
if (SWIFTFILE_IS_SDK_OVERLAY)
263-
list(APPEND swift_flags "-swift-version" "5")
263+
list(APPEND swift_flags "-swift-version" "4")
264264
endif()
265265

266266
if(SWIFTFILE_IS_SDK_OVERLAY)

branches/tensorflow/lib/IRGen/GenEnum.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,6 @@ namespace {
630630
IGF.Builder.CreateCall(
631631
IGF.IGM.getInitEnumMetadataSingleCaseFn(),
632632
{metadata, flags, payloadLayout});
633-
634-
// Pre swift-5.1 runtimes were missing the initialization of the
635-
// the extraInhabitantCount field. Do it here instead.
636-
auto payloadRef = IGF.Builder.CreateBitOrPointerCast(
637-
payloadLayout, IGF.IGM.TypeLayoutTy->getPointerTo());
638-
auto payloadExtraInhabitantCount =
639-
IGF.Builder.CreateLoad(IGF.Builder.CreateStructGEP(
640-
Address(payloadRef, Alignment(1)), 3,
641-
Size(IGF.IGM.DataLayout.getTypeAllocSize(IGF.IGM.SizeTy) * 2 +
642-
IGF.IGM.DataLayout.getTypeAllocSize(IGF.IGM.Int32Ty))));
643-
emitStoreOfExtraInhabitantCount(IGF, payloadExtraInhabitantCount,
644-
metadata);
645633
}
646634

647635
bool mayHaveExtraInhabitants(IRGenModule &IGM) const override {

branches/tensorflow/lib/IRGen/GenOpaque.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,11 @@ llvm::Value *irgen::emitInvariantLoadOfOpaqueWitness(IRGenFunction &IGF,
343343
return witness;
344344
}
345345

346-
static Address emitAddressOfValueWitnessTableValue(IRGenFunction &IGF,
347-
llvm::Value *table,
348-
ValueWitness witness) {
346+
/// Given a value witness table, load one of the value witnesses.
347+
/// The result has the appropriate type for the witness.
348+
static llvm::Value *emitLoadOfValueWitnessValue(IRGenFunction &IGF,
349+
llvm::Value *table,
350+
ValueWitness witness) {
349351
assert(!isValueWitnessFunction(witness));
350352
assert(unsigned(witness) <= unsigned(ValueWitness::ExtraInhabitantCount) &&
351353
"extraInhabitantCount not the last non-function value witness");
@@ -366,15 +368,7 @@ static Address emitAddressOfValueWitnessTableValue(IRGenFunction &IGF,
366368
Address addr = Address(table, IGF.IGM.getPointerAlignment());
367369
addr = IGF.Builder.CreateBitCast(addr, IGF.IGM.getValueWitnessTablePtrTy());
368370
addr = IGF.Builder.CreateStructGEP(addr, unsigned(witness), offset);
369-
return addr;
370-
}
371371

372-
/// Given a value witness table, load one of the value witnesses.
373-
/// The result has the appropriate type for the witness.
374-
static llvm::Value *emitLoadOfValueWitnessValue(IRGenFunction &IGF,
375-
llvm::Value *table,
376-
ValueWitness witness) {
377-
auto addr = emitAddressOfValueWitnessTableValue(IGF, table, witness);
378372
auto load = IGF.Builder.CreateLoad(addr, getValueWitnessLabel(witness));
379373
IGF.setInvariantLoad(load);
380374
return load;
@@ -918,15 +912,6 @@ llvm::Value *irgen::emitLoadOfExtraInhabitantCount(IRGenFunction &IGF,
918912
return IGF.emitValueWitnessValue(T, ValueWitness::ExtraInhabitantCount);
919913
}
920914

921-
void irgen::emitStoreOfExtraInhabitantCount(IRGenFunction &IGF,
922-
llvm::Value *value,
923-
llvm::Value *metadata) {
924-
auto vwTable = IGF.emitValueWitnessTableRefForMetadata(metadata);
925-
auto addr = emitAddressOfValueWitnessTableValue(
926-
IGF, vwTable, ValueWitness::ExtraInhabitantCount);
927-
IGF.Builder.CreateStore(value, addr);
928-
}
929-
930915
std::pair<llvm::Value *, llvm::Value *>
931916
irgen::emitLoadOfIsInline(IRGenFunction &IGF, llvm::Value *metadata) {
932917
auto *flags = emitLoadOfValueWitnessValueFromMetadata(IGF, metadata,

branches/tensorflow/lib/IRGen/GenOpaque.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ namespace irgen {
215215
/// Emit a load of the 'extraInhabitantCount' value witness.
216216
llvm::Value *emitLoadOfExtraInhabitantCount(IRGenFunction &IGF, SILType T);
217217

218-
/// Emit a stored to the 'extraInhabitantCount' value witness.
219-
void emitStoreOfExtraInhabitantCount(IRGenFunction &IGF, llvm::Value *val,
220-
llvm::Value *metadata);
221-
222218
/// Returns the IsInline flag and the loaded flags value.
223219
std::pair<llvm::Value *, llvm::Value *>
224220
emitLoadOfIsInline(IRGenFunction &IGF, llvm::Value *metadata);

0 commit comments

Comments
 (0)