From 082fe7185eb140d5425f2316ac457bac56a0bad3 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 4 Jun 2007 23:28:33 +0000 Subject: [PATCH] Fix a bunch of small bugs, and improve the debugging output significantly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37424 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVNPRE.cpp | 70 ++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/Transforms/Scalar/GVNPRE.cpp b/lib/Transforms/Scalar/GVNPRE.cpp index 1105e70aa3d..4f327663c1c 100644 --- a/lib/Transforms/Scalar/GVNPRE.cpp +++ b/lib/Transforms/Scalar/GVNPRE.cpp @@ -138,15 +138,19 @@ Value* GVNPRE::phi_translate(ValueTable& VN, std::set& MS, return 0; if (BinaryOperator* BO = dyn_cast(V)) { - Value* newOp1 = phi_translate(VN, MS, set, + Value* newOp1 = isa(BO->getOperand(0)) + ? phi_translate(VN, MS, set, find_leader(VN, set, VN[BO->getOperand(0)]), - pred); + pred) + : BO->getOperand(0); if (newOp1 == 0) return 0; - Value* newOp2 = phi_translate(VN, MS, set, - find_leader(VN, set, VN[BO->getOperand(1)]), - pred); + Value* newOp2 = isa(BO->getOperand(1)) + ? phi_translate(VN, MS, set, + find_leader(VN, set, VN[BO->getOperand(0)]), + pred) + : BO->getOperand(1); if (newOp2 == 0) return 0; @@ -303,8 +307,10 @@ void GVNPRE::CalculateAvailOut(GVNPRE::ValueTable& VN, std::set& add(VN, MS, BO); - currExps.insert(leftValue); - currExps.insert(rightValue); + if (isa(leftValue)) + currExps.insert(leftValue); + if (isa(rightValue)) + currExps.insert(rightValue); currExps.insert(BO); currTemps.insert(BO); @@ -365,7 +371,13 @@ bool GVNPRE::runOnFunction(Function &F) { df_begin(PDT.getRootNode()), E = df_end(DT.getRootNode()); PDI != E; ++PDI) { BasicBlock* BB = PDI->getBlock(); - + DOUT << "Block: " << BB->getName() << "\n"; + DOUT << "TMP_GEN: "; + dump(VN, generatedTemporaries[BB]); + DOUT << "\n"; + + DOUT << "EXP_GEN: "; + dump_unique(VN, generatedExpressions[BB]); visited.insert(BB); std::set& anticIn = anticipatedIn[BB]; @@ -373,31 +385,33 @@ bool GVNPRE::runOnFunction(Function &F) { if (BB->getTerminator()->getNumSuccessors() == 1) { if (visited.find(BB) == visited.end()) - phi_translate_set(VN, maximalSet, anticIn, BB, anticOut); + phi_translate_set(VN, maximalSet, maximalSet, BB, anticOut); else - phi_translate_set(VN, anticIn, anticIn, BB, anticOut); + phi_translate_set(VN, maximalSet, anticipatedIn[BB->getTerminator()->getSuccessor(0)], BB, anticOut); } else if (BB->getTerminator()->getNumSuccessors() > 1) { - for (unsigned i = 0; i < BB->getTerminator()->getNumSuccessors(); ++i) { + BasicBlock* first = BB->getTerminator()->getSuccessor(0); + anticOut.insert(anticipatedIn[first].begin(), + anticipatedIn[first].end()); + for (unsigned i = 1; i < BB->getTerminator()->getNumSuccessors(); ++i) { BasicBlock* currSucc = BB->getTerminator()->getSuccessor(i); + std::set& succAnticIn = anticipatedIn[currSucc]; + std::set temp; - if (visited.find(currSucc) == visited.end()) - temp.insert(maximalSet.begin(), maximalSet.end()); - else - temp.insert(anticIn.begin(), anticIn.end()); - - anticIn.clear(); - std::insert_iterator > ai_ins(anticIn, - anticIn.begin()); - - std::set_difference(anticipatedIn[currSucc].begin(), - anticipatedIn[currSucc].end(), - temp.begin(), - temp.end(), - ai_ins, - ExprLT()); + std::insert_iterator > temp_ins(temp, + temp.begin()); + std::set_intersection(anticOut.begin(), anticOut.end(), + succAnticIn.begin(), succAnticIn.end(), + temp_ins, ExprLT()); + + anticOut.clear(); + anticOut.insert(temp.begin(), temp.end()); } } + DOUT << "ANTIC_OUT: "; + dump_unique(VN, anticOut); + DOUT << "\n"; + std::set S; std::insert_iterator > s_ins(S, S.begin()); std::set_union(anticOut.begin(), anticOut.end(), @@ -416,6 +430,10 @@ bool GVNPRE::runOnFunction(Function &F) { clean(VN, anticIn); + DOUT << "ANTIC_IN: "; + dump_unique(VN, anticIn); + DOUT << "\n"; + if (old != anticIn) changed = true; -- 2.34.1