From 71d3934badcf3f161164b3f75c01328f39c3a31a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 30 Apr 2002 20:52:49 +0000 Subject: [PATCH] Remove unneccesary pass git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2420 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/HoistPHIConstants.cpp | 86 ---------------------------- 1 file changed, 86 deletions(-) delete mode 100644 lib/Transforms/HoistPHIConstants.cpp diff --git a/lib/Transforms/HoistPHIConstants.cpp b/lib/Transforms/HoistPHIConstants.cpp deleted file mode 100644 index bdf2efc952b..00000000000 --- a/lib/Transforms/HoistPHIConstants.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===- llvm/Transforms/HoistPHIConstants.h - Normalize PHI nodes ------------=// -// -// HoistPHIConstants - Remove literal constants that are arguments of PHI nodes -// by inserting cast instructions in the preceeding basic blocks, and changing -// constant references into references of the casted value. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Transforms/HoistPHIConstants.h" -#include "llvm/iPHINode.h" -#include "llvm/iOther.h" -#include "llvm/BasicBlock.h" -#include "llvm/Function.h" -#include "llvm/Pass.h" - -typedef std::pair BBConstTy; -typedef std::map CachedCopyMap; - -static Value *NormalizePhiOperand(PHINode *PN, Value *CPV, - BasicBlock *Pred, CachedCopyMap &CopyCache) { - // Check if we've already inserted a copy for this constant in Pred - // Note that `copyCache[Pred]' will create an empty vector the first time - // - CachedCopyMap::iterator CCI = CopyCache.find(BBConstTy(Pred, CPV)); - if (CCI != CopyCache.end()) return CCI->second; - - // Create a copy instruction and add it to the cache... - CastInst *Inst = new CastInst(CPV, CPV->getType()); - CopyCache.insert(std::make_pair(BBConstTy(Pred, CPV), Inst)); - - // Insert the copy just before the terminator inst of the predecessor BB - assert(Pred->getTerminator() && "Degenerate BB encountered!"); - Pred->getInstList().insert(Pred->getInstList().end()-1, Inst); - - return Inst; -} - - -//--------------------------------------------------------------------------- -// Entry point for normalizing constant args in PHIs -//--------------------------------------------------------------------------- - -static bool doHoistPHIConstants(Function *M) { - CachedCopyMap Cache; - bool Changed = false; - - for (Function::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI) { - std::vector phis; // normalizing invalidates BB iterator - - for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) { - if (PHINode *PN = dyn_cast(*II)) - phis.push_back(PN); - else - break; // All PHIs occur at top of BB! - } - - for (std::vector::iterator PI=phis.begin(); PI != phis.end();++PI) - for (unsigned i = 0; i < (*PI)->getNumIncomingValues(); ++i) { - Value *Op = (*PI)->getIncomingValue(i); - - if (isa(Op)) { - (*PI)->setIncomingValue(i, - NormalizePhiOperand((*PI), - (*PI)->getIncomingValue(i), - (*PI)->getIncomingBlock(i), Cache)); - Changed = true; - } - } - } - - return Changed; -} - -namespace { - struct HoistPHIConstants : public FunctionPass { - const char *getPassName() const { return "Hoist Constants from PHI Nodes"; } - - virtual bool runOnFunction(Function *F) { return doHoistPHIConstants(F); } - - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.preservesCFG(); - } - }; -} - -Pass *createHoistPHIConstantsPass() { return new HoistPHIConstants(); } -- 2.34.1