Skip to content

Commit a293573

Browse files
authored
[SSAUpdater] Only iterate blocks modified by CheckIfPHIMatches() in RecordMatchingPHIs() (#153596)
In #100281, we use `TaggedBlocks` to record blocks modified by `CheckIfPHIMatche()`, so do not need to clear every block in `BlockList` if `CheckIfPHIMatches()` match failed. If `CheckIfPHIMatches()` match succeed, we can reuse `TaggedBlocks` to only record matching PHIs for modified blocks, avoid checking every block in `BlockList` to see if `PHITag` is set.
1 parent 2692ff8 commit a293573

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ class SSAUpdaterImpl {
366366
continue;
367367

368368
// Look for an existing PHI.
369-
FindExistingPHI(Info->BB, BlockList);
369+
FindExistingPHI(Info->BB);
370370
if (Info->AvailableVal)
371371
continue;
372372

@@ -412,19 +412,19 @@ class SSAUpdaterImpl {
412412

413413
/// FindExistingPHI - Look through the PHI nodes in a block to see if any of
414414
/// them match what is needed.
415-
void FindExistingPHI(BlkT *BB, BlockListTy *BlockList) {
415+
void FindExistingPHI(BlkT *BB) {
416416
SmallVector<BBInfo *, 20> TaggedBlocks;
417417
for (auto &SomePHI : BB->phis()) {
418418
if (CheckIfPHIMatches(&SomePHI, TaggedBlocks)) {
419-
RecordMatchingPHIs(BlockList);
419+
RecordMatchingPHIs(TaggedBlocks);
420420
break;
421421
}
422422
}
423423
}
424424

425425
/// CheckIfPHIMatches - Check if a PHI node matches the placement and values
426426
/// in the BBMap.
427-
bool CheckIfPHIMatches(PhiT *PHI, SmallVectorImpl<BBInfo *> &TaggedBlocks) {
427+
bool CheckIfPHIMatches(PhiT *PHI, BlockListTy &TaggedBlocks) {
428428
// Match failed: clear all the PHITag values. Only need to clear visited
429429
// blocks.
430430
auto Cleanup = make_scope_exit([&]() {
@@ -484,15 +484,15 @@ class SSAUpdaterImpl {
484484

485485
/// RecordMatchingPHIs - For each PHI node that matches, record it in both
486486
/// the BBMap and the AvailableVals mapping.
487-
void RecordMatchingPHIs(BlockListTy *BlockList) {
488-
for (typename BlockListTy::iterator I = BlockList->begin(),
489-
E = BlockList->end(); I != E; ++I)
490-
if (PhiT *PHI = (*I)->PHITag) {
491-
BlkT *BB = PHI->getParent();
492-
ValT PHIVal = Traits::GetPHIValue(PHI);
493-
(*AvailableVals)[BB] = PHIVal;
494-
BBMap[BB]->AvailableVal = PHIVal;
495-
}
487+
void RecordMatchingPHIs(BlockListTy &TaggedBlocks) {
488+
for (BBInfo *Block : TaggedBlocks) {
489+
PhiT *PHI = Block->PHITag;
490+
assert(PHI && "PHITag didn't set?");
491+
BlkT *BB = PHI->getParent();
492+
ValT PHIVal = Traits::GetPHIValue(PHI);
493+
(*AvailableVals)[BB] = PHIVal;
494+
BBMap[BB]->AvailableVal = PHIVal;
495+
}
496496
}
497497
};
498498

0 commit comments

Comments
 (0)