Swift SIL: escape effects for function arguments.

Store a list of argument effects in a function, which specify if and how arguments escape.
Such effects can be specified in the Swift source code (for details see docs/ReferenceGuides/UnderscoredAttributes.md) or derived in an optimization pass.

For details see the documentation in SwiftCompilerSources/Sources/SIL/Effects.swift.
This commit is contained in:
Erik Eckstein
2021-09-24 10:22:31 +02:00
parent 72fc4e3c95
commit f09dfc93a9
21 changed files with 836 additions and 35 deletions

View File

@@ -2944,6 +2944,36 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
else if (getEffectsKind() == EffectsKind::ReleaseNone)
OS << "[releasenone] ";
llvm::SmallVector<int, 8> definedEscapesIndices;
llvm::SmallVector<int, 8> escapesIndices;
visitArgEffects([&](int effectIdx, bool isDerived, ArgEffectKind kind) {
if (kind == ArgEffectKind::Escape) {
if (isDerived) {
escapesIndices.push_back(effectIdx);
} else {
definedEscapesIndices.push_back(effectIdx);
}
}
});
if (!definedEscapesIndices.empty()) {
OS << "[defined_escapes ";
for (int effectIdx : definedEscapesIndices) {
if (effectIdx > 0)
OS << ", ";
writeEffect(OS, effectIdx);
}
OS << "] ";
}
if (!escapesIndices.empty()) {
OS << "[escapes ";
for (int effectIdx : escapesIndices) {
if (effectIdx > 0)
OS << ", ";
writeEffect(OS, effectIdx);
}
OS << "] ";
}
if (auto *replacedFun = getDynamicallyReplacedFunction()) {
OS << "[dynamic_replacement_for \"";
OS << replacedFun->getName();