# Changeset View

Changeset View

# Standalone View

Standalone View

# llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp

Show First 20 Lines • Show All 2747 Lines • ▼ Show 20 Line(s) | 2747 | for (unsigned PredNum = 0; PredNum < OpPHI->getNumOperands(); ++PredNum) { | |||
---|---|---|---|---|---|

2748 | auto *PredBB = OpPHI->getIncomingBlock(PredNum); | 2748 | auto *PredBB = OpPHI->getIncomingBlock(PredNum); | ||

2749 | Value *FoundVal = nullptr; | 2749 | Value *FoundVal = nullptr; | ||

2750 | // We could just skip unreachable edges entirely but it's tricky to do | 2750 | // We could just skip unreachable edges entirely but it's tricky to do | ||

2751 | // with rewriting existing phi nodes. | 2751 | // with rewriting existing phi nodes. | ||

2752 | if (ReachableEdges.count({PredBB, PHIBlock})) { | 2752 | if (ReachableEdges.count({PredBB, PHIBlock})) { | ||

2753 | // Clone the instruction, create an expression from it that is | 2753 | // Clone the instruction, create an expression from it that is | ||

2754 | // translated back into the predecessor, and see if we have a leader. | 2754 | // translated back into the predecessor, and see if we have a leader. | ||

2755 | Instruction *ValueOp = I->clone(); | 2755 | Instruction *ValueOp = I->clone(); | ||

2756 | SmallPtrSet<Value *, 4> CurrentDeps; | ||||

2756 | if (MemAccess) | 2757 | if (MemAccess) | ||

2757 | TempToMemory.insert({ValueOp, MemAccess}); | 2758 | TempToMemory.insert({ValueOp, MemAccess}); | ||

2758 | bool SafeForPHIOfOps = true; | 2759 | bool SafeForPHIOfOps = true; | ||

2759 | VisitedOps.clear(); | 2760 | VisitedOps.clear(); | ||

2760 | for (auto &Op : ValueOp->operands()) { | 2761 | for (auto &Op : ValueOp->operands()) { | ||

2761 | auto *OrigOp = &*Op; | 2762 | auto *OrigOp = &*Op; | ||

2762 | // When these operand changes, it could change whether there is a | 2763 | // When these operand changes, it could change whether there is a | ||

2763 | // leader for us or not, so we have to add additional users. | 2764 | // leader for us or not, so we have to add additional users. | ||

2764 | if (isa<PHINode>(Op)) { | 2765 | if (isa<PHINode>(Op)) { | ||

2765 | Op = Op->DoPHITranslation(PHIBlock, PredBB); | 2766 | Op = Op->DoPHITranslation(PHIBlock, PredBB); | ||

2766 | if (Op != OrigOp && Op != I) | 2767 | if (Op != OrigOp && Op != I) | ||

2767 | Deps.insert(Op); | 2768 | CurrentDeps.insert(Op); | ||

2768 | } else if (auto *ValuePHI = RealToTemp.lookup(Op)) { | 2769 | } else if (auto *ValuePHI = RealToTemp.lookup(Op)) { | ||

2769 | if (getBlockForValue(ValuePHI) == PHIBlock) | 2770 | if (getBlockForValue(ValuePHI) == PHIBlock) | ||

2770 | Op = ValuePHI->getIncomingValueForBlock(PredBB); | 2771 | Op = ValuePHI->getIncomingValueForBlock(PredBB); | ||

2771 | } | 2772 | } | ||

2772 | // If we phi-translated the op, it must be safe. | 2773 | // If we phi-translated the op, it must be safe. | ||

2773 | SafeForPHIOfOps = | 2774 | SafeForPHIOfOps = | ||

2774 | SafeForPHIOfOps && | 2775 | SafeForPHIOfOps && | ||

2775 | (Op != OrigOp || OpIsSafeForPHIOfOps(Op, PHIBlock, VisitedOps)); | 2776 | (Op != OrigOp || OpIsSafeForPHIOfOps(Op, PHIBlock, VisitedOps)); | ||

2776 | } | 2777 | } | ||

2777 | // FIXME: For those things that are not safe we could generate | 2778 | // FIXME: For those things that are not safe we could generate | ||

2778 | // expressions all the way down, and see if this comes out to a | 2779 | // expressions all the way down, and see if this comes out to a | ||

2779 | // constant. For anything where that is true, and unsafe, we should | 2780 | // constant. For anything where that is true, and unsafe, we should | ||

2780 | // have made a phi-of-ops (or value numbered it equivalent to something) | 2781 | // have made a phi-of-ops (or value numbered it equivalent to something) | ||

2781 | // for the pieces already. | 2782 | // for the pieces already. | ||

2782 | FoundVal = !SafeForPHIOfOps ? nullptr | 2783 | FoundVal = !SafeForPHIOfOps ? nullptr | ||

2783 | : findLeaderForInst(ValueOp, Visited, | 2784 | : findLeaderForInst(ValueOp, Visited, | ||

2784 | MemAccess, I, PredBB); | 2785 | MemAccess, I, PredBB); | ||

2785 | ValueOp->deleteValue(); | 2786 | ValueOp->deleteValue(); | ||

2786 | if (!FoundVal) | 2787 | if (!FoundVal) { | ||

2788 | // We failed to find a leader for the current ValueOp, but this might | ||||

2789 | // change in case of the translated operands change. | ||||

2790 | if (SafeForPHIOfOps) | ||||

2791 | for (auto Dep : CurrentDeps) | ||||

2792 | addAdditionalUsers(Dep, I); | ||||

2793 | | ||||

2787 | return nullptr; | 2794 | return nullptr; | ||

2795 | } | ||||

2796 | Deps.insert(CurrentDeps.begin(), CurrentDeps.end()); | ||||

2788 | } else { | 2797 | } else { | ||

2789 | DEBUG(dbgs() << "Skipping phi of ops operand for incoming block " | 2798 | DEBUG(dbgs() << "Skipping phi of ops operand for incoming block " | ||

2790 | << getBlockName(PredBB) | 2799 | << getBlockName(PredBB) | ||

2791 | << " because the block is unreachable\n"); | 2800 | << " because the block is unreachable\n"); | ||

2792 | FoundVal = UndefValue::get(I->getType()); | 2801 | FoundVal = UndefValue::get(I->getType()); | ||

2793 | RevisitOnReachabilityChange[PHIBlock].set(InstrToDFSNum(I)); | 2802 | RevisitOnReachabilityChange[PHIBlock].set(InstrToDFSNum(I)); | ||

2794 | } | 2803 | } | ||

2795 | 2804 | | |||

▲ Show 20 Lines • Show All 1462 Lines • Show Last 20 Lines |