Skip to content

Commit af91fec

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. (cherry picked from commit 6129f4e)
1 parent a485d97 commit af91fec

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
@@ -873,39 +873,41 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
873873
return SILIsolationInfo::getTaskIsolated(fArg);
874874
}
875875

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

882-
os << ": ";
881+
os << ": ";
883882

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

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

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

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

@@ -924,7 +926,7 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
924926
}
925927
case ActorInstance::Kind::ActorAccessorInit:
926928
os << "'self'-isolated";
927-
printOptions();
929+
printOptions(os);
928930
os << '\n';
929931
os << "instance: actor accessor init\n";
930932
return;
@@ -934,17 +936,17 @@ void SILIsolationInfo::print(llvm::raw_ostream &os) const {
934936
if (getActorIsolation().getKind() == ActorIsolation::ActorInstance) {
935937
if (auto *vd = getActorIsolation().getActorInstance()) {
936938
os << "'" << vd->getBaseIdentifier() << "'-isolated";
937-
printOptions();
939+
printOptions(os);
938940
return;
939941
}
940942
}
941943

942944
getActorIsolation().printForDiagnostics(os);
943-
printOptions();
945+
printOptions(os);
944946
return;
945947
case Task:
946948
os << "task-isolated";
947-
printOptions();
949+
printOptions(os);
948950
os << '\n';
949951
os << "instance: " << *getIsolatedValue();
950952
return;
@@ -1071,9 +1073,7 @@ void SILIsolationInfo::printForOneLineLogging(llvm::raw_ostream &os) const {
10711073
return;
10721074
case Disconnected:
10731075
os << "disconnected";
1074-
if (getOptions().contains(Flag::UnsafeNonIsolated)) {
1075-
os << ": nonisolated(unsafe)";
1076-
}
1076+
printOptions(os);
10771077
return;
10781078
case Actor:
10791079
if (auto instance = getActorInstance()) {
@@ -1082,27 +1082,32 @@ void SILIsolationInfo::printForOneLineLogging(llvm::raw_ostream &os) const {
10821082
SILValue value = instance.getValue();
10831083
if (auto name = VariableNameInferrer::inferName(value)) {
10841084
os << "'" << *name << "'-isolated";
1085+
printOptions(os);
10851086
return;
10861087
}
10871088
break;
10881089
}
10891090
case ActorInstance::Kind::ActorAccessorInit:
10901091
os << "'self'-isolated";
1092+
printOptions(os);
10911093
return;
10921094
}
10931095
}
10941096

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

11021105
getActorIsolation().printForDiagnostics(os);
1106+
printOptions(os);
11031107
return;
11041108
case Task:
11051109
os << "task-isolated";
1110+
printOptions(os);
11061111
return;
11071112
}
11081113
}

0 commit comments

Comments
 (0)