Skip to content

Commit 42df9c4

Browse files
committed
[send-non-sendable] Cleanup logging a little.
Specifically: 1. Converted llvm::errs() -> llvm::dbgs() when using LLVM_DEBUG. 2. Converted a dump method on errs to be a print method on dbgs that is called from dump with print(llvm::dbgs()).
1 parent 336ed71 commit 42df9c4

File tree

2 files changed

+87
-105
lines changed

2 files changed

+87
-105
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ class PartitionOp {
152152
return sourceExpr;
153153
}
154154

155-
void dump() const LLVM_ATTRIBUTE_USED {
156-
raw_ostream &os = llvm::errs();
155+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
156+
157+
void print(llvm::raw_ostream &os) const {
157158
switch (OpKind) {
158159
case PartitionOpKind::Assign:
159160
os << "assign %%" << OpArgs[0] << " = %%" << OpArgs[1] << "\n";
@@ -221,7 +222,7 @@ class Partition {
221222

222223
auto fail = [&](Element i, int type) {
223224
llvm::dbgs() << "FAIL(i=" << i << "; type=" << type << "): ";
224-
dump();
225+
print(llvm::dbgs());
225226
return false;
226227
};
227228

@@ -367,14 +368,10 @@ class Partition {
367368
fst_reduced.merge(i, Element(snd_label));
368369
}
369370

370-
LLVM_DEBUG(
371-
llvm::dbgs() << "JOIN PEFORMED: \nFST: ";
372-
fst.dump();
373-
llvm::dbgs() << "SND: ";
374-
snd.dump();
375-
llvm::dbgs() << "RESULT: ";
376-
fst_reduced.dump();
377-
);
371+
LLVM_DEBUG(llvm::dbgs() << "JOIN PEFORMED: \nFST: ";
372+
fst.print(llvm::dbgs()); llvm::dbgs() << "SND: ";
373+
snd.print(llvm::dbgs()); llvm::dbgs() << "RESULT: ";
374+
fst_reduced.print(llvm::dbgs()););
378375

379376
assert(fst_reduced.is_canonical_correct());
380377

@@ -516,24 +513,27 @@ class Partition {
516513
llvm::dbgs() << "}\n";
517514
}
518515

519-
void dump() const LLVM_ATTRIBUTE_USED {
516+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
517+
518+
void print(llvm::raw_ostream &os) const {
520519
std::map<Region, std::vector<Element>> buckets;
521520

522521
for (auto [i, label] : labels)
523522
buckets[label].push_back(i);
524523

525-
llvm::dbgs() << "[";
524+
os << "[";
526525
for (auto [label, indices] : buckets) {
527-
llvm::dbgs() << (label.isConsumed() ? "{" : "(");
526+
os << (label.isConsumed() ? "{" : "(");
528527
int j = 0;
529528
for (Element i : indices) {
530-
llvm::dbgs() << (j++ ? " " : "") << i;
529+
os << (j++ ? " " : "") << i;
531530
}
532-
llvm::dbgs() << (label.isConsumed() ? "}" : ")");
531+
os << (label.isConsumed() ? "}" : ")");
533532
}
534-
llvm::dbgs() << "]\n";
533+
os << "]\n";
535534
}
536535
};
537-
}
536+
537+
} // namespace swift
538538

539539
#endif // SWIFT_PARTITIONUTILS_H

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,8 @@ class PartitionOpTranslator {
904904
break;
905905
}
906906

907-
LLVM_DEBUG(llvm::errs() << "warning: ";
908-
llvm::errs() << "unhandled instruction kind "
907+
LLVM_DEBUG(llvm::dbgs() << "warning: ";
908+
llvm::dbgs() << "unhandled instruction kind "
909909
<< getSILInstructionName(inst->getKind()) << "\n";);
910910

911911
return {};
@@ -915,16 +915,11 @@ class PartitionOpTranslator {
915915
// transformations to the non-Sendable partition that it induces.
916916
// it accomplished this by sequentially calling translateSILInstruction
917917
std::vector<PartitionOp> translateSILBasicBlock(SILBasicBlock *basicBlock) {
918-
LLVM_DEBUG(
919-
llvm::dbgs() << SEP_STR
920-
<< "Compiling basic block for function "
921-
<< basicBlock->getFunction()->getName()
922-
<< ": ";
923-
basicBlock->dumpID();
924-
llvm::dbgs() << SEP_STR;
925-
basicBlock->dump();
926-
llvm::dbgs() << SEP_STR << "Results:\n";
927-
);
918+
LLVM_DEBUG(llvm::dbgs() << SEP_STR << "Compiling basic block for function "
919+
<< basicBlock->getFunction()->getName() << ": ";
920+
basicBlock->dumpID(); llvm::dbgs() << SEP_STR;
921+
basicBlock->print(llvm::dbgs());
922+
llvm::dbgs() << SEP_STR << "Results:\n";);
928923

929924
//translate each SIL instruction to a PartitionOp, if necessary
930925
std::vector<PartitionOp> partitionOps;
@@ -937,18 +932,14 @@ class PartitionOpTranslator {
937932
LLVM_DEBUG(
938933
if (translationIndex != lastTranslationIndex) {
939934
llvm::dbgs() << " ┌─┬─╼";
940-
instruction.dump();
935+
instruction.print(llvm::dbgs());
941936
llvm::dbgs() << " │ └─╼ ";
942937
instruction.getLoc().getSourceLoc().printLineAndColumn(
943938
llvm::dbgs(), function->getASTContext().SourceMgr);
944939
llvm::dbgs() << " │ translation #" << translationIndex;
945940
llvm::dbgs() << "\n └─────╼ ";
946-
} else {
947-
llvm::dbgs() << " └╼ ";
948-
}
949-
op.dump();
950-
lastTranslationIndex = translationIndex;
951-
);
941+
} else { llvm::dbgs() << " └╼ "; } op.print(llvm::dbgs());
942+
lastTranslationIndex = translationIndex;);
952943
}
953944
}
954945

@@ -1038,36 +1029,32 @@ class BlockPartitionState {
10381029
return exitPartition;
10391030
}
10401031

1041-
void dump() LLVM_ATTRIBUTE_USED {
1032+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
1033+
1034+
void print(llvm::raw_ostream &os) const {
10421035
LLVM_DEBUG(
1043-
llvm::dbgs() << SEP_STR
1044-
<< "BlockPartitionState[reached="
1045-
<< reached
1046-
<< ", needsUpdate="
1047-
<< needsUpdate
1048-
<< "]\nid: ";
1049-
basicBlock->dumpID();
1050-
llvm::dbgs() << "entry partition: ";
1051-
entryPartition.dump();
1052-
llvm::dbgs() << "exit partition: ";
1053-
exitPartition.dump();
1054-
llvm::dbgs() << "instructions:\n┌──────────╼\n";
1055-
for (PartitionOp op : blockPartitionOps) {
1056-
llvm::dbgs() << "";
1057-
op.dump();
1058-
}
1059-
llvm::dbgs() << "└──────────╼\nSuccs:\n";
1060-
for (auto succ : basicBlock->getSuccessorBlocks()) {
1061-
llvm::dbgs() << "";
1062-
succ->dumpID();
1063-
}
1064-
llvm::dbgs() << "Preds:\n";
1065-
for (auto pred : basicBlock->getPredecessorBlocks()) {
1066-
llvm::dbgs() << "";
1067-
pred->dumpID();
1068-
}
1069-
llvm::dbgs()<< SEP_STR;
1070-
);
1036+
os << SEP_STR << "BlockPartitionState[reached=" << reached
1037+
<< ", needsUpdate=" << needsUpdate << "]\nid: ";
1038+
basicBlock->printID(os); os << "entry partition: ";
1039+
entryPartition.print(os); os << "exit partition: ";
1040+
exitPartition.print(os);
1041+
os << "instructions:\n┌──────────╼\n"; for (PartitionOp op
1042+
: blockPartitionOps) {
1043+
os << "";
1044+
op.print(os);
1045+
} os << "└──────────╼\nSuccs:\n";
1046+
for (auto succ
1047+
: basicBlock->getSuccessorBlocks()) {
1048+
os << "";
1049+
succ->printID(os);
1050+
} os
1051+
<< "Preds:\n";
1052+
for (auto pred
1053+
: basicBlock->getPredecessorBlocks()) {
1054+
os << "";
1055+
pred->printID(os);
1056+
} os
1057+
<< SEP_STR;);
10711058
}
10721059
};
10731060

@@ -1223,17 +1210,19 @@ class ConsumeRequireAccumulator {
12231210
}
12241211
}
12251212

1226-
void dump() const {
1213+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
1214+
1215+
void print(llvm::raw_ostream &os) const {
12271216
forEachConsumeRequire(
1228-
[](const PartitionOp& consumeOp, unsigned numProcessed, unsigned numSkipped) {
1229-
llvm::dbgs() << " ┌──╼ CONSUME: ";
1230-
consumeOp.dump();
1217+
[&](const PartitionOp &consumeOp, unsigned numProcessed,
1218+
unsigned numSkipped) {
1219+
os << " ┌──╼ CONSUME: ";
1220+
consumeOp.print(os);
12311221
},
1232-
[](const PartitionOp& requireOp) {
1233-
llvm::dbgs() << " ├╼ REQUIRE: ";
1234-
requireOp.dump();
1235-
}
1236-
);
1222+
[&](const PartitionOp &requireOp) {
1223+
os << " ├╼ REQUIRE: ";
1224+
requireOp.print(os);
1225+
});
12371226
}
12381227
};
12391228

@@ -1429,25 +1418,22 @@ class RaceTracer {
14291418
}
14301419

14311420
bool dumpBlockSearch(SILBasicBlock * SILBlock, TrackableValueID consumedVal) {
1432-
LLVM_DEBUG(
1433-
unsigned i = 0;
1434-
const BlockPartitionState &block = blockStates[SILBlock];
1435-
Partition working = block.getEntryPartition();
1436-
llvm::dbgs() << "┌──────────╼\n";
1437-
working.dump();
1438-
block.forEachPartitionOp([&](const PartitionOp &op) {
1439-
llvm::dbgs() << "├[" << i++ << "] ";
1440-
op.dump();
1441-
working.apply(op);
1442-
llvm::dbgs() << "";
1443-
if (working.isConsumed(consumedVal)) {
1444-
llvm::errs() << "(" << consumedVal << " CONSUMED) ";
1445-
}
1446-
working.dump();
1447-
return true;
1448-
});
1449-
llvm::dbgs() << "└──────────╼\n";
1450-
);
1421+
LLVM_DEBUG(unsigned i = 0;
1422+
const BlockPartitionState &block = blockStates[SILBlock];
1423+
Partition working = block.getEntryPartition();
1424+
llvm::dbgs() << "┌──────────╼\n"; working.print(llvm::dbgs());
1425+
block.forEachPartitionOp([&](const PartitionOp &op) {
1426+
llvm::dbgs() << "├[" << i++ << "] ";
1427+
op.print(llvm::dbgs());
1428+
working.apply(op);
1429+
llvm::dbgs() << "";
1430+
if (working.isConsumed(consumedVal)) {
1431+
llvm::dbgs() << "(" << consumedVal << " CONSUMED) ";
1432+
}
1433+
working.print(llvm::dbgs());
1434+
return true;
1435+
});
1436+
llvm::dbgs() << "└──────────╼\n";);
14511437
return false;
14521438
}
14531439

@@ -1624,10 +1610,8 @@ class PartitionAnalysis {
16241610
});
16251611
}
16261612

1627-
LLVM_DEBUG(
1628-
llvm::dbgs() << "Accumulator Complete:\n";
1629-
raceTracer.getAccumulator().dump();
1630-
);
1613+
LLVM_DEBUG(llvm::dbgs() << "Accumulator Complete:\n";
1614+
raceTracer.getAccumulator().print(llvm::dbgs()););
16311615

16321616
// ask the raceTracer to report diagnostics at the consumption sites
16331617
// for all the racy requirement sites entered into it above
@@ -1692,22 +1676,20 @@ class PartitionAnalysis {
16921676
}
16931677

16941678
public:
1679+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
16951680

1696-
void dump() LLVM_ATTRIBUTE_USED {
1697-
llvm::dbgs() << "\nPartitionAnalysis[fname=" << function->getName() << "]\n";
1681+
void print(llvm::raw_ostream &os) const {
1682+
os << "\nPartitionAnalysis[fname=" << function->getName() << "]\n";
16981683

16991684
for (auto [_, blockState] : blockStates) {
1700-
blockState.dump();
1685+
blockState.print(os);
17011686
}
17021687
}
17031688

17041689
static void performForFunction(SILFunction *function) {
17051690
auto analysis = PartitionAnalysis(function);
17061691
analysis.solve();
1707-
LLVM_DEBUG(
1708-
llvm::dbgs() << "SOLVED: ";
1709-
analysis.dump();
1710-
);
1692+
LLVM_DEBUG(llvm::dbgs() << "SOLVED: "; analysis.print(llvm::dbgs()););
17111693
analysis.diagnose();
17121694
}
17131695
};

0 commit comments

Comments
 (0)