Skip to content

Commit 3a377a3

Browse files
committed
[send-non-sendable] When logging the pseudo-ir dump out the root representative value associated with pseudo-ir ids.
Really, we should just be using representative values here in general since it serves the same purpose and makes it easier to trace back values. But this in the short term makes the output easier to reason about.
1 parent acd1063 commit 3a377a3

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class PartitionOp {
141141

142142
PartitionOpKind getKind() const { return OpKind; }
143143

144+
ArrayRef<Element> getOpArgs() const { return OpArgs; }
145+
144146
SILInstruction *getSourceInst(bool assertNonNull = false) const {
145147
assert(!assertNonNull ||
146148
sourceInst && "PartitionOps should be assigned SILInstruction"

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ class PartitionOpTranslator {
225225
/// ensure simplifyVal is called on SILValues before entering into this map
226226
llvm::DenseMap<SILValue, TrackableValueState> equivalenceClassValuesToState;
227227

228+
#ifndef NDEBUG
229+
llvm::DenseMap<unsigned, SILValue> stateIndexToEquivalenceClass;
230+
#endif
231+
228232
// some values that AccessStorage claims are uniquely identified are still
229233
// captured (e.g. in a closure). This set is initialized upon
230234
// PartitionOpTranslator construction to store those values.
@@ -245,9 +249,13 @@ class PartitionOpTranslator {
245249

246250
// If we did not insert, just return the already stored value.
247251
if (!iter.second) {
248-
return {value, iter.first->second};
252+
return {iter.first->first, iter.first->second};
249253
}
250254

255+
#ifndef NDEBUG
256+
self->stateIndexToEquivalenceClass[iter.first->second.getID()] = value;
257+
#endif
258+
251259
// Otherwise, we need to compute our true aliased and sendable values. Begi
252260
// by seeing if we have a value that we can prove is not aliased.
253261
if (isAddress(value)) {
@@ -930,6 +938,10 @@ class PartitionOpTranslator {
930938
//translate each SIL instruction to a PartitionOp, if necessary
931939
std::vector<PartitionOp> partitionOps;
932940
int lastTranslationIndex = -1;
941+
#ifndef NDEBUG
942+
llvm::SmallVector<unsigned, 8> opsToPrint;
943+
#endif
944+
933945
for (SILInstruction &instruction : *basicBlock) {
934946
auto ops = translateSILInstruction(&instruction);
935947
for (PartitionOp &op : ops) {
@@ -943,10 +955,32 @@ class PartitionOpTranslator {
943955
instruction.getLoc().getSourceLoc().printLineAndColumn(
944956
llvm::dbgs(), function->getASTContext().SourceMgr);
945957
llvm::dbgs() << " │ translation #" << translationIndex;
946-
llvm::dbgs() << "\n └─────╼ ";
947-
} else { llvm::dbgs() << " └╼ "; } op.print(llvm::dbgs());
948-
lastTranslationIndex = translationIndex;);
958+
llvm::dbgs() << "\n ├─────╼ ";
959+
} else {
960+
llvm::dbgs() << " │ └╼ ";
961+
}
962+
op.print(llvm::dbgs());
963+
lastTranslationIndex = translationIndex;
964+
);
949965
}
966+
LLVM_DEBUG(
967+
if (ops.size()) {
968+
llvm::dbgs() << " └─────╼ Used Values\n";
969+
SWIFT_DEFER { opsToPrint.clear(); };
970+
for (PartitionOp &op : ops) {
971+
// Now dump our the root value we map.
972+
for (unsigned opArg : op.getOpArgs()) {
973+
// If we didn't insert, skip this. We only emit this once.
974+
opsToPrint.push_back(opArg);
975+
}
976+
}
977+
sortUnique(opsToPrint);
978+
for (unsigned opArg : opsToPrint) {
979+
llvm::dbgs() << " └╼ ";
980+
llvm::dbgs() << "%%" << opArg << ": " << stateIndexToEquivalenceClass[opArg];
981+
}
982+
}
983+
);
950984
}
951985

952986
return partitionOps;

0 commit comments

Comments
 (0)