Optimizer: Replace the MandatoryCombine pass with a Simplification pass, which is implemented in Swift

The Swift Simplification pass can do more than the old MandatoryCombine pass: simplification of more instruction types and dead code elimination.
The result is a better -Onone performance while still keeping debug info consistent.

Currently following code patterns are simplified:
* `struct` -> `struct_extract`
* `enum` -> `unchecked_enum_data`
* `partial_apply` -> `apply`
* `br` to a 1:1 related block
* `cond_br` with a constant condition
* `isConcrete` and `is_same_metadata` builtins

More simplifications can be added in the future.

rdar://96708429
rdar://104562580
This commit is contained in:
Erik Eckstein
2023-02-07 16:15:27 +01:00
parent 85210a4e91
commit d25b1ed834
60 changed files with 164 additions and 546 deletions

View File

@@ -434,10 +434,6 @@ PASS(YieldOnceCheck, "yield-once-check",
PASS(OSLogOptimization, "os-log-optimization", "Optimize os log calls")
PASS(ForEachLoopUnroll, "for-each-loop-unroll",
"Unroll forEach loops over array literals")
PASS(MandatoryCombine, "mandatory-combine",
"Perform mandatory peephole combines")
PASS(OptimizedMandatoryCombine, "optimized-mandatory-combine",
"Perform -O level mandatory peephole combines")
PASS(BugReducerTester, "bug-reducer-tester",
"sil-bug-reducer Tool Testing by Asserting on a Sentinel Function")
PASS(AssemblyVisionRemarkGenerator, "assembly-vision-remark-generator",

View File

@@ -38,7 +38,6 @@ target_sources(swiftSILOptimizer PRIVATE
RawSILInstLowering.cpp
SILGenCleanup.cpp
YieldOnceCheck.cpp
MandatoryCombine.cpp
OSLogOptimization.cpp
MoveOnlyWrappedTypeEliminator.cpp
OwnershipModelEliminator.cpp)

View File

@@ -1,416 +0,0 @@
//===------- MandatoryCombiner.cpp ----------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file
///
/// Defines the MandatoryCombiner function transform. The pass contains basic
/// instruction combines to be performed at the beginning of both the Onone and
/// also the performance pass pipelines, after the diagnostics passes have been
/// run. It is intended to be run before and to be independent of other
/// transforms.
///
/// The intention of this pass is to be a place for mandatory peepholes that
/// are not needed for diagnostics. Please put any such peepholes here instead
/// of in the diagnostic passes.
///
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "sil-mandatory-combiner"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/STLExtras.h"
#include "swift/SIL/BasicBlockUtils.h"
#include "swift/SIL/SILInstructionWorklist.h"
#include "swift/SIL/SILVisitor.h"
#include "swift/SIL/BasicBlockDatastructures.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"
#include "swift/SILOptimizer/Utils/CanonicalizeInstruction.h"
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
#include "swift/SILOptimizer/Utils/StackNesting.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace swift;
//===----------------------------------------------------------------------===//
// Utility
//===----------------------------------------------------------------------===//
/// \returns whether all the values are of trivial type in the provided
/// function.
template <typename Values>
static bool areAllValuesTrivial(Values values, SILFunction &function) {
return llvm::all_of(values, [&](SILValue value) -> bool {
return value->getType().isTrivial(function);
});
}
//===----------------------------------------------------------------------===//
// CanonicalizeInstruction subclass for use in Mandatory Combiner.
//===----------------------------------------------------------------------===//
namespace {
class MandatoryCombineCanonicalize final : CanonicalizeInstruction {
public:
using Worklist = SmallSILInstructionWorklist<256>;
private:
Worklist &worklist;
bool changed = false;
public:
MandatoryCombineCanonicalize(Worklist &worklist, DeadEndBlocks &deadEndBlocks)
: CanonicalizeInstruction(DEBUG_TYPE, deadEndBlocks), worklist(worklist) {
}
void notifyNewInstruction(SILInstruction *inst) override {
worklist.add(inst);
worklist.addUsersOfAllResultsToWorklist(inst);
changed = true;
}
// Just delete the given 'inst' and record its operands. The callback isn't
// allowed to mutate any other instructions.
void killInstruction(SILInstruction *inst) override {
worklist.eraseSingleInstFromFunction(*inst,
/*AddOperandsToWorklist*/ true);
changed = true;
}
void notifyHasNewUsers(SILValue value) override {
if (worklist.size() < 10000) {
worklist.addUsersToWorklist(value);
}
changed = true;
}
bool tryCanonicalize(SILInstruction *inst) {
changed = false;
canonicalize(inst);
return changed;
}
};
} // anonymous namespace
//===----------------------------------------------------------------------===//
// MandatoryCombiner Interface
//===----------------------------------------------------------------------===//
namespace {
class MandatoryCombiner final
: public SILInstructionVisitor<MandatoryCombiner, SILInstruction *> {
bool compilingWithOptimization;
using Worklist = SmallSILInstructionWorklist<256>;
/// The list of instructions remaining to visit, perhaps to combine.
Worklist worklist;
/// Whether any changes have been made.
bool madeChange;
/// Set to true if some alloc/dealloc_stack instruction are inserted and at
/// the end of the run stack nesting needs to be corrected.
bool invalidatedStackNesting = false;
/// The number of times that the worklist has been processed.
unsigned iteration;
InstModCallbacks instModCallbacks;
SmallVectorImpl<SILInstruction *> &createdInstructions;
SmallVector<SILInstruction *, 16> instructionsPendingDeletion;
DeadEndBlocks &deadEndBlocks;
public:
MandatoryCombiner(bool optimized,
SmallVectorImpl<SILInstruction *> &createdInstructions,
DeadEndBlocks &deadEndBlocks)
: compilingWithOptimization(optimized), worklist("MC"), madeChange(false),
iteration(0),
instModCallbacks(),
createdInstructions(createdInstructions),
deadEndBlocks(deadEndBlocks) {
instModCallbacks = InstModCallbacks()
.onDelete([&](SILInstruction *instruction) {
worklist.erase(instruction);
instructionsPendingDeletion.push_back(instruction);
})
.onCreateNewInst([&](SILInstruction *instruction) {
worklist.add(instruction);
})
.onSetUseValue([this](Operand *use, SILValue newValue) {
use->set(newValue);
worklist.add(use->getUser());
});
};
void addReachableCodeToWorklist(SILFunction &function);
/// \return whether a change was made.
bool doOneIteration(SILFunction &function, unsigned iteration);
void clear() {
iteration = 0;
worklist.resetChecked();
madeChange = false;
}
/// Applies the MandatoryCombiner to the provided function.
///
/// \param function the function to which to apply the MandatoryCombiner.
///
/// \return whether a change was made.
bool runOnFunction(SILFunction &function) {
bool changed = false;
while (doOneIteration(function, iteration)) {
changed = true;
++iteration;
}
if (invalidatedStackNesting) {
StackNesting::fixNesting(&function);
}
return changed;
}
/// Base visitor that does not do anything.
SILInstruction *visitSILInstruction(SILInstruction *) { return nullptr; }
SILInstruction *visitApplyInst(ApplyInst *instruction);
};
} // end anonymous namespace
//===----------------------------------------------------------------------===//
// MandatoryCombiner Non-Visitor Utility Methods
//===----------------------------------------------------------------------===//
static llvm::cl::opt<bool> EnableCanonicalizationAndTrivialDCE(
"sil-mandatory-combine-enable-canon-and-simple-dce", llvm::cl::Hidden,
llvm::cl::init(false),
llvm::cl::desc("An option for compiler developers that cause the Mandatory "
"Combiner to be more aggressive at eliminating trivially "
"dead code and canonicalizing SIL"));
void MandatoryCombiner::addReachableCodeToWorklist(SILFunction &function) {
BasicBlockWorklist blockWorklist(function.getEntryBlock());
SmallVector<SILInstruction *, 128> initialInstructionWorklist;
while (SILBasicBlock *block = blockWorklist.pop()) {
for (auto iterator = block->begin(), end = block->end(); iterator != end;) {
auto *instruction = &*iterator;
++iterator;
if (isInstructionTriviallyDead(instruction)) {
if (EnableCanonicalizationAndTrivialDCE) {
if (compilingWithOptimization) {
instruction->replaceAllUsesOfAllResultsWithUndef();
instruction->eraseFromParent();
}
}
continue;
}
initialInstructionWorklist.push_back(instruction);
}
for (SILBasicBlock *succ : block->getSuccessors()) {
blockWorklist.pushIfNotVisited(succ);
}
}
worklist.addInitialGroup(initialInstructionWorklist);
}
bool MandatoryCombiner::doOneIteration(SILFunction &function,
unsigned iteration) {
madeChange = false;
addReachableCodeToWorklist(function);
MandatoryCombineCanonicalize mcCanonicalize(worklist, deadEndBlocks);
while (!worklist.isEmpty()) {
auto *instruction = worklist.pop_back_val();
if (instruction == nullptr) {
continue;
}
if (EnableCanonicalizationAndTrivialDCE) {
if (compilingWithOptimization) {
if (isInstructionTriviallyDead(instruction)) {
worklist.eraseInstFromFunction(*instruction);
madeChange = true;
continue;
}
}
if (mcCanonicalize.tryCanonicalize(instruction)) {
madeChange = true;
continue;
}
}
#ifndef NDEBUG
std::string instructionDescription;
#endif
LLVM_DEBUG(llvm::raw_string_ostream SS(instructionDescription);
instruction->print(SS); instructionDescription = SS.str(););
LLVM_DEBUG(llvm::dbgs()
<< "MC: Visiting: " << instructionDescription << '\n');
if (auto replacement = visit(instruction)) {
worklist.replaceInstructionWithInstruction(instruction, replacement
#ifndef NDEBUG
,
instructionDescription
#endif
);
madeChange = true;
}
for (SILInstruction *instruction : instructionsPendingDeletion) {
worklist.eraseInstFromFunction(*instruction);
madeChange = true;
}
instructionsPendingDeletion.clear();
// Our tracking list has been accumulating instructions created by the
// SILBuilder during this iteration. Go through the tracking list and add
// its contents to the worklist and then clear said list in preparation
// for the next iteration.
for (SILInstruction *instruction : createdInstructions) {
if (instruction->isDeleted())
continue;
LLVM_DEBUG(llvm::dbgs() << "MC: add " << *instruction
<< " from tracking list to worklist\n");
worklist.add(instruction);
madeChange = true;
}
createdInstructions.clear();
}
worklist.resetChecked();
return madeChange;
}
//===----------------------------------------------------------------------===//
// MandatoryCombiner Visitor Methods
//===----------------------------------------------------------------------===//
SILInstruction *MandatoryCombiner::visitApplyInst(ApplyInst *instruction) {
// Apply this pass only to partial applies all of whose arguments are
// trivial.
auto calledValue = instruction->getCallee();
if (calledValue == nullptr) {
return nullptr;
}
auto fullApplyCallee = calledValue->getDefiningInstruction();
if (fullApplyCallee == nullptr) {
return nullptr;
}
auto partialApply = dyn_cast<PartialApplyInst>(fullApplyCallee);
if (partialApply == nullptr) {
return nullptr;
}
auto *function = partialApply->getCalleeFunction();
if (function == nullptr) {
return nullptr;
}
ApplySite fullApplySite(instruction);
auto fullApplyArguments = fullApplySite.getArguments();
if (!areAllValuesTrivial(fullApplyArguments, *function)) {
return nullptr;
}
auto partialApplyArguments = ApplySite(partialApply).getArguments();
if (!areAllValuesTrivial(partialApplyArguments, *function)) {
return nullptr;
}
auto callee = partialApply->getCallee();
ApplySite partialApplySite(partialApply);
SmallVector<SILValue, 8> argsVec;
llvm::copy(fullApplyArguments, std::back_inserter(argsVec));
llvm::copy(partialApplyArguments, std::back_inserter(argsVec));
SILBuilderWithScope builder(instruction, &createdInstructions);
ApplyInst *replacement = builder.createApply(
/*Loc=*/instruction->getDebugLocation().getLocation(), /*Fn=*/callee,
/*Subs=*/partialApply->getSubstitutionMap(),
/*Args*/ argsVec,
/*isNonThrowing=*/instruction->getApplyOptions(),
/*SpecializationInfo=*/partialApply->getSpecializationInfo());
worklist.replaceInstructionWithInstruction(instruction, replacement
#ifndef NDEBUG
,
/*instructionDescription=*/""
#endif
);
if (tryDeleteDeadClosure(partialApply, instModCallbacks)) {
invalidatedStackNesting = true;
}
return nullptr;
}
//===----------------------------------------------------------------------===//
// Top Level Entrypoint
//===----------------------------------------------------------------------===//
namespace {
class MandatoryCombine final : public SILFunctionTransform {
bool optimized;
SmallVector<SILInstruction *, 64> createdInstructions;
public:
MandatoryCombine(bool optimized) : optimized(optimized) {}
void run() override {
auto *function = getFunction();
// If this function is an external declaration, bail. We only want to visit
// functions with bodies.
if (function->isExternalDeclaration()) {
return;
}
DeadEndBlocks deadEndBlocks(function);
MandatoryCombiner combiner(optimized, createdInstructions, deadEndBlocks);
bool madeChange = combiner.runOnFunction(*function);
if (madeChange) {
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
}
}
};
} // end anonymous namespace
SILTransform *swift::createMandatoryCombine() {
return new MandatoryCombine(/*optimized*/ false);
}
SILTransform *swift::createOptimizedMandatoryCombine() {
return new MandatoryCombine(/*optimized*/ true);
}

View File

@@ -572,7 +572,7 @@ static void addPrepareOptimizationsPipeline(SILPassPipelinePlan &P) {
#endif
P.addForEachLoopUnroll();
P.addOptimizedMandatoryCombine();
P.addSimplification();
P.addAccessMarkerElimination();
}
@@ -971,7 +971,7 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
// in the editor.
P.startPipeline("Non-Diagnostic Mandatory Optimizations");
P.addForEachLoopUnroll();
P.addMandatoryCombine();
P.addOnoneSimplification();
// TODO: MandatoryARCOpts should be subsumed by CopyPropagation. There should
// be no need to run another analysis of copies at -Onone.
@@ -1011,6 +1011,12 @@ SILPassPipelinePlan::getOnonePassPipeline(const SILOptions &Options) {
// In Onone builds, do a function-local analysis in a function pass.
P.addFunctionStackProtection();
// This is mainly there to optimize `Builtin.isConcrete`, which must not be
// constant folded before any generic specialization.
P.addLateOnoneSimplification();
P.addCleanupDebugSteps();
// Has only an effect if the -sil-based-debuginfo option is specified.
P.addSILDebugInfoGenerator();

View File

@@ -15,7 +15,7 @@
// IRGen test.
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=Simplification -emit-ir %s | %FileCheck %s --check-prefix=IRGEN --check-prefix %target-cpu
// NOTE: `%target-cpu`-specific FileCheck lines exist because lowered function types in LLVM IR differ between architectures.
// `shell` is required only to run `sed` as a

View File

@@ -23,7 +23,7 @@ func basic(_ x: Float) -> Float { x }
@_silgen_name("test_differentiable_function")
func testDifferentiableFunction() {
let _: @differentiable(reverse) (Float) -> Float = basic
let a: @differentiable(reverse) (Float) -> Float = basic
}
// CHECK-SILGEN-LABEL: sil hidden [ossa] @test_differentiable_function : $@convention(thin) () -> () {

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xllvm -sil-print-debuginfo -emit-sil %s | %FileCheck %s
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xllvm -sil-disable-pass=Simplification -Xllvm -sil-print-debuginfo -emit-sil %s | %FileCheck %s
import macros

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-sil -verify -Xllvm -sil-disable-pass=simplification %s | %FileCheck %s
struct Point {
let x: Int

View File

@@ -4,6 +4,8 @@
// REQUIRES: concurrency
// REQUIRES: distributed
// REQUIRES: swift_in_compiler
/// The convention in this test is that the Swift declaration comes before its FileCheck lines.
import Distributed
@@ -37,16 +39,13 @@ distributed actor MyDistActor {
// CHECK: hop_to_executor {{%[0-9]+}}
// CHECK: [[READY_FN:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0aC6SystemV10actorReadyyyx0B00bC0RzAA0C7AddressV2IDRtzlF : $@convention(method) <τ_0_0 where τ_0_0 : DistributedActor, τ_0_0.ID == ActorAddress> (@guaranteed τ_0_0, @guaranteed FakeActorSystem) -> ()
// CHECK: = apply [[READY_FN]]
// CHECK: br [[RET_BB:bb[0-9]+]]
// CHECK: return
// CHECK: [[FAIL_BB]]:
// CHECK: [[RESIGN_FN:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0aC6SystemV8resignIDyyAA0C7AddressVF : $@convention(method) (@guaranteed ActorAddress, @guaranteed FakeActorSystem) -> ()
// CHECK: = apply [[RESIGN_FN]]
// CHECK: builtin "destroyDefaultActor"
// CHECK: throw {{%[0-9]+}} : $any Error
// CHECK: [[RET_BB]]:
// CHECK: return
// CHECK: } // end sil function '$s14default_deinit11MyDistActorC24system_async_fail_throws4condACSg015FakeDistributedE7Systems0kE6SystemV_SbtYaKcfc'
}

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-ir -parse-sil %s -parse-stdlib | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir -parse-sil %s -parse-stdlib -Xllvm -sil-disable-pass=simplification | %FileCheck %s
import Builtin
import Swift

View File

@@ -1,7 +1,7 @@
// #if directives don't work with SIL keywords, therefore please put ObjC tests
// in `enum_objc.sil`.
// RUN: %target-swift-frontend %s -disable-type-layout -disable-generic-metadata-prespecialization -disable-generic-metadata-prespecialization -gnone -emit-ir -disable-diagnostic-passes -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-objc --check-prefix=CHECK-objc-%target-ptrsize --check-prefix=CHECK-objc-%target-ptrsize-simulator-%target-is-simulator -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend %s -disable-type-layout -disable-generic-metadata-prespecialization -gnone -emit-ir -disable-diagnostic-passes -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-native --check-prefix=CHECK-native-%target-ptrsize -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend %s -Xllvm -sil-disable-pass=simplification -disable-type-layout -disable-generic-metadata-prespecialization -disable-generic-metadata-prespecialization -gnone -emit-ir -disable-diagnostic-passes -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-objc --check-prefix=CHECK-objc-%target-ptrsize --check-prefix=CHECK-objc-%target-ptrsize-simulator-%target-is-simulator -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend %s -Xllvm -sil-disable-pass=simplification -disable-type-layout -disable-generic-metadata-prespecialization -gnone -emit-ir -disable-diagnostic-passes -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-native --check-prefix=CHECK-native-%target-ptrsize -DWORD=i%target-ptrsize
// REQUIRES: CPU=i386 || CPU=x86_64

View File

@@ -1,7 +1,7 @@
// #if directives don't work with SIL keywords, therefore please put ObjC tests
// in `enum_objc.sil`.
// RUN: %target-swift-frontend -disable-type-layout -prespecialize-generic-metadata %s -target %module-target-future -gnone -emit-ir -disable-diagnostic-passes -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-objc --check-prefix=CHECK-objc-%target-ptrsize --check-prefix=CHECK-objc-%target-ptrsize-simulator-%target-is-simulator -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend -disable-type-layout -prespecialize-generic-metadata %s -target %module-target-future -gnone -emit-ir -disable-diagnostic-passes -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-native --check-prefix=CHECK-native-%target-ptrsize -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend -disable-type-layout -prespecialize-generic-metadata %s -Xllvm -sil-disable-pass=simplification -target %module-target-future -gnone -emit-ir -disable-diagnostic-passes -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-objc --check-prefix=CHECK-objc-%target-ptrsize --check-prefix=CHECK-objc-%target-ptrsize-simulator-%target-is-simulator -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend -disable-type-layout -prespecialize-generic-metadata %s -Xllvm -sil-disable-pass=simplification -target %module-target-future -gnone -emit-ir -disable-diagnostic-passes -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-native --check-prefix=CHECK-native-%target-ptrsize -DWORD=i%target-ptrsize
// REQUIRES: CPU=i386 || CPU=x86_64
// REQUIRES: VENDOR=apple || OS=linux-gnu

View File

@@ -13,20 +13,20 @@ import fixed_layout_class
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16class_resilience20useRootClassPropertyyy013fixed_layout_A0026OutsideParentWithResilientF0CF"(%T18fixed_layout_class34OutsideParentWithResilientPropertyC* %0)
public func useRootClassProperty(_ o: OutsideParentWithResilientProperty) {
// CHECK: getelementptr inbounds %T18fixed_layout_class34OutsideParentWithResilientPropertyC, %T18fixed_layout_class34OutsideParentWithResilientPropertyC* %0, i32 0, i32 1
_ = o.p
let a = o.p
// CHECK: load [[INT]], [[INT]]* @"$s18fixed_layout_class34OutsideParentWithResilientPropertyC1s16resilient_struct4SizeVvpWvd"
_ = o.s
let b = o.s
// CHECK: load [[INT]], [[INT]]* @"$s18fixed_layout_class34OutsideParentWithResilientPropertyC5colors5Int32VvpWvd"
_ = o.color
let c = o.color
// CHECK: ret void
}
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16class_resilience19useSubclassPropertyyy013fixed_layout_A012OutsideChildCF"(%T18fixed_layout_class12OutsideChildC* %0)
public func useSubclassProperty(_ o: OutsideChild) {
// CHECK: getelementptr inbounds %T18fixed_layout_class13OutsideParentC, %T18fixed_layout_class13OutsideParentC* %4, i32 0, i32 1
_ = o.property
// CHECK: getelementptr inbounds %T18fixed_layout_class13OutsideParentC, %T18fixed_layout_class13OutsideParentC* {{%[0-9]+}}, i32 0, i32 1
let a = o.property
// CHECK: getelementptr inbounds %T18fixed_layout_class12OutsideChildC, %T18fixed_layout_class12OutsideChildC* %0, i32 0, i32 2
_ = o.childProperty
let b = o.childProperty
// CHECK: ret void
}
@@ -47,7 +47,7 @@ public func useGenericRootClassProperty<A>(_ o: GenericOutsideParent<A>) {
// CHECK: [[FIELD_OFFSET_ADDR:%.*]] = getelementptr inbounds i8, i8* [[METADATA_ADDR]], [[INT]] [[FIELD_OFFSET_OFFSET]]
// CHECK: [[FIELD_OFFSET_PTR:%.*]] = bitcast i8* [[FIELD_OFFSET_ADDR]] to [[INT]]*
// CHECK: [[FIELD_OFFSET:%.*]] = load [[INT]], [[INT]]* [[FIELD_OFFSET_PTR]]
_ = o.property
let a = o.property
// CHECK: ret void
}
@@ -55,7 +55,7 @@ public func useGenericRootClassProperty<A>(_ o: GenericOutsideParent<A>) {
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s16class_resilience27useGenericRootClassPropertyyy013fixed_layout_A00D13OutsideParentCySiGF"(%T18fixed_layout_class20GenericOutsideParentCySiG* %0)
public func useGenericRootClassProperty(_ o: GenericOutsideParent<Int>) {
// CHECK: getelementptr inbounds %T18fixed_layout_class20GenericOutsideParentCySiG, %T18fixed_layout_class20GenericOutsideParentCySiG* %0, i32 0, i32 1
_ = o.property
let a = o.property
// CHECK: ret void
}
@@ -78,7 +78,7 @@ public func useGenericSubclassProperty<A>(_ o: GenericOutsideChild<A>) {
// CHECK: [[FIELD_OFFSET_ADDR:%.*]] = getelementptr inbounds i8, i8* [[METADATA_ADDR]], [[INT]] [[FIELD_OFFSET_OFFSET]]
// CHECK: [[FIELD_OFFSET_PTR:%.*]] = bitcast i8* [[FIELD_OFFSET_ADDR]] to [[INT]]*
// CHECK: [[FIELD_OFFSET:%.*]] = load [[INT]], [[INT]]* [[FIELD_OFFSET_PTR]]
_ = o.property
let a = o.property
// CHECK: [[METADATA_ADDR:%.*]] = bitcast %T18fixed_layout_class19GenericOutsideChildC* %0 to %swift.type**
// CHECK: [[METADATA:%.*]] = load %swift.type*, %swift.type** [[METADATA_ADDR]]
@@ -90,7 +90,7 @@ public func useGenericSubclassProperty<A>(_ o: GenericOutsideChild<A>) {
// CHECK: [[FIELD_OFFSET_ADDR:%.*]] = getelementptr inbounds i8, i8* [[METADATA_ADDR]], [[INT]] [[FIELD_OFFSET_OFFSET]]
// CHECK: [[FIELD_OFFSET_PTR:%.*]] = bitcast i8* [[FIELD_OFFSET_ADDR]] to [[INT]]*
// CHECK: [[FIELD_OFFSET:%.*]] = load [[INT]], [[INT]]* [[FIELD_OFFSET_PTR]]
_ = o.childProperty
let b = o.childProperty
// CHECK: ret void
}
@@ -99,10 +99,10 @@ public func useGenericSubclassProperty<A>(_ o: GenericOutsideChild<A>) {
public func useGenericSubclassProperty(_ o: GenericOutsideChild<Int>) {
// CHECK: [[UPCAST:%.*]] = bitcast %T18fixed_layout_class19GenericOutsideChildCySiG* %0 to %T18fixed_layout_class20GenericOutsideParentCySiG*
// CHECK: getelementptr inbounds %T18fixed_layout_class20GenericOutsideParentCySiG, %T18fixed_layout_class20GenericOutsideParentCySiG* [[UPCAST]], i32 0, i32 1
_ = o.property
let a = o.property
// CHECK: getelementptr inbounds %T18fixed_layout_class19GenericOutsideChildCySiG, %T18fixed_layout_class19GenericOutsideChildCySiG* %0, i32 0, i32 2
_ = o.childProperty
let b = o.childProperty
// CHECK: ret void
}
@@ -112,7 +112,7 @@ public func callVirtualMethod(_ o: OutsideParent) {
// Note: virtual method calls still use dispatch thunks
// CHECK: call swiftcc void @"$s18fixed_layout_class13OutsideParentC6methodyyFTj"
_ = o.method()
let a = o.method()
// CHECK: ret void
}

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -disable-generic-metadata-prespecialization -I %S/Inputs/abi %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -disable-generic-metadata-prespecialization -I %S/Inputs/abi %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize
sil_stage canonical
import c_layout

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -prespecialize-generic-metadata -target %module-target-future -I %S/Inputs/abi %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -prespecialize-generic-metadata -target %module-target-future -I %S/Inputs/abi %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize
// REQUIRES: VENDOR=apple || OS=linux-gnu
// UNSUPPORTED: CPU=i386 && OS=ios

View File

@@ -1,8 +1,8 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/../Inputs/resilient_struct.swift -enable-library-evolution -emit-module -emit-module-path %t/resilient_struct.swiftmodule
// RUN: %target-swift-frontend -enable-library-evolution -I %t -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -enable-library-evolution -I %t -emit-ir -O %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-library-evolution -I %t -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-library-evolution -I %t -emit-ir -O %s
// CHECK: %swift.type = type { [[INT:i32|i64]] }

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend %s -Xllvm -sil-disable-pass=simplification -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=MandatoryCombine %s -emit-ir | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-ptrsize %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=OnoneSimplification %s -emit-ir | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-ptrsize %s
// UNSUPPORTED: CPU=arm64_32

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %build-irgen-test-overlays
// RUN: %target-swift-frontend -sdk %S/Inputs -I %t -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -sdk %S/Inputs -I %t -emit-ir %s | %FileCheck %s
// REQUIRES: CPU=x86_64
// REQUIRES: objc_interop

View File

@@ -1,7 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/UsingObjCStuff.swiftmodule -module-name UsingObjCStuff -I %t -I %S/Inputs/mixed_mode -swift-version 4 %S/Inputs/mixed_mode/UsingObjCStuff.swift
// RUN: %target-swift-frontend -emit-ir -I %t -I %S/Inputs/mixed_mode -module-name main -swift-version 4 %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V5 --check-prefix=CHECK-V5-%target-ptrsize -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend -emit-ir -I %t -I %S/Inputs/mixed_mode -module-name main -swift-version 5 %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V5 --check-prefix=CHECK-V5-%target-ptrsize -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-ir -I %t -I %S/Inputs/mixed_mode -module-name main -swift-version 4 %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V5 --check-prefix=CHECK-V5-%target-ptrsize -DWORD=i%target-ptrsize
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-ir -I %t -I %S/Inputs/mixed_mode -module-name main -swift-version 5 %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-V5 --check-prefix=CHECK-V5-%target-ptrsize -DWORD=i%target-ptrsize
// REQUIRES: objc_interop

View File

@@ -1,4 +1,5 @@
// RUN: %target-swift-emit-ir -enable-experimental-move-only %s | %FileCheck -check-prefix=IR %s
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
// RUN: %target-swift-emit-ir -enable-experimental-move-only -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=IR %s
// Test that makes sure that at IRGen time we properly handle conditional
// releases for trivial and non-trivial move only types. The SIL/SILGen part of

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %build-irgen-test-overlays
// RUN: %target-swift-frontend -gnone -enable-objc-interop -sdk %S/Inputs -I %t %s -emit-ir | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -gnone -enable-objc-interop -sdk %S/Inputs -I %t %s -emit-ir | %FileCheck %s
// REQUIRES: CPU=x86_64
// REQUIRES: objc_interop

View File

@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -enable-objc-interop -primary-file %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize --check-prefixes=CHECK,CHECK-objc
// RUN: %target-swift-frontend -disable-objc-interop -primary-file %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize --check-prefixes=CHECK,CHECK-native
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-objc-interop -primary-file %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize --check-prefixes=CHECK,CHECK-objc
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -disable-objc-interop -primary-file %s -emit-ir | %FileCheck %s -DINT=i%target-ptrsize --check-prefixes=CHECK,CHECK-native
sil_stage canonical
import Builtin

View File

@@ -1,13 +1,13 @@
// This line tests that IRGen is properly turning the unspecialized builtins
// into traps.
//
// RUN: %target-swift-frontend -emit-ir -parse-as-library -parse-stdlib %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir -parse-as-library -parse-stdlib -Xllvm -sil-disable-pass=Simplification %s | %FileCheck %s
// Make sure we are not eliminating these builtins before IRGen runs. As part of
// the builtin's contract, we expect IRGen to convert them to traps, not
// anything before.
//
// RUN: %target-swift-frontend -emit-sil -parse-as-library -parse-stdlib %s | %FileCheck --check-prefix=SIL %s
// RUN: %target-swift-frontend -emit-sil -parse-as-library -parse-stdlib -Xllvm -sil-disable-pass=Simplification %s | %FileCheck --check-prefix=SIL %s
import Swift

View File

@@ -54,7 +54,7 @@ struct CStruct : WithAssoc {
}
func requireWitness3<T: WithAssoc> (_ t: T) {
_ = T.self.AssocType
let a = T.self.AssocType
}
protocol WithAssocConformance {

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -gnone -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -gnone -emit-ir %s | %FileCheck %s
import Builtin

View File

@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s --check-prefix=WMO --check-prefix=CHECK
// RUN: %target-swift-frontend -emit-ir -primary-file %s | %FileCheck %s --check-prefix=PRIMARY --check-prefix=CHECK
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-ir %s | %FileCheck %s --check-prefix=WMO --check-prefix=CHECK
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-ir -primary-file %s | %FileCheck %s --check-prefix=PRIMARY --check-prefix=CHECK
sil_stage canonical

View File

@@ -8,7 +8,7 @@
// RUN: %target-swift-frontend -emit-module -I %t -o %t %S/../Inputs/fixed_layout_class.swift
// RUN: %target-swift-frontend -enable-library-evolution -parse-sil -parse-as-library -emit-ir -I %t %s | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -enable-library-evolution -parse-sil -parse-as-library -emit-ir -I %t %s | %FileCheck %s
// CHECK: %swift.type = type { [[INT:i32|i64]] }

View File

@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-ir %s | %FileCheck %s
sil_stage canonical

View File

@@ -1,5 +1,7 @@
// RUN: %target-swift-emit-sil -I %S/Inputs -enable-experimental-cxx-interop %s | %FileCheck %s
// REQUIRES: swift_in_compiler
// CHECK: // clang name: WithStaticMember::staticMember
// CHECK: sil_global public_external @{{_ZN16WithStaticMember12staticMemberE|\?staticMember@WithStaticMember@@2HA}} : $Int32
// CHECK: // clang name: WithIncompleteStaticMember::selfMember
@@ -22,7 +24,8 @@ func writeStaticMember() {
// CHECK: sil hidden @$s4main17writeStaticMemberyyF : $@convention(thin) () -> ()
// CHECK: [[ADDR:%.*]] = global_addr @{{_ZN16WithStaticMember12staticMemberE|\?staticMember@WithStaticMember@@2HA}} : $*Int32
// CHECK: [[INT:%.*]] = struct $Int32 (%2 : $Builtin.Int32)
// CHECK: [[LIT:%.*]] = integer_literal $Builtin.Int32, -1
// CHECK: [[INT:%.*]] = struct $Int32 ([[LIT]] : $Builtin.Int32)
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[ADDR]] : $*Int32
// CHECK: store [[INT]] to [[ACCESS]] : $*Int32

View File

@@ -143,6 +143,7 @@ ImportedObjCGenerics.test("InheritanceFromNongeneric") {
expectTrue(Container<NSString>.superclass() == NSObject.self)
expectTrue(Container<NSObject>.superclass() == NSObject.self)
expectTrue(Container<NSObject>.self == Container<NSString>.self)
expectTrue((Container<NSObject>, Int).self == (Container<NSString>, Int).self)
}
public class InheritInSwift: Container<NSString> {

View File

@@ -1,4 +1,5 @@
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-move-only) | %FileCheck %s
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-move-only -Xllvm -sil-disable-pass=simplification) | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: swift_test_mode_optimize_none

View File

@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -emit-module -o %t/tmp.swiftmodule
// RUN: %target-swift-frontend %s -Xllvm -sil-disable-pass=simplification -emit-module -o %t/tmp.swiftmodule
// RUN: %target-sil-opt %t/tmp.swiftmodule | %FileCheck %s
sil_stage canonical

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_public_non_abi.sil
// RUN: %target-swift-frontend -emit-sil -I %t %s | %FileCheck %s
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_public_non_abi.sil -Xllvm -sil-disable-pass=simplification
// RUN: %target-swift-frontend -emit-sil -I %t %s -Xllvm -sil-disable-pass=simplification | %FileCheck %s
sil_stage raw

View File

@@ -1,6 +1,8 @@
// RUN: %target-swift-emit-silgen -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s
// RUN: %target-swift-emit-sil -Onone -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck -check-prefix=CANONICAL %s
// REQUIRES: swift_in_compiler
import Swift
protocol ClassProto : class { }
@@ -829,7 +831,6 @@ func retain(ptr: Builtin.NativeObject) {
// CANONICAL-NEXT: debug_value
// CANONICAL-NEXT: strong_release [[P]]
// CANONICAL-NEXT: tuple
// CANONICAL-NEXT: tuple
// CANONICAL-NEXT: return
// CANONICAL: } // end sil function '$s8builtins7release{{[_0-9a-zA-Z]*}}F'

View File

@@ -2,6 +2,8 @@
// RUN: %target-swift-emit-sil -enable-copy-propagation=requested-passes-only -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-experimental-move-only | %FileCheck -check-prefix=CHECK-SIL %s
// RUN: %target-swift-emit-sil -enable-copy-propagation=requested-passes-only -module-name moveonly -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -enable-experimental-move-only | %FileCheck -check-prefix=CHECK-SIL-OPT %s
// REQUIRES: swift_in_compiler
import Swift
class Klass {}
@@ -45,7 +47,6 @@ class Klass {}
// CHECK-SIL-NEXT: strong_retain [[VALUE]]
// CHECK-SIL-NEXT: strong_retain [[VALUE]]
// CHECK-SIL-NEXT: strong_release [[VALUE]]
// CHECK-SIL-NEXT: tuple ()
// CHECK-SIL-NEXT: dealloc_stack [[INPUT]] : $*Klass
// CHECK-SIL-NEXT: strong_release [[VALUE]] : $Klass
// CHECK-SIL-NEXT: return [[VALUE]] : $Klass
@@ -87,7 +88,6 @@ public func useCopy(_ k: Klass) -> Klass {
// CHECK-SIL-NEXT: strong_retain [[VALUE]]
// CHECK-SIL-NEXT: strong_retain [[VALUE]]
// CHECK-SIL-NEXT: strong_release [[VALUE]]
// CHECK-SIL-NEXT: tuple ()
// CHECK-SIL-NEXT: dealloc_stack [[INPUT]]
// CHECK-SIL-NEXT: strong_release [[VALUE]] : $T
// CHECK-SIL-NEXT: return [[VALUE]] : $T

View File

@@ -1,5 +1,6 @@
// RUN: %target-swift-emit-silgen -enable-experimental-move-only %s | %FileCheck -check-prefix=SILGEN %s
// RUN: %target-swift-emit-sil -enable-experimental-move-only %s | %FileCheck -check-prefix=SIL %s
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
// RUN: %target-swift-emit-silgen -enable-experimental-move-only -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=SILGEN %s
// RUN: %target-swift-emit-sil -enable-experimental-move-only -Xllvm -sil-disable-pass=simplification %s | %FileCheck -check-prefix=SIL %s
// Test that makes sure that throughout the pipeline we properly handle
// conditional releases for trivial and non-trivial move only types.

View File

@@ -1,6 +1,8 @@
// RUN: %target-swift-frontend %s -sil-verify-all -emit-sil -enable-copy-propagation=false -o - -I %S/Inputs/usr/include | %FileCheck %s
// REQUIRES: objc_interop
// REQUIRES: swift_in_compiler
// Using -enable-copy-propagation=false to pattern match against older SIL
// output. At least until -enable-copy-propagation has been around
// long enough in the same form to be worth rewriting CHECK lines.
@@ -75,12 +77,6 @@ public func couldActuallyEscapeWithLoop(_ closure: @escaping () -> (), _ villain
// CHECK-LABEL: sil @$s27closure_lifetime_fixup_objc9dontCrashyyF : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK: [[NONE:%.*]] = enum $Optional<{{.*}}>, #Optional.none!enumelt
// CHECK: br bb1
//
// CHECK: bb1:
// CHECK: br bb2
//
// CHECK: bb2:
// CHECK: br [[LOOP_HEADER_BB:bb[0-9]+]]([[NONE]]
//
// CHECK: [[LOOP_HEADER_BB]]([[LOOP_IND_VAR:%.*]] : $Optional

View File

@@ -1,6 +1,8 @@
// RUN: %target-swift-frontend -module-name constant_propagation_stdlib %s -parse-stdlib -emit-sil -o - | %FileCheck --check-prefix=CHECK-ONONE %s
// RUN: %target-swift-frontend -module-name constant_propagation_stdlib %s -parse-stdlib -emit-sil -o - -O | %FileCheck --check-prefix=CHECK-O %s
// REQUIRES: swift_in_compiler
public struct MyInt {
var v: Builtin.Int32
}
@@ -21,8 +23,7 @@ public func isConcrete_true(_ x: MyInt) -> Builtin.Int1 {
// CHECK-ONONE-LABEL: sil @$s27constant_propagation_stdlib16isConcrete_falseyBi1_xlF : $@convention(thin) <T> (@in_guaranteed T) -> Builtin.Int1 {
// CHECK-ONONE: bb0(
// CHECK-ONONE: [[METATYPE:%.*]] = metatype $@thick T.Type
// CHECK-ONONE: [[RESULT:%.*]] = builtin "isConcrete"<T>([[METATYPE]] : $@thick T.Type) : $Builtin.Int1
// CHECK-ONONE: [[RESULT:%.*]] = integer_literal $Builtin.Int1, 0
// CHECK-ONONE: return [[RESULT]]
// CHECK-ONONE: } // end sil function '$s27constant_propagation_stdlib16isConcrete_falseyBi1_xlF'
// CHECK-O-LABEL: sil [signature_optimized_thunk] [always_inline] {{.*}}@$s27constant_propagation_stdlib16isConcrete_falseyBi1_xlF : $@convention(thin) <T> (@in_guaranteed T) -> Builtin.Int1 {

View File

@@ -1,5 +1,7 @@
// RUN: %target-swift-frontend -emit-sil -enable-copy-propagation=false %s | %FileCheck %s
// REQUIRES: swift_in_compiler
// Using -enable-copy-propagation=false to pattern match against older SIL
// output. At least until -enable-copy-propagation has been around
// long enough in the same form to be worth rewriting CHECK lines.
@@ -779,7 +781,9 @@ class FailableBaseClass {
//
// CHECK: [[FAIL_BB]]:
// CHECK: release_value [[SELF_OPTIONAL]]
// CHECK: br [[FAIL_TRAMPOLINE_BB:bb[0-9]+]]
// CHECK: dealloc_stack [[SELF_BOX]]
// CHECK: [[NEW_SELF:%.*]] = enum $Optional<FailableBaseClass>, #Optional.none!enumelt
// CHECK-NEXT: br [[EPILOG_BB:bb[0-9]+]]([[NEW_SELF]] : $Optional<FailableBaseClass>)
//
// CHECK: [[SUCC_BB]]:
// CHECK-NEXT: [[SELF_VALUE:%.*]] = unchecked_enum_data [[SELF_OPTIONAL]]
@@ -788,11 +792,6 @@ class FailableBaseClass {
// CHECK-NEXT: [[NEW_SELF:%.*]] = enum $Optional<FailableBaseClass>, #Optional.some!enumelt, [[SELF_VALUE]]
// CHECK-NEXT: destroy_addr [[SELF_BOX]]
// CHECK-NEXT: dealloc_stack [[SELF_BOX]]
// CHECK-NEXT: br [[EPILOG_BB:bb[0-9]+]]([[NEW_SELF]] : $Optional<FailableBaseClass>)
//
// CHECK: [[FAIL_TRAMPOLINE_BB]]:
// CHECK: dealloc_stack [[SELF_BOX]]
// CHECK: [[NEW_SELF:%.*]] = enum $Optional<FailableBaseClass>, #Optional.none!enumelt
// CHECK-NEXT: br [[EPILOG_BB]]([[NEW_SELF]] : $Optional<FailableBaseClass>)
//
// CHECK: [[EPILOG_BB]]([[NEW_SELF:%.*]] : $Optional<FailableBaseClass>):

View File

@@ -1,4 +1,4 @@
// RUN: %target-swiftc_driver -module-name devirt_single_module_in_multiple_files -O %s %S/Inputs/BaseProblem.swift %S/Inputs/Problems.swift -parse-as-library -Xllvm -sil-disable-pass=inline -emit-sil 2>&1 | %FileCheck %s
// RUN: %target-swiftc_driver -module-name devirt_single_module_in_multiple_files -O %s %S/Inputs/BaseProblem.swift %S/Inputs/Problems.swift -parse-as-library -Xllvm -sil-disable-pass=inline -Xllvm -sil-disable-pass=function-signature-opts -emit-sil 2>&1 | %FileCheck %s
public func test() {
let e = Evaluator()
@@ -6,12 +6,12 @@ public func test() {
e.evaluate(1)
}
// CHECK-LABEL: sil private @$s38devirt_single_module_in_multiple_files9EvaluatorCACycfcSiycfU_
// CHECK-LABEL: sil {{.*}}@{{.*}}s38devirt_single_module_in_multiple_files9EvaluatorCACycfcSiycfU_{{.*}}
// CHECK: %{{.*}} = class_method %{{.*}} : $Problem1, #Problem1.run : (Problem1) -> () -> Int, $@convention(method) (@guaranteed Problem1) -> Int
// CHECK-NEXT: apply
// CHECK: return
// CHECK-LABEL: sil private @$s38devirt_single_module_in_multiple_files9EvaluatorCACycfcSiycfU0_
// CHECK-LABEL: sil {{.*}}@{{.*}}s38devirt_single_module_in_multiple_files9EvaluatorCACycfcSiycfU0_{{.*}}
// CHECK: %{{.*}} = class_method %{{.*}} : $Problem2, #Problem2.run : (Problem2) -> () -> Int, $@convention(method) (@guaranteed Problem2) -> Int
// CHECK-NEXT: apply
// CHECK: return

View File

@@ -1,4 +1,6 @@
// RUN: %target-sil-opt -O -wmo -enable-sil-verify-all -sil-disable-pass=DeadFunctionAndGlobalElimination %s | %FileCheck %s
// RUN: %target-sil-opt -O -wmo -enable-sil-verify-all -sil-disable-pass=DeadFunctionAndGlobalElimination -sil-disable-pass=function-signature-opts %s | %FileCheck %s
// REQUIRES: swift_in_compiler
sil_stage canonical
@@ -9,13 +11,10 @@ protocol ClassProtocol: AnyObject { func method() }
class C: ClassProtocol { func method() {} }
// CHECK-LABEL: sil [signature_optimized_thunk] [always_inline] @test_indirect_class_protocol : $@convention(thin) (@in any ClassProtocol) -> ()
sil @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> () {
sil [noinline] @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> () {
// CHECK: bb0(%0 : $*any ClassProtocol):
bb0(%0 : $*ClassProtocol):
// CHECK-NEXT: %1 = load %0
// CHECK-NEXT: strong_release %1
destroy_addr %0 : $*ClassProtocol
// CHECK-NEXT: return undef
return undef : $()
}
@@ -39,19 +38,12 @@ bb0(%0 : $*ClassProtocol):
}
// Check that a specialization of test_indirect_class_protocol is created.
// CHECK-LABEL: sil shared [signature_optimized_thunk] [always_inline] {{.*}}@$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5 : $@convention(thin) (@owned C) -> ()
// CHECK-LABEL: sil shared {{.*}}@$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5 : $@convention(thin) (@owned C) -> ()
// CHECK: bb0(%0 : $C):
// CHECK-NEXT: strong_release %0
// CHECK-NEXT: return undef
// CHECK-LABEL: end sil function '$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5'
// Check the generated specialization of test_indirect_class_protocol
// CHECK-LABEL: sil shared @$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5Tf4d_n : $@convention(thin) () -> ()
// Make sure *everything* was inlined / optimized away
// CHECK: bb0:
// CHECK-NEXT: return undef
// CHECK: } // end sil function '$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5Tf4d_n'
sil @invoke_indirect_class_protocol : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : $C):
%1 = init_existential_ref %0 : $C : $C, $ClassProtocol

View File

@@ -1,5 +1,7 @@
// RUN: %target-swift-frontend -emit-sil -primary-file %s | %FileCheck %s
// REQUIRES: swift_in_compiler
// Test to ensure that mandatory inlining of generics with a dynamic Self
// substitution works correctly with thick_metatype instructions and SIL
// type lowering.
@@ -53,8 +55,6 @@ class C : P {
// CHECK-NEXT: [[STATIC_METATYPE:%.*]] = upcast [[METATYPE]] : $@thick @dynamic_self C.Type to $@thick C.Type
// CHECK-NEXT: [[FN:%.*]] = class_method [[STATIC_METATYPE]] : $@thick C.Type, #C.init!allocator : (C.Type) -> () -> C, $@convention(method) (@thick C.Type) -> @owned C
// CHECK-NEXT: [[RESULT2:%.*]] = apply [[FN]]([[STATIC_METATYPE]]) : $@convention(method) (@thick C.Type) -> @owned C
// CHECK-NEXT: tuple ()
// CHECK-NEXT: tuple ()
// CHECK-NEXT: return %5 : $C
func returnsNewInstanceTransparentProtocol() -> Self {
return makeInstanceTransparentProtocol(type(of: self))

View File

@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all -mandatory-combine -sil-mandatory-combine-enable-canon-and-simple-dce %s | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all -sil-combine %s | %FileCheck %s
sil_stage canonical

View File

@@ -1,4 +1,6 @@
// RUN: %target-sil-opt -mandatory-combine %s | %FileCheck %s
// RUN: %target-sil-opt -onone-simplification %s | %FileCheck %s
// REQUIRES: swift_in_compiler
sil_stage canonical

View File

@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -optimized-mandatory-combine -sil-mandatory-combine-enable-canon-and-simple-dce %s | %FileCheck %s
// RUN: %target-sil-opt -sil-combine %s | %FileCheck %s
// Tests for when the mandatory combiner is running with optimizations
// enabled. Only put tests here for functionality that only occurs when the

View File

@@ -157,7 +157,6 @@ func class_constrained_generic<T : C>(_ o: T) -> AnyClass? {
func invoke(_ c: C) {
// CHECK-NOT: function_ref @$s18mandatory_inlining25class_constrained_generic{{[_0-9a-zA-Z]*}}F
// CHECK-NOT: apply
// CHECK: init_existential_metatype
_ = class_constrained_generic(c)
// CHECK: return
}

View File

@@ -1,6 +1,8 @@
// RUN: %target-swift-frontend -emit-sil -enable-experimental-concurrency -disable-availability-checking %s | %FileCheck %s
// REQUIRES: concurrency
// REQUIRES: swift_in_compiler
@_transparent
func reasyncFunction(_ value: Optional<Int>, _ fn: () async throws -> Int) reasync rethrows -> Int {
switch value {
@@ -12,15 +14,7 @@ func reasyncFunction(_ value: Optional<Int>, _ fn: () async throws -> Int) reasy
// CHECK-LABEL: sil hidden @$s26mandatory_inlining_reasync20callsReasyncFunctionSiyF : $@convention(thin) () -> Int {
// CHECK: [[FN:%.*]] = function_ref @$s26mandatory_inlining_reasync20callsReasyncFunctionSiyFSiyXEfU_ : $@convention(thin) () -> Int
// CHECK-NEXT: [[THICK:%.*]] = thin_to_thick_function [[FN]] : $@convention(thin) () -> Int to $@noescape @callee_guaranteed () -> Int
// FIXME: it looks like the hop is being removed but not this instruction
// CHECK-NEXT: [[GENERIC_EXEC:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none
// CHECK-NEXT: br bb1
// CHECK: bb1:
// CHECK-NEXT: [[RESULT:%.*]] = apply [[THICK]]() : $@noescape @callee_guaranteed () -> Int
// CHECK-NEXT: br bb2
// CHECK: bb2:
// CHECK-NEXT: return [[RESULT]] : $Int
func callsReasyncFunction() -> Int {
return reasyncFunction(nil, { return 321 } )

View File

@@ -0,0 +1,39 @@
// RUN: %target-swift-frontend -primary-file %s -module-name=test -Xllvm -sil-print-debuginfo -emit-sil | %FileCheck %s
// REQUIRES: swift_in_compiler
// CHECK-LABEL: sil [transparent] @$s4test9checkTypeySixs17FixedWidthIntegerRzlF
@_transparent
public func checkType<A: FixedWidthInteger>(_ a: A) -> Int {
// CHECK-NOT: builtin
// CHECK: debug_step , loc "{{[^"]+}}":[[# @LINE + 1]]
if _isConcrete(A.self) {
// CHECK-NOT: builtin
if A.self == Int.self {
return 1
}
}
return 0
}
// CHECK: } // end sil function '$s4test9checkTypeySixs17FixedWidthIntegerRzlF'
// CHECK-LABEL: sil @$s4test0A10IsConcreteSiyF
public func testIsConcrete() -> Int {
// CHECK: debug_step , loc "{{[^"]+}}":[[# @LINE + 1]]:3
checkType(1)
// CHECK: [[IL:%[0-9]+]] = integer_literal $Builtin.Int{{[0-9]+}}, 1
// CHECK: [[I:%[0-9]+]] = struct $Int ([[IL]] :
// CHECK: return [[I]]
}
// CHECK: } // end sil function '$s4test0A10IsConcreteSiyF'
// CHECK-LABEL: sil @$s4test0A17MetadatComparisonSbyF
public func testMetadatComparison() -> Bool {
// CHECK: debug_step , loc "{{[^"]+}}":[[# @LINE + 1]]
[String: Int].self == Never.self
// CHECK: [[IL:%[0-9]+]] = integer_literal $Builtin.Int1, 0
// CHECK: [[I:%[0-9]+]] = struct $Bool ([[IL]] :
// CHECK: return [[I]]
}
// CHECK: } // end sil function '$s4test0A17MetadatComparisonSbyF'

View File

@@ -5,6 +5,8 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -O -sil-stats-functions -sil-stats-only-function=test_simple 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-ONLY-FUNCTION %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -O -sil-stats-functions -sil-stats-only-functions=test 2>&1 | %FileCheck --check-prefix=CHECK-SIL-STATS-ONLY-FUNCTIONS %s
// REQUIRES: swift_in_compiler
// Test different modes of optimizer counters statistics collection.
@@ -17,9 +19,9 @@ sil @fatalError : $@convention(thin) () -> Never
// Check that module level statistics are produced.
//
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel,Function+EarlyLoopOpt, PerformanceConstantPropagation, {{.*}}, 15, 12
// CHECK-SIL-STATS-MODULES: module, block, HighLevel,Function+EarlyLoopOpt, SimplifyCFG, {{.*}}, 6, 3
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel,Function+EarlyLoopOpt, SimplifyCFG, {{.*}}, 12, 6
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel,Function+EarlyLoopOpt, PerformanceConstantPropagation, {{.*}}, 14, 11
// CHECK-SIL-STATS-MODULES: module, block, HighLevel,Function+EarlyLoopOpt, SimplifyCFG, {{.*}}, 5, 3
// CHECK-SIL-STATS-MODULES: module, inst, HighLevel,Function+EarlyLoopOpt, SimplifyCFG, {{.*}}, 11, 6
// Check that module level statistics are produced.
//

View File

@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all -optimized-mandatory-combine -sil-mandatory-combine-enable-canon-and-simple-dce -semantic-arc-opts %s | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all -sil-combine -semantic-arc-opts %s | %FileCheck %s
// Make sure that we can perform all of these RAUW without producing ARC traffic
// that semantic arc opts can't eliminate.
@@ -258,19 +258,18 @@ bb0(%0 : @guaranteed $Klass):
// CHECK-NOT: destroy_value
//
// CHECK: bb2:
// CHECK-NEXT: [[COPY:%.*]] = copy_value [[ARG]]
// CHECK-NEXT: cond_br undef, bb3, bb4
//
// CHECK: bb3:
// CHECK-NEXT: destroy_value [[COPY]]
// CHECK-NEXT: br bb2
//
// CHECK: bb4:
// CHECK-NEXT: [[ENUM_SOME_RESULT:%.*]] = enum $FakeOptional<Klass>, #FakeOptional.some!enumelt, [[COPY]]
// CHECK-NEXT: br bb6([[ENUM_SOME_RESULT]] : $FakeOptional<Klass>)
// CHECK-NEXT: [[ENUM_SOME_RESULT:%.*]] = enum $FakeOptional<Klass>, #FakeOptional.some!enumelt, %0
// CHECK-NEXT: [[COPY:%.*]] = copy_value [[ENUM_SOME_RESULT]]
// CHECK-NEXT: br bb6([[COPY]] : $FakeOptional<Klass>)
//
// CHECK: bb5:
// CHECK-NEXT: [[ENUM_NONE_RESULT:%.*]] = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt // user: %10
// CHECK-NEXT: [[ENUM_NONE_RESULT:%.*]] = enum $FakeOptional<Klass>, #FakeOptional.none!enumelt
// CHECK-NEXT: br bb6([[ENUM_NONE_RESULT]] :
//
// CHECK: bb6([[RESULT:%.*]] : @owned $FakeOptional<Klass>):
@@ -340,7 +339,6 @@ bb0(%0 : @guaranteed $Builtin.NativeObject):
// CHECK-LABEL: sil [ossa] @unowned_to_guaranteed_rauw_2b : $@convention(thin) (@guaranteed Builtin.NativeObject) -> Klass {
// CHECK: bb0(
// CHECK-NEXT: unchecked_ref_cast
// CHECK-NEXT: unchecked_ownership_conversion
// CHECK-NEXT: return
// CHECK: } // end sil function 'unowned_to_guaranteed_rauw_2b'
sil [ossa] @unowned_to_guaranteed_rauw_2b : $@convention(thin) (@guaranteed Builtin.NativeObject) -> Klass {

View File

@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -simplification | %FileCheck %s
// REQUIRES: swift_in_compiler

View File

@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module -Xfrontend -disable-diagnostic-passes -whole-module-optimization -Xfrontend -enable-objc-interop -o %t/def_basic.swiftmodule %S/Inputs/def_basic.sil
// RUN: %target-build-swift -Xllvm -sil-disable-pass=simplification -emit-module -Xfrontend -disable-diagnostic-passes -whole-module-optimization -Xfrontend -enable-objc-interop -o %t/def_basic.swiftmodule %S/Inputs/def_basic.sil
// RUN: llvm-bcanalyzer %t/def_basic.swiftmodule | %FileCheck %s
// RUN: %target-build-swift -emit-sil -I %t %s -o %t/basic_sil.sil
// RUN: %target-sil-opt -parse-serialized-sil -I %t %t/basic_sil.sil -performance-linker | %FileCheck %S/Inputs/def_basic.sil

View File

@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -Xfrontend %clang-importer-sdk -I %S/../Inputs/clang-importer-sdk/swift-modules -emit-module -Xfrontend -disable-diagnostic-passes -whole-module-optimization -o %t/def_basic_objc.swiftmodule %S/Inputs/def_basic_objc.sil
// RUN: %target-build-swift -Xllvm -sil-disable-pass=simplification -Xfrontend %clang-importer-sdk -I %S/../Inputs/clang-importer-sdk/swift-modules -emit-module -Xfrontend -disable-diagnostic-passes -whole-module-optimization -o %t/def_basic_objc.swiftmodule %S/Inputs/def_basic_objc.sil
// RUN: llvm-bcanalyzer %t/def_basic_objc.swiftmodule | %FileCheck %s
// RUN: %target-build-swift -Xfrontend %clang-importer-sdk -emit-sil -I %t %s -o %t/basic_sil_objc.sil

View File

@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module -Xfrontend -disable-availability-checking -Xfrontend -disable-diagnostic-passes -whole-module-optimization -Xfrontend -enable-objc-interop -o %t/def_concurrency.swiftmodule %S/Inputs/def_concurrency.sil
// RUN: %target-build-swift -Xllvm -sil-disable-pass=simplification -emit-module -Xfrontend -disable-availability-checking -Xfrontend -disable-diagnostic-passes -whole-module-optimization -Xfrontend -enable-objc-interop -o %t/def_concurrency.swiftmodule %S/Inputs/def_concurrency.sil
// RUN: llvm-bcanalyzer %t/def_concurrency.swiftmodule | %FileCheck %s
// RUN: %target-build-swift -emit-sil -I %t %s -o %t/concurrency_sil.sil
// RUN: %target-sil-opt -parse-serialized-sil -I %t %t/concurrency_sil.sil -performance-linker | %FileCheck %S/Inputs/def_concurrency.sil

View File

@@ -1,6 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -enable-experimental-move-only -g -emit-module -module-name OtherModule %S/Inputs/moveonly_deinit.swift -emit-module-path %t/OtherModule.swiftmodule
// RUN: %target-swift-frontend -enable-experimental-move-only -g -I %t %s -emit-silgen
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
// RUN: %target-swift-frontend -enable-experimental-move-only -Xllvm -sil-disable-pass=simplification -g -emit-module -module-name OtherModule %S/Inputs/moveonly_deinit.swift -emit-module-path %t/OtherModule.swiftmodule
// RUN: %target-swift-frontend -enable-experimental-move-only -Xllvm -sil-disable-pass=simplification -g -I %t %s -emit-silgen
// Make sure we can deserialize deinits of both enums and structs.

View File

@@ -1,5 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_deinit.swift -enable-experimental-move-only
// TODO: re-enable the simplification passes once rdar://104875010 is fixed
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_deinit.swift -enable-experimental-move-only
// RUN: not %target-swift-frontend -I %t %s -emit-sil -o /dev/null 2>&1 | %FileCheck %s
// This test makes sure that if we import a move only type and do not set the

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-module -Xllvm -verify-skip-convert-escape-to-noescape-attributes -Xfrontend -disable-diagnostic-passes -whole-module-optimization -o %t/sil_partial_apply_ownership.swiftmodule %s
// RUN: %target-build-swift -Xllvm -verify-skip-convert-escape-to-noescape-attributes -emit-sil -I %t %s | %FileCheck %s
// RUN: %target-build-swift -Xllvm -sil-disable-pass=simplification -emit-module -Xllvm -verify-skip-convert-escape-to-noescape-attributes -Xfrontend -disable-diagnostic-passes -whole-module-optimization -o %t/sil_partial_apply_ownership.swiftmodule %s
// RUN: %target-build-swift -Xllvm -sil-disable-pass=simplification -Xllvm -verify-skip-convert-escape-to-noescape-attributes -emit-sil -I %t %s | %FileCheck %s
import Builtin

View File

@@ -1,9 +1,11 @@
// RUN: %sil-passpipeline-dumper -Onone | %FileCheck %s
// REQUIRES: swift_in_compiler
// CHECK: ---
// CHECK: name: Non-Diagnostic Mandatory Optimizations
// CHECK: passes: [ "for-each-loop-unroll", "mandatory-combine", "mandatory-arc-opts",
// CHECK: "onone-prespecializer" ]
// CHECK: passes: [ "for-each-loop-unroll", "onone-simplification", "mandatory-arc-opts",
// CHECK: "onone-prespecializer" ]
// CHECK: ---
// CHECK: name: Serialization
// CHECK: passes: [ "serialize-sil", "sil-moved-async-var-dbginfo-propagator",
@@ -11,5 +13,6 @@
// CHECK: ---
// CHECK: name: Rest of Onone
// CHECK: passes: [ "use-prespecialized", "target-constant-folding", "function-stack-protection",
// CHECK-NEXT: "late-onone-simplification", "cleanup-debug-steps",
// CHECK-NEXT: "sil-debuginfo-gen" ]
// CHECK: ...

View File

@@ -91,7 +91,6 @@ _swift_complete()
-sil-loop-region-view-cfg-only-function \
-sil-loop-region-view-cfg-only-functions \
-sil-lower-agg-instrs-expand-all \
-sil-mandatory-combine-enable-canon-and-simple-dce \
-sil-merge-stack-slots \
-sil-opt-pass-count \
-sil-opt-remark-ignore-always-infer \