Files
swift-mirror/lib/SIL/IR/ApplySite.cpp
Erik Eckstein 18063707b5 Optimizer: enable complete OSSA lifetimes throughout the pass pipeline
This new OSSA invariant simplifies many optimizations because they don't have to take care of the corner case of incomplete lifetimes in dead-end blocks.

The implementation basically consists of these changes:
* add the lifetime completion utility
* add a flag in SILFunction which tells optimization that they need to run the lifetime completion utility
* let all optimizations complete lifetimes if necessary
* enable the ownership verifier to check complete lifetimes
2026-01-22 17:41:48 +01:00

62 lines
2.2 KiB
C++

//===--- ApplySite.cpp - Wrapper around apply instructions ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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
//
//===----------------------------------------------------------------------===//
#include "swift/SIL/ApplySite.h"
#include "swift/SIL/SILBuilder.h"
using namespace swift;
void ApplySite::insertAfterInvocation(function_ref<void(SILBuilder &)> func) const {
SILBuilderWithScope::insertAfter(getInstruction(), func);
}
void ApplySite::insertAfterApplication(
function_ref<void(SILBuilder &)> func) const {
switch (getKind()) {
case ApplySiteKind::ApplyInst:
case ApplySiteKind::TryApplyInst:
case ApplySiteKind::PartialApplyInst:
return insertAfterInvocation(func);
case ApplySiteKind::BeginApplyInst:
SmallVector<EndApplyInst *, 2> endApplies;
SmallVector<AbortApplyInst *, 2> abortApplies;
SmallVector<EndBorrowInst *, 2> endBorrows;
auto *bai = cast<BeginApplyInst>(getInstruction());
bai->getCoroutineEndPoints(endApplies, abortApplies, &endBorrows);
for (auto *eai : endApplies) {
SILBuilderWithScope builder(std::next(eai->getIterator()));
func(builder);
}
for (auto *aai : abortApplies) {
SILBuilderWithScope builder(std::next(aai->getIterator()));
func(builder);
}
for (auto *ebi : endBorrows) {
SILBuilderWithScope builder(std::next(ebi->getIterator()));
func(builder);
}
return;
}
llvm_unreachable("covered switch isn't covered");
}
bool ApplySite::isAddressable(const Operand &operand) const {
unsigned calleeArgIndex = getCalleeArgIndex(operand);
assert(calleeArgIndex >= getSubstCalleeConv().getSILArgIndexOfFirstParam());
unsigned paramIdx =
calleeArgIndex - getSubstCalleeConv().getSILArgIndexOfFirstParam();
CanSILFunctionType calleeType = getSubstCalleeType();
return calleeType->isAddressable(paramIdx, getFunction());
}