Skip to content

Commit 75bad90

Browse files
authored
Merge pull request swiftlang#30467 from atrick/add-inline-never
Add -sil-inline-never-functions flag.
2 parents 2df9bb5 + e8d3ee1 commit 75bad90

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#include "swift/SILOptimizer/Utils/PerformanceInlinerUtils.h"
1414
#include "swift/AST/Module.h"
1515
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
16+
#include "llvm/Support/CommandLine.h"
17+
18+
llvm::cl::opt<std::string>
19+
SILInlineNeverFuns("sil-inline-never-functions", llvm::cl::init(""),
20+
llvm::cl::desc("Never inline functions whose name "
21+
"includes this string."));
1622

1723
//===----------------------------------------------------------------------===//
1824
// ConstantTracker
@@ -687,6 +693,10 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
687693
return nullptr;
688694
}
689695

696+
if (!SILInlineNeverFuns.empty()
697+
&& Callee->getName().find(SILInlineNeverFuns, 0) != StringRef::npos)
698+
return nullptr;
699+
690700
if (!Callee->shouldOptimize()) {
691701
return nullptr;
692702
}

test/SILOptimizer/array_contentof_opt.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
// RUN: %target-swift-frontend -O -sil-verify-all -emit-sil %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -O -sil-verify-all -emit-sil -Xllvm '-sil-inline-never-functions=$sSa6append' %s | %FileCheck %s
22
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
33

4-
// This is an end-to-end test of the array(contentsOf) -> array(Element) optimization
4+
// This is an end-to-end test of the Array.append(contentsOf:) ->
5+
// Array.append(Element) optimization.
6+
//
7+
// To check that the optimization produces the expected
8+
// Array.append(Element) calls, the CHECK lines match those call
9+
// sites. The optimizer may subsequently inline Array.append(Element),
10+
// which is good, but to keep the test simple and specific to the
11+
// optimization, the RUN line prevents inlining Array.append(Element).
12+
// Likewise, negative tests check for the existence of
13+
// Array.append(contentsOf:), so don't inline those either.
514

615
// CHECK-LABEL: sil @{{.*}}testInt
716
// CHECK-NOT: apply
@@ -22,14 +31,13 @@ public func testInt(_ a: inout [Int]) {
2231
// CHECK-DAG: apply [[F]]
2332
// CHECK-DAG: apply [[F]]
2433
// CHECK: } // end sil function '{{.*}}testThreeInts{{.*}}'
25-
2634
public func testThreeInts(_ a: inout [Int]) {
2735
a += [1, 2, 3]
2836
}
2937

3038
// CHECK-LABEL: sil @{{.*}}testTooManyInts
3139
// CHECK-NOT: apply
32-
// CHECK: [[F:%[0-9]+]] = function_ref @$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5Tf4gn_n
40+
// CHECK: [[F:%[0-9]+]] = function_ref @$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5
3341
// CHECK-NOT: apply
3442
// CHECK: apply [[F]]
3543
// CHECK-NOT: apply
@@ -57,7 +65,7 @@ public func dontPropagateContiguousArray(_ a: inout ContiguousArray<UInt8>) {
5765

5866
// Check if the specialized Array.append<A>(contentsOf:) is reasonably optimized for Array<Int>.
5967

60-
// CHECK-LABEL: sil shared {{.*}}@$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5
68+
// CHECK-LABEL: sil shared {{.*}}@$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5Tf4gn_n
6169

6270
// There should only be a single call to _createNewBuffer or reserveCapacityForAppend/reserveCapacityImpl.
6371

utils/swift-autocomplete.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ _swift_complete()
6868
-sil-verify-without-invalidation \
6969
-sil-inline-test-threshold \
7070
-sil-inline-test \
71+
-sil-inline-never-functions \
7172
-sroa-args-remove-dead-args-after \
7273
-ml \
7374
-sil-print-escapes \

0 commit comments

Comments
 (0)