Skip to content

Commit f91b892

Browse files
authored
Merge pull request #60053 from ktoso/wip-sil-branch-names
[SILPrinter] print target branch debug names in SIL dumps
2 parents 7a2e6d8 + b63770b commit f91b892

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
894894
llvm::SmallVector<SILValue, 8> values;
895895
llvm::copy(inst->getResults(), std::back_inserter(values));
896896
printUserList(values, inst);
897+
printBranchTargets(inst);
897898
}
898899

899900
void printUserList(ArrayRef<SILValue> values, SILNodePointer node) {
@@ -937,6 +938,31 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
937938
[&] { *this << ", "; });
938939
}
939940

941+
void printBranchTargets(const SILInstruction *inst) {
942+
if (auto condBr = dyn_cast<CondBranchInst>(inst)) {
943+
if (condBr->getTrueBB()->getDebugName().hasValue()) {
944+
*this << ", true->" << condBr->getTrueBB()->getDebugName().getValue();
945+
}
946+
if (condBr->getFalseBB()->getDebugName().hasValue()) {
947+
*this << ", false->" << condBr->getFalseBB()->getDebugName().getValue();
948+
}
949+
} else if (auto br = dyn_cast<BranchInst>(inst)) {
950+
if (br->getDestBB()->getDebugName().hasValue()) {
951+
*this << ", dest->" << br->getDestBB()->getDebugName().getValue();
952+
}
953+
} else if (auto termInst = dyn_cast<TermInst>(inst)) {
954+
// Otherwise, we just print the successors in order without pretty printing
955+
for (unsigned i = 0, numSuccessors = termInst->getSuccessors().size();
956+
i != numSuccessors; ++i) {
957+
auto &successor = termInst->getSuccessors()[i];
958+
if (successor.getBB()->getDebugName().hasValue()) {
959+
*this << ", #" << i
960+
<< "->" << successor.getBB()->getDebugName().getValue();
961+
}
962+
}
963+
}
964+
}
965+
940966
void printConformances(ArrayRef<ProtocolConformanceRef> conformances) {
941967
// FIXME: conformances should always be printed and parsed!
942968
if (!Ctx.printVerbose()) {

0 commit comments

Comments
 (0)