From b7f66977be8f5248b1638b796d8abff4b24e7915 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 18 Jan 2015 01:45:07 +0000 Subject: [PATCH] [PM] Lift the actual analyses used into the inferface rather than accepting a Pass and querying it for analyses. This is necessary to allow the utilities to work both with the old and new pass managers, and I also think this makes the interface much more clear and helps the reader know what analyses the utility can actually handle. I plan to repeat this process iteratively to clean up all the pass utilities. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226386 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Transforms/Utils/BasicBlockUtils.h | 4 +++- lib/Transforms/Utils/BasicBlockUtils.cpp | 17 +++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/llvm/Transforms/Utils/BasicBlockUtils.h b/include/llvm/Transforms/Utils/BasicBlockUtils.h index 19acf5b2db8..858323d051d 100644 --- a/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -23,6 +23,7 @@ namespace llvm { class AliasAnalysis; +class MemoryDependenceAnalysis; class DominatorTree; class Instruction; class MDNode; @@ -39,7 +40,8 @@ void DeleteDeadBlock(BasicBlock *BB); /// any single-entry PHI nodes 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, Pass *P = nullptr); +void FoldSingleEntryPHINodes(BasicBlock *BB, AliasAnalysis *AA = nullptr, + MemoryDependenceAnalysis *MemDep = nullptr); /// DeleteDeadPHIs - Examine each PHI in the given block and delete it if it /// is dead. Also recursively delete any operands that become dead as diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 867e4337cfc..29b5d2bb903 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -65,16 +65,10 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) { /// any single-entry PHI nodes 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 llvm::FoldSingleEntryPHINodes(BasicBlock *BB, Pass *P) { +void llvm::FoldSingleEntryPHINodes(BasicBlock *BB, AliasAnalysis *AA, + MemoryDependenceAnalysis *MemDep) { if (!isa(BB->begin())) return; - AliasAnalysis *AA = nullptr; - MemoryDependenceAnalysis *MemDep = nullptr; - if (P) { - AA = P->getAnalysisIfAvailable(); - MemDep = P->getAnalysisIfAvailable(); - } - while (PHINode *PN = dyn_cast(BB->begin())) { if (PN->getIncomingValue(0) != PN) PN->replaceAllUsesWith(PN->getIncomingValue(0)); @@ -148,8 +142,11 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) { } // Begin by getting rid of unneeded PHIs. - if (isa(BB->front())) - FoldSingleEntryPHINodes(BB, P); + if (isa(BB->front())) { + auto *AA = P ? P->getAnalysisIfAvailable() : nullptr; + auto *MemDep = P ? P->getAnalysisIfAvailable() : nullptr; + FoldSingleEntryPHINodes(BB, AA, MemDep); + } // Delete the unconditional branch from the predecessor... PredBB->getInstList().pop_back(); -- 2.34.1