llvm.org GIT mirror llvm / 5da2c85
Merge from mainline because Owen said so. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_21@42080 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 13 years ago
1 changed file(s) with 16 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
672672 void dump(DenseMap& d);
673673 bool iterateOnFunction(Function &F);
674674 Value* CollapsePhi(PHINode* p);
675 bool isSafeReplacement(PHINode* p, Instruction* inst);
675676 };
676677
677678 char GVN::ID = 0;
730731 if (constVal) {
731732 if (Instruction* inst = dyn_cast(constVal)) {
732733 if (DT.dominates(inst, p))
733 return inst;
734 if (isSafeReplacement(p, inst))
735 return inst;
734736 } else {
735737 return constVal;
736738 }
737739 }
738740
739741 return 0;
742 }
743
744 bool GVN::isSafeReplacement(PHINode* p, Instruction* inst) {
745 if (!isa(inst))
746 return true;
747
748 for (Instruction::use_iterator UI = p->use_begin(), E = p->use_end();
749 UI != E; ++UI)
750 if (PHINode* use_phi = dyn_cast(UI))
751 if (use_phi->getParent() == inst->getParent())
752 return false;
753
754 return true;
740755 }
741756
742757 /// GetValueForBlock - Get the value to use within the specified basic block.