diff --git a/lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp b/lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp index 44da2a6458d8f..d30d9b4ca6691 100644 --- a/lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp +++ b/lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp @@ -13,6 +13,12 @@ #include "swift/SILOptimizer/Utils/PerformanceInlinerUtils.h" #include "swift/AST/Module.h" #include "swift/SILOptimizer/Utils/InstOptUtils.h" +#include "llvm/Support/CommandLine.h" + +llvm::cl::opt + SILInlineNeverFuns("sil-inline-never-functions", llvm::cl::init(""), + llvm::cl::desc("Never inline functions whose name " + "includes this string.")); //===----------------------------------------------------------------------===// // ConstantTracker @@ -687,6 +693,10 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI, return nullptr; } + if (!SILInlineNeverFuns.empty() + && Callee->getName().find(SILInlineNeverFuns, 0) != StringRef::npos) + return nullptr; + if (!Callee->shouldOptimize()) { return nullptr; } diff --git a/test/SILOptimizer/array_contentof_opt.swift b/test/SILOptimizer/array_contentof_opt.swift index aa218c2c6c88f..7d2af225a2a79 100644 --- a/test/SILOptimizer/array_contentof_opt.swift +++ b/test/SILOptimizer/array_contentof_opt.swift @@ -1,7 +1,16 @@ -// RUN: %target-swift-frontend -O -sil-verify-all -emit-sil %s | %FileCheck %s +// RUN: %target-swift-frontend -O -sil-verify-all -emit-sil -Xllvm '-sil-inline-never-functions=$sSa6append' %s | %FileCheck %s // REQUIRES: swift_stdlib_no_asserts,optimized_stdlib -// This is an end-to-end test of the array(contentsOf) -> array(Element) optimization +// This is an end-to-end test of the Array.append(contentsOf:) -> +// Array.append(Element) optimization. +// +// To check that the optimization produces the expected +// Array.append(Element) calls, the CHECK lines match those call +// sites. The optimizer may subsequently inline Array.append(Element), +// which is good, but to keep the test simple and specific to the +// optimization, the RUN line prevents inlining Array.append(Element). +// Likewise, negative tests check for the existence of +// Array.append(contentsOf:), so don't inline those either. // CHECK-LABEL: sil @{{.*}}testInt // CHECK-NOT: apply @@ -22,14 +31,13 @@ public func testInt(_ a: inout [Int]) { // CHECK-DAG: apply [[F]] // CHECK-DAG: apply [[F]] // CHECK: } // end sil function '{{.*}}testThreeInts{{.*}}' - public func testThreeInts(_ a: inout [Int]) { a += [1, 2, 3] } // CHECK-LABEL: sil @{{.*}}testTooManyInts // CHECK-NOT: apply -// CHECK: [[F:%[0-9]+]] = function_ref @$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5Tf4gn_n +// CHECK: [[F:%[0-9]+]] = function_ref @$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5 // CHECK-NOT: apply // CHECK: apply [[F]] // CHECK-NOT: apply @@ -57,7 +65,7 @@ public func dontPropagateContiguousArray(_ a: inout ContiguousArray) { // Check if the specialized Array.append(contentsOf:) is reasonably optimized for Array. -// CHECK-LABEL: sil shared {{.*}}@$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5 +// CHECK-LABEL: sil shared {{.*}}@$sSa6append10contentsOfyqd__n_t7ElementQyd__RszSTRd__lFSi_SaySiGTg5Tf4gn_n // There should only be a single call to _createNewBuffer or reserveCapacityForAppend/reserveCapacityImpl. diff --git a/utils/swift-autocomplete.bash b/utils/swift-autocomplete.bash index 7e48fd7d5fa85..d79094d0c64c4 100644 --- a/utils/swift-autocomplete.bash +++ b/utils/swift-autocomplete.bash @@ -68,6 +68,7 @@ _swift_complete() -sil-verify-without-invalidation \ -sil-inline-test-threshold \ -sil-inline-test \ + -sil-inline-never-functions \ -sroa-args-remove-dead-args-after \ -ml \ -sil-print-escapes \