Skip to content

Commit 6129f4e

Browse files
committed
[region-isolation] Print out SILIsolationInfo's options on all printing routines for SILIsolationInfo.
Before we wouldn't print them in all situations and even more so a few of the printing routines did not have it at all. This just adds a centralized SILIsolationInfo::dumpOptions() method and then goes through all of the printing helpers and changes them to use them as appropriate.
1 parent 0c25480 commit 6129f4e

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

include/swift/SILOptimizer/Utils/SILIsolationInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class SILIsolationInfo {
142142
/// If set, this means that this actor isolation is from an isolated
143143
/// parameter and should be allowed to merge into a self parameter.
144144
UnappliedIsolatedAnyParameter = 0x2,
145+
146+
/// The maximum number of bits used by a Flag.
147+
MaxNumBits = 2,
145148
};
146149

147150
using Options = OptionSet<Flag>;
@@ -426,6 +429,9 @@ class SILIsolationInfo {
426429
bool isEqual(const SILIsolationInfo &other) const;
427430

428431
void Profile(llvm::FoldingSetNodeID &id) const;
432+
433+
private:
434+
void printOptions(llvm::raw_ostream &os) const;
429435
};
430436

431437
/// A SILIsolationInfo that has gone through merging and represents the dynamic

lib/SILOptimizer/Utils/SILIsolationInfo.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -874,39 +874,41 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
874874
return SILIsolationInfo::getTaskIsolated(fArg);
875875
}
876876

877-
void SILIsolationInfo::print(llvm::raw_ostream &os) const {
878-
auto printOptions = [&] {
879-
auto opts = getOptions();
880-
if (!opts)
881-
return;
877+
void SILIsolationInfo::printOptions(llvm::raw_ostream &os) const {
878+
auto opts = getOptions();
879+
if (!opts)
880+
return;
882881

883-
os << ": ";
882+
os << ": ";
884883

885-
std::array<std::pair<Flag, StringLiteral>, 2> data = {
886-
std::make_pair(Flag::UnsafeNonIsolated,
887-
StringLiteral("nonisolated(unsafe)")),
888-
std::make_pair(Flag::UnappliedIsolatedAnyParameter,
889-
StringLiteral("unapplied_isolated_parameter")),
890-
};
884+
llvm::SmallVector<StringLiteral, unsigned(Flag::MaxNumBits)> data;
891885

892-
llvm::interleave(
893-
data, os,
894-
[&](const std::pair<Flag, StringLiteral> &value) {
895-
opts -= value.first;
896-
os << value.second;
897-
},
898-
", ");
886+
if (opts.contains(Flag::UnsafeNonIsolated)) {
887+
data.push_back(StringLiteral("nonisolated(unsafe)"));
888+
opts -= Flag::UnsafeNonIsolated;
889+
}
899890

900-
assert(!opts && "Unhandled flag?!");
901-
};
891+
if (opts.contains(Flag::UnappliedIsolatedAnyParameter)) {
892+
data.push_back(StringLiteral("unapplied_isolated_any_parameter"));
893+
opts -= Flag::UnappliedIsolatedAnyParameter;
894+
}
902895

896+
assert(!opts && "Unhandled flag?!");
897+
assert(data.size() < unsigned(Flag::MaxNumBits) &&
898+
"Please update MaxNumBits so that we can avoid heap allocations in "
899+
"this SmallVector");
900+
901+
llvm::interleave(data, os, ", ");
902+
}
903+
904+
void SILIsolationInfo::print(llvm::raw_ostream &os) const {
903905
switch (Kind(*this)) {
904906
case Unknown:
905907
os << "unknown";
906908
return;
907909
case Disconnected:
908910
os << "disconnected";
909-
printOptions();
911+
printOptions(os);
910912
return;
911913
case Actor:
912914
if (ActorInstance instance = getActorInstance()) {
@@ -915,7 +917,7 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
915917
SILValue value = instance.getValue();
916918
if (auto name = VariableNameInferrer::inferName(value)) {
917919
os << "'" << *name << "'-isolated";
918-
printOptions();
920+
printOptions(os);
919921
os << "\n";
920922
os << "instance: " << *value;
921923

@@ -925,7 +927,7 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
925927
}
926928
case ActorInstance::Kind::ActorAccessorInit:
927929
os << "'self'-isolated";
928-
printOptions();
930+
printOptions(os);
929931
os << '\n';
930932
os << "instance: actor accessor init\n";
931933
return;
@@ -935,17 +937,17 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
935937
if (getActorIsolation().getKind() == ActorIsolation::ActorInstance) {
936938
if (auto *vd = getActorIsolation().getActorInstance()) {
937939
os << "'" << vd->getBaseIdentifier() << "'-isolated";
938-
printOptions();
940+
printOptions(os);
939941
return;
940942
}
941943
}
942944

943945
getActorIsolation().printForDiagnostics(os);
944-
printOptions();
946+
printOptions(os);
945947
return;
946948
case Task:
947949
os << "task-isolated";
948-
printOptions();
950+
printOptions(os);
949951
os << '\n';
950952
os << "instance: " << *getIsolatedValue();
951953
return;
@@ -1072,9 +1074,7 @@ void SILIsolationInfo::printForOneLineLogging(llvm::raw_ostream &os) const {
10721074
return;
10731075
case Disconnected:
10741076
os << "disconnected";
1075-
if (getOptions().contains(Flag::UnsafeNonIsolated)) {
1076-
os << ": nonisolated(unsafe)";
1077-
}
1077+
printOptions(os);
10781078
return;
10791079
case Actor:
10801080
if (auto instance = getActorInstance()) {
@@ -1083,27 +1083,32 @@ void SILIsolationInfo::printForOneLineLogging(llvm::raw_ostream &os) const {
10831083
SILValue value = instance.getValue();
10841084
if (auto name = VariableNameInferrer::inferName(value)) {
10851085
os << "'" << *name << "'-isolated";
1086+
printOptions(os);
10861087
return;
10871088
}
10881089
break;
10891090
}
10901091
case ActorInstance::Kind::ActorAccessorInit:
10911092
os << "'self'-isolated";
1093+
printOptions(os);
10921094
return;
10931095
}
10941096
}
10951097

10961098
if (getActorIsolation().getKind() == ActorIsolation::ActorInstance) {
10971099
if (auto *vd = getActorIsolation().getActorInstance()) {
10981100
os << "'" << vd->getBaseIdentifier() << "'-isolated";
1101+
printOptions(os);
10991102
return;
11001103
}
11011104
}
11021105

11031106
getActorIsolation().printForDiagnostics(os);
1107+
printOptions(os);
11041108
return;
11051109
case Task:
11061110
os << "task-isolated";
1111+
printOptions(os);
11071112
return;
11081113
}
11091114
}

0 commit comments

Comments
 (0)