Skip to content

Commit

Permalink
[RS4GC] Lazily set changed flag when folding single entry phis
Browse files Browse the repository at this point in the history
The function FoldSingleEntryPHINodes() is changed to return if
it has changed IR or not. This return value is used by RS4GC to
set the MadeChange flag respectively.

Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D93810
  • Loading branch information
Yevgeny Rouban committed Dec 28, 2020
1 parent 9d70dbd commit d76c1d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
Expand Up @@ -74,7 +74,7 @@ bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU = nullptr,
/// in it, fold them away. This handles the case when all entries to the PHI
/// nodes in a block are guaranteed equal, such as when the block has exactly
/// one predecessor.
void FoldSingleEntryPHINodes(BasicBlock *BB,
bool FoldSingleEntryPHINodes(BasicBlock *BB,
MemoryDependenceResults *MemDep = nullptr);

/// Examine each PHI in the given block and delete it if it is dead. Also
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
Expand Up @@ -2735,10 +2735,8 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT,
// of liveness sets for no good reason. It may be harder to do this post
// insertion since relocations and base phis can confuse things.
for (BasicBlock &BB : F)
if (BB.getUniquePredecessor()) {
MadeChange = true;
FoldSingleEntryPHINodes(&BB);
}
if (BB.getUniquePredecessor())
MadeChange |= FoldSingleEntryPHINodes(&BB);

// Before we start introducing relocations, we want to tweak the IR a bit to
// avoid unfortunate code generation effects. The main example is that we
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Expand Up @@ -136,9 +136,10 @@ bool llvm::EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
return !DeadBlocks.empty();
}

void llvm::FoldSingleEntryPHINodes(BasicBlock *BB,
bool llvm::FoldSingleEntryPHINodes(BasicBlock *BB,
MemoryDependenceResults *MemDep) {
if (!isa<PHINode>(BB->begin())) return;
if (!isa<PHINode>(BB->begin()))
return false;

while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
if (PN->getIncomingValue(0) != PN)
Expand All @@ -151,6 +152,7 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB,

PN->eraseFromParent();
}
return true;
}

bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI,
Expand Down

0 comments on commit d76c1d2

Please sign in to comment.