diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/PHIElimination.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/PHIElimination.cpp | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/PHIElimination.cpp b/contrib/llvm-project/llvm/lib/CodeGen/PHIElimination.cpp index 54805584dbc1..77a6c37e1362 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/PHIElimination.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/PHIElimination.cpp @@ -107,6 +107,7 @@ namespace { using BBVRegPair = std::pair<unsigned, Register>; using VRegPHIUse = DenseMap<BBVRegPair, unsigned>; + // Count the number of non-undef PHI uses of each register in each BB. VRegPHIUse VRegPHIUseCount; // Defs of PHI sources which are implicit_def. @@ -426,9 +427,13 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, } // Adjust the VRegPHIUseCount map to account for the removal of this PHI node. - for (unsigned i = 1; i != MPhi->getNumOperands(); i += 2) - --VRegPHIUseCount[BBVRegPair(MPhi->getOperand(i+1).getMBB()->getNumber(), - MPhi->getOperand(i).getReg())]; + for (unsigned i = 1; i != MPhi->getNumOperands(); i += 2) { + if (!MPhi->getOperand(i).isUndef()) { + --VRegPHIUseCount[BBVRegPair( + MPhi->getOperand(i + 1).getMBB()->getNumber(), + MPhi->getOperand(i).getReg())]; + } + } // Now loop over all of the incoming arguments, changing them to copy into the // IncomingReg register in the corresponding predecessor basic block. @@ -461,6 +466,15 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, assert(MRI->use_empty(SrcReg) && "Expected a single use from UnspillableTerminator"); SrcRegDef->getOperand(0).setReg(IncomingReg); + + // Update LiveVariables. + if (LV) { + LiveVariables::VarInfo &SrcVI = LV->getVarInfo(SrcReg); + LiveVariables::VarInfo &IncomingVI = LV->getVarInfo(IncomingReg); + IncomingVI.AliveBlocks = std::move(SrcVI.AliveBlocks); + SrcVI.AliveBlocks.clear(); + } + continue; } @@ -515,9 +529,8 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, // case, we should mark the last such terminator as being the killing // block, not the copy. MachineBasicBlock::iterator KillInst = opBlock.end(); - MachineBasicBlock::iterator FirstTerm = opBlock.getFirstTerminator(); - for (MachineBasicBlock::iterator Term = FirstTerm; - Term != opBlock.end(); ++Term) { + for (MachineBasicBlock::iterator Term = InsertPos; Term != opBlock.end(); + ++Term) { if (Term->readsRegister(SrcReg)) KillInst = Term; } @@ -527,7 +540,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, if (reusedIncoming || !IncomingReg) { // We may have to rewind a bit if we didn't insert a copy this time. - KillInst = FirstTerm; + KillInst = InsertPos; while (KillInst != opBlock.begin()) { --KillInst; if (KillInst->isDebugInstr()) @@ -574,9 +587,8 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, if (!isLiveOut) { MachineBasicBlock::iterator KillInst = opBlock.end(); - MachineBasicBlock::iterator FirstTerm = opBlock.getFirstTerminator(); - for (MachineBasicBlock::iterator Term = FirstTerm; - Term != opBlock.end(); ++Term) { + for (MachineBasicBlock::iterator Term = InsertPos; + Term != opBlock.end(); ++Term) { if (Term->readsRegister(SrcReg)) KillInst = Term; } @@ -586,7 +598,7 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, if (reusedIncoming || !IncomingReg) { // We may have to rewind a bit if we didn't just insert a copy. - KillInst = FirstTerm; + KillInst = InsertPos; while (KillInst != opBlock.begin()) { --KillInst; if (KillInst->isDebugInstr()) @@ -623,14 +635,19 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB, /// used in a PHI node. We map that to the BB the vreg is coming from. This is /// used later to determine when the vreg is killed in the BB. void PHIElimination::analyzePHINodes(const MachineFunction& MF) { - for (const auto &MBB : MF) + for (const auto &MBB : MF) { for (const auto &BBI : MBB) { if (!BBI.isPHI()) break; - for (unsigned i = 1, e = BBI.getNumOperands(); i != e; i += 2) - ++VRegPHIUseCount[BBVRegPair(BBI.getOperand(i+1).getMBB()->getNumber(), - BBI.getOperand(i).getReg())]; + for (unsigned i = 1, e = BBI.getNumOperands(); i != e; i += 2) { + if (!BBI.getOperand(i).isUndef()) { + ++VRegPHIUseCount[BBVRegPair( + BBI.getOperand(i + 1).getMBB()->getNumber(), + BBI.getOperand(i).getReg())]; + } + } } + } } bool PHIElimination::SplitPHIEdges(MachineFunction &MF, |
