@@ -180,6 +180,12 @@ class CodeMotionContext {
180
180
// / we compute the genset and killset.
181
181
llvm::SmallPtrSet<SILBasicBlock *, 8 > InterestBlocks;
182
182
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
+
183
189
// / Return the rc-identity root of the SILValue.
184
190
SILValue getRCRoot (SILValue R) {
185
191
return RCFI->getRCIdentityRoot (R);
@@ -308,14 +314,23 @@ class RetainCodeMotionContext : public CodeMotionContext {
308
314
return true ;
309
315
// Identical RC root blocks code motion, we will be able to move this retain
310
316
// 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);
312
320
return true ;
321
+ }
313
322
// 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);
315
326
return true ;
327
+ }
316
328
// 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);
318
332
return true ;
333
+ }
319
334
// This instruction does not block the retain code motion.
320
335
return false ;
321
336
}
@@ -398,6 +413,8 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
398
413
continue ;
399
414
RCRootIndex[Root] = RCRootVault.size ();
400
415
RCRootVault.insert (Root);
416
+ LLVM_DEBUG (llvm::dbgs ()
417
+ << " Retain Root #" << RCRootVault.size () << " " << Root);
401
418
}
402
419
}
403
420
@@ -560,6 +577,9 @@ void RetainCodeMotionContext::convergeCodeMotionDataFlow() {
560
577
}
561
578
562
579
void RetainCodeMotionContext::computeCodeMotionInsertPoints () {
580
+ #ifndef NDEBUG
581
+ printCtx.emplace (llvm::dbgs (), /* Verbose=*/ false , /* Sorted=*/ true );
582
+ #endif
563
583
// The BBSetOuts have converged, run last iteration and figure out
564
584
// insertion point for each refcounted root.
565
585
for (SILBasicBlock *BB : PO->getReversePostOrder ()) {
@@ -667,11 +687,17 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
667
687
return true ;
668
688
// Identical RC root blocks code motion, we will be able to move this release
669
689
// 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);
671
693
return true ;
694
+ }
672
695
// 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);
674
699
return true ;
700
+ }
675
701
// This instruction does not block the release.
676
702
return false ;
677
703
}
@@ -771,6 +797,8 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
771
797
continue ;
772
798
RCRootIndex[Root] = RCRootVault.size ();
773
799
RCRootVault.insert (Root);
800
+ LLVM_DEBUG (llvm::dbgs ()
801
+ << " Release Root #" << RCRootVault.size () << " " << Root);
774
802
}
775
803
if (MultiIteration && BB.getTerminator ()->isFunctionExiting ())
776
804
Worklist.push_back (&BB);
@@ -972,6 +1000,10 @@ void ReleaseCodeMotionContext::convergeCodeMotionDataFlow() {
972
1000
}
973
1001
974
1002
void ReleaseCodeMotionContext::computeCodeMotionInsertPoints () {
1003
+ #ifndef NDEBUG
1004
+ printCtx.emplace (llvm::dbgs (), /* Verbose=*/ false , /* Sorted=*/ true );
1005
+ #endif
1006
+
975
1007
// The BBSetIns have converged, run last iteration and figure out insertion
976
1008
// point for each RC root.
977
1009
for (SILBasicBlock *BB : PO->getPostOrder ()) {
@@ -991,6 +1023,9 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
991
1023
if (!SBB->BBSetIn [i])
992
1024
continue ;
993
1025
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]);
994
1029
}
995
1030
}
996
1031
@@ -1010,6 +1045,9 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
1010
1045
if (!SBB->BBSetIn [i])
1011
1046
continue ;
1012
1047
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]);
1013
1051
}
1014
1052
S->BBSetOut .reset (i);
1015
1053
}
0 commit comments