|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "swift/SIL/BasicBlockUtils.h"
|
| 14 | +#include "swift/SIL/BasicBlockDatastructures.h" |
14 | 15 | #include "swift/Basic/Defer.h"
|
15 | 16 | #include "swift/Basic/STLExtras.h"
|
16 | 17 | #include "swift/SIL/Dominance.h"
|
@@ -521,3 +522,38 @@ void swift::findJointPostDominatingSet(
|
521 | 522 | }
|
522 | 523 | }
|
523 | 524 | }
|
| 525 | + |
| 526 | +//===----------------------------------------------------------------------===// |
| 527 | +// checkReachingBlockDominance |
| 528 | +//===----------------------------------------------------------------------===// |
| 529 | + |
| 530 | +#ifndef NDEBUG |
| 531 | +/// Check that \p sourceBlock dominates \p destBlock. |
| 532 | +/// |
| 533 | +/// Useful for *temporary* assertions when Dominance is unavailable. This is |
| 534 | +/// worst case O(numberOfBlocksInFunction). It should only be used when \p |
| 535 | +/// sourceBlock is expected to be "close to" \p destBlock in almost all |
| 536 | +/// cases. Because of the potential for quadratic behavior, it should only be |
| 537 | +/// used during feature development, never as a permanent check. If a dominance |
| 538 | +/// check is required for correctness, then DominanceInfo should be passed down |
| 539 | +/// to the utility function that needs this check. |
| 540 | +bool |
| 541 | +swift::checkDominates(SILBasicBlock *sourceBlock, SILBasicBlock *destBlock) { |
| 542 | + SILBasicBlock *entryBlock = sourceBlock->getParent()->getEntryBlock(); |
| 543 | + BasicBlockWorklist worklist(destBlock); |
| 544 | + bool reaches = false; |
| 545 | + while (SILBasicBlock *block = worklist.pop()) { |
| 546 | + if (block == sourceBlock) { |
| 547 | + reaches = true; |
| 548 | + continue; |
| 549 | + } |
| 550 | + if (block == entryBlock) { |
| 551 | + return false; // does not dominate |
| 552 | + } |
| 553 | + for (auto *predBlock : block->getPredecessorBlocks()) { |
| 554 | + worklist.pushIfNotVisited(predBlock); |
| 555 | + } |
| 556 | + } |
| 557 | + return reaches; |
| 558 | +} |
| 559 | +#endif |
0 commit comments