Skip to content

Commit b6e072b

Browse files
authored
Merge pull request #25901 from atrick/debug-arc
ARCCodeMotion: add debug tracing.
2 parents d45dc38 + 8116c0b commit b6e072b

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

lib/SILOptimizer/Transforms/ARCCodeMotion.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ class CodeMotionContext {
180180
/// we compute the genset and killset.
181181
llvm::SmallPtrSet<SILBasicBlock *, 8> InterestBlocks;
182182

183+
#ifndef NDEBUG
184+
// SILPrintContext is used to print block IDs in RPO order.
185+
// It is optional so only the final insertion point interference is printed.
186+
Optional<SILPrintContext> printCtx;
187+
#endif
188+
183189
/// Return the rc-identity root of the SILValue.
184190
SILValue getRCRoot(SILValue R) {
185191
return RCFI->getRCIdentityRoot(R);
@@ -308,14 +314,23 @@ class RetainCodeMotionContext : public CodeMotionContext {
308314
return true;
309315
// Identical RC root blocks code motion, we will be able to move this retain
310316
// further once we move the blocking retain.
311-
if (isRetainInstruction(II) && getRCRoot(II) == Ptr)
317+
if (isRetainInstruction(II) && getRCRoot(II) == Ptr) {
318+
LLVM_DEBUG(if (printCtx) llvm::dbgs()
319+
<< "Retain " << Ptr << " at matching retain " << *II);
312320
return true;
321+
}
313322
// Ref count checks do not have side effects, but are barriers for retains.
314-
if (mayCheckRefCount(II))
323+
if (mayCheckRefCount(II)) {
324+
LLVM_DEBUG(if (printCtx) llvm::dbgs()
325+
<< "Retain " << Ptr << " at refcount check " << *II);
315326
return true;
327+
}
316328
// mayDecrement reference count stops code motion.
317-
if (mayDecrementRefCount(II, Ptr, AA))
329+
if (mayDecrementRefCount(II, Ptr, AA)) {
330+
LLVM_DEBUG(if (printCtx) llvm::dbgs()
331+
<< "Retain " << Ptr << " at may decrement " << *II);
318332
return true;
333+
}
319334
// This instruction does not block the retain code motion.
320335
return false;
321336
}
@@ -398,6 +413,8 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
398413
continue;
399414
RCRootIndex[Root] = RCRootVault.size();
400415
RCRootVault.insert(Root);
416+
LLVM_DEBUG(llvm::dbgs()
417+
<< "Retain Root #" << RCRootVault.size() << " " << Root);
401418
}
402419
}
403420

@@ -560,6 +577,9 @@ void RetainCodeMotionContext::convergeCodeMotionDataFlow() {
560577
}
561578

562579
void RetainCodeMotionContext::computeCodeMotionInsertPoints() {
580+
#ifndef NDEBUG
581+
printCtx.emplace(llvm::dbgs(), /*Verbose=*/false, /*Sorted=*/true);
582+
#endif
563583
// The BBSetOuts have converged, run last iteration and figure out
564584
// insertion point for each refcounted root.
565585
for (SILBasicBlock *BB : PO->getReversePostOrder()) {
@@ -667,11 +687,17 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
667687
return true;
668688
// Identical RC root blocks code motion, we will be able to move this release
669689
// further once we move the blocking release.
670-
if (isReleaseInstruction(II) && getRCRoot(II) == Ptr)
690+
if (isReleaseInstruction(II) && getRCRoot(II) == Ptr) {
691+
LLVM_DEBUG(if (printCtx) llvm::dbgs()
692+
<< "Release " << Ptr << " at matching release " << *II);
671693
return true;
694+
}
672695
// Stop at may interfere.
673-
if (mayHaveSymmetricInterference(II, Ptr, AA))
696+
if (mayHaveSymmetricInterference(II, Ptr, AA)) {
697+
LLVM_DEBUG(if (printCtx) llvm::dbgs()
698+
<< "Release " << Ptr << " at interference " << *II);
674699
return true;
700+
}
675701
// This instruction does not block the release.
676702
return false;
677703
}
@@ -771,6 +797,8 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
771797
continue;
772798
RCRootIndex[Root] = RCRootVault.size();
773799
RCRootVault.insert(Root);
800+
LLVM_DEBUG(llvm::dbgs()
801+
<< "Release Root #" << RCRootVault.size() << " " << Root);
774802
}
775803
if (MultiIteration && BB.getTerminator()->isFunctionExiting())
776804
Worklist.push_back(&BB);
@@ -972,6 +1000,10 @@ void ReleaseCodeMotionContext::convergeCodeMotionDataFlow() {
9721000
}
9731001

9741002
void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
1003+
#ifndef NDEBUG
1004+
printCtx.emplace(llvm::dbgs(), /*Verbose=*/false, /*Sorted=*/true);
1005+
#endif
1006+
9751007
// The BBSetIns have converged, run last iteration and figure out insertion
9761008
// point for each RC root.
9771009
for (SILBasicBlock *BB : PO->getPostOrder()) {
@@ -991,6 +1023,9 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
9911023
if (!SBB->BBSetIn[i])
9921024
continue;
9931025
InsertPoints[RCRootVault[i]].push_back(&*(*Succ).begin());
1026+
LLVM_DEBUG(llvm::dbgs()
1027+
<< "Release partial merge. Insert at successor: "
1028+
<< printCtx->getID(BB) << " " << RCRootVault[i]);
9941029
}
9951030
}
9961031

@@ -1010,6 +1045,9 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
10101045
if (!SBB->BBSetIn[i])
10111046
continue;
10121047
InsertPoints[RCRootVault[i]].push_back(&*(*Succ).begin());
1048+
LLVM_DEBUG(llvm::dbgs()
1049+
<< "Release terminator use. Insert at successor: "
1050+
<< printCtx->getID(BB) << " " << RCRootVault[i]);
10131051
}
10141052
S->BBSetOut.reset(i);
10151053
}

0 commit comments

Comments
 (0)