SIL: make argument effects more readable in textual SIL

So far, argument effects were printed in square brackets before the function name, e.g.
```
sil [escapes !%0.**, !%1, %1.c*.v** => %0.v**] @foo : $@convention(thin) (@guaranteed T) -> @out S {
bb0(%0 : $*S, %1 : @guaranteed $T):
...
```

As we are adding more argument effects, this becomes unreadable.
To make it more readable, print the effects after the opening curly brace, and print a separate line for each argument. E.g.
```
sil [ossa] @foo : $@convention(thin) (@guaranteed T) -> @out S {
[%0: noescape **]
[%1: noescape, escape c*.v** => %0.v**]
bb0(%0 : $*S, %1 : @guaranteed $T):
...
```
This commit is contained in:
Erik Eckstein
2022-09-12 08:24:47 +02:00
parent e1ff0aa235
commit 8e2e7a73c5
23 changed files with 520 additions and 335 deletions

View File

@@ -135,7 +135,7 @@ static FunctionRegisterFn destroyFunction = nullptr;
static FunctionWriteFn writeFunction = nullptr;
static FunctionParseFn parseFunction = nullptr;
static FunctionCopyEffectsFn copyEffectsFunction = nullptr;
static FunctionGetEffectFlagsFn getEffectFlagsFunction = nullptr;
static FunctionGetEffectInfoFn getEffectInfoFunction = nullptr;
SILFunction::SILFunction(
SILModule &Module, SILLinkage Linkage, StringRef Name,
@@ -907,22 +907,23 @@ void Function_register(SwiftMetatype metatype,
FunctionRegisterFn initFn, FunctionRegisterFn destroyFn,
FunctionWriteFn writeFn, FunctionParseFn parseFn,
FunctionCopyEffectsFn copyEffectsFn,
FunctionGetEffectFlagsFn getEffectFlagsFn) {
FunctionGetEffectInfoFn effectInfoFn) {
functionMetatype = metatype;
initFunction = initFn;
destroyFunction = destroyFn;
writeFunction = writeFn;
parseFunction = parseFn;
copyEffectsFunction = copyEffectsFn;
getEffectFlagsFunction = getEffectFlagsFn;
getEffectInfoFunction = effectInfoFn;
}
std::pair<const char *, int> SILFunction::
parseEffects(StringRef attrs, bool fromSIL, bool isDerived,
parseEffects(StringRef attrs, bool fromSIL, int argumentIndex, bool isDerived,
ArrayRef<StringRef> paramNames) {
if (parseFunction) {
BridgedParsingError error = parseFunction(
{this}, attrs, (SwiftInt)fromSIL, (SwiftInt)isDerived,
{this}, attrs, (SwiftInt)fromSIL,
(SwiftInt)argumentIndex, (SwiftInt)isDerived,
{(const unsigned char *)paramNames.data(), paramNames.size()});
return {(const char *)error.message, (int)error.position};
}
@@ -942,25 +943,25 @@ void SILFunction::copyEffects(SILFunction *from) {
}
bool SILFunction::hasArgumentEffects() const {
if (getEffectFlagsFunction) {
return getEffectFlagsFunction({const_cast<SILFunction *>(this)}, 0) != 0;
if (getEffectInfoFunction) {
BridgedFunction f = {const_cast<SILFunction *>(this)};
return getEffectInfoFunction(f, 0).argumentIndex >= 0;
}
return false;
}
void SILFunction::
visitArgEffects(std::function<void(int, bool, ArgEffectKind)> c) const {
if (!getEffectFlagsFunction)
visitArgEffects(std::function<void(int, int, bool)> c) const {
if (!getEffectInfoFunction)
return;
int idx = 0;
BridgedFunction bridgedFn = {const_cast<SILFunction *>(this)};
while (int flags = getEffectFlagsFunction(bridgedFn, idx)) {
ArgEffectKind kind = ArgEffectKind::Unknown;
if (flags & EffectsFlagEscape)
kind = ArgEffectKind::Escape;
c(idx, (flags & EffectsFlagDerived) != 0, kind);
while (true) {
BridgedEffectInfo ei = getEffectInfoFunction(bridgedFn, idx);
if (ei.argumentIndex < 0)
return;
c(idx, ei.argumentIndex, ei.isDerived);
idx++;
}
}