mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	Tail duplication should zap a copy it inserted for SSA update if the copy is the only use of its source.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91390 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -90,7 +90,8 @@ namespace {
 | 
				
			|||||||
                              SmallSetVector<MachineBasicBlock*, 8> &Succs);
 | 
					                              SmallSetVector<MachineBasicBlock*, 8> &Succs);
 | 
				
			||||||
    bool TailDuplicateBlocks(MachineFunction &MF);
 | 
					    bool TailDuplicateBlocks(MachineFunction &MF);
 | 
				
			||||||
    bool TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
					    bool TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			||||||
                       SmallVector<MachineBasicBlock*, 8> &TDBBs);
 | 
					                       SmallVector<MachineBasicBlock*, 8> &TDBBs,
 | 
				
			||||||
 | 
					                       SmallVector<MachineInstr*, 16> &Copies);
 | 
				
			||||||
    void RemoveDeadBlock(MachineBasicBlock *MBB);
 | 
					    void RemoveDeadBlock(MachineBasicBlock *MBB);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -194,7 +195,8 @@ bool TailDuplicatePass::TailDuplicateBlocks(MachineFunction &MF) {
 | 
				
			|||||||
                                                MBB->succ_end());
 | 
					                                                MBB->succ_end());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SmallVector<MachineBasicBlock*, 8> TDBBs;
 | 
					    SmallVector<MachineBasicBlock*, 8> TDBBs;
 | 
				
			||||||
    if (TailDuplicate(MBB, MF, TDBBs)) {
 | 
					    SmallVector<MachineInstr*, 16> Copies;
 | 
				
			||||||
 | 
					    if (TailDuplicate(MBB, MF, TDBBs, Copies)) {
 | 
				
			||||||
      ++NumTails;
 | 
					      ++NumTails;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // TailBB's immediate successors are now successors of those predecessors
 | 
					      // TailBB's immediate successors are now successors of those predecessors
 | 
				
			||||||
@@ -251,6 +253,21 @@ bool TailDuplicatePass::TailDuplicateBlocks(MachineFunction &MF) {
 | 
				
			|||||||
        SSAUpdateVals.clear();
 | 
					        SSAUpdateVals.clear();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      // Eliminate some of the copies inserted tail duplication to maintain
 | 
				
			||||||
 | 
					      // SSA form.
 | 
				
			||||||
 | 
					      for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
 | 
				
			||||||
 | 
					        MachineInstr *Copy = Copies[i];
 | 
				
			||||||
 | 
					        unsigned Src, Dst, SrcSR, DstSR;
 | 
				
			||||||
 | 
					        if (TII->isMoveInstr(*Copy, Src, Dst, SrcSR, DstSR)) {
 | 
				
			||||||
 | 
					          MachineRegisterInfo::use_iterator UI = MRI->use_begin(Src);
 | 
				
			||||||
 | 
					          if (++UI == MRI->use_end()) {
 | 
				
			||||||
 | 
					            // Copy is the only use. Do trivial copy propagation here.
 | 
				
			||||||
 | 
					            MRI->replaceRegWith(Dst, Src);
 | 
				
			||||||
 | 
					            Copy->eraseFromParent();
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (PreRegAlloc && TailDupVerify)
 | 
					      if (PreRegAlloc && TailDupVerify)
 | 
				
			||||||
        VerifyPHIs(MF, false);
 | 
					        VerifyPHIs(MF, false);
 | 
				
			||||||
      MadeChange = true;
 | 
					      MadeChange = true;
 | 
				
			||||||
@@ -418,7 +435,8 @@ TailDuplicatePass::UpdateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead,
 | 
				
			|||||||
/// of its predecessors.
 | 
					/// of its predecessors.
 | 
				
			||||||
bool
 | 
					bool
 | 
				
			||||||
TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
					TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			||||||
                                 SmallVector<MachineBasicBlock*, 8> &TDBBs) {
 | 
					                                 SmallVector<MachineBasicBlock*, 8> &TDBBs,
 | 
				
			||||||
 | 
					                                 SmallVector<MachineInstr*, 16> &Copies) {
 | 
				
			||||||
  // Don't try to tail-duplicate single-block loops.
 | 
					  // Don't try to tail-duplicate single-block loops.
 | 
				
			||||||
  if (TailBB->isSuccessor(TailBB))
 | 
					  if (TailBB->isSuccessor(TailBB))
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
@@ -502,7 +520,7 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // Clone the contents of TailBB into PredBB.
 | 
					    // Clone the contents of TailBB into PredBB.
 | 
				
			||||||
    DenseMap<unsigned, unsigned> LocalVRMap;
 | 
					    DenseMap<unsigned, unsigned> LocalVRMap;
 | 
				
			||||||
    SmallVector<std::pair<unsigned,unsigned>, 4> Copies;
 | 
					    SmallVector<std::pair<unsigned,unsigned>, 4> CopyInfos;
 | 
				
			||||||
    MachineBasicBlock::iterator I = TailBB->begin();
 | 
					    MachineBasicBlock::iterator I = TailBB->begin();
 | 
				
			||||||
    while (I != TailBB->end()) {
 | 
					    while (I != TailBB->end()) {
 | 
				
			||||||
      MachineInstr *MI = &*I;
 | 
					      MachineInstr *MI = &*I;
 | 
				
			||||||
@@ -510,7 +528,7 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			|||||||
      if (MI->getOpcode() == TargetInstrInfo::PHI) {
 | 
					      if (MI->getOpcode() == TargetInstrInfo::PHI) {
 | 
				
			||||||
        // Replace the uses of the def of the PHI with the register coming
 | 
					        // Replace the uses of the def of the PHI with the register coming
 | 
				
			||||||
        // from PredBB.
 | 
					        // from PredBB.
 | 
				
			||||||
        ProcessPHI(MI, TailBB, PredBB, LocalVRMap, Copies);
 | 
					        ProcessPHI(MI, TailBB, PredBB, LocalVRMap, CopyInfos);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        // Replace def of virtual registers with new registers, and update
 | 
					        // Replace def of virtual registers with new registers, and update
 | 
				
			||||||
        // uses with PHI source register or the new registers.
 | 
					        // uses with PHI source register or the new registers.
 | 
				
			||||||
@@ -518,9 +536,12 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    MachineBasicBlock::iterator Loc = PredBB->getFirstTerminator();
 | 
					    MachineBasicBlock::iterator Loc = PredBB->getFirstTerminator();
 | 
				
			||||||
    for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
 | 
					    for (unsigned i = 0, e = CopyInfos.size(); i != e; ++i) {
 | 
				
			||||||
      const TargetRegisterClass *RC = MRI->getRegClass(Copies[i].first);
 | 
					      const TargetRegisterClass *RC = MRI->getRegClass(CopyInfos[i].first);
 | 
				
			||||||
      TII->copyRegToReg(*PredBB, Loc, Copies[i].first, Copies[i].second, RC, RC);
 | 
					      TII->copyRegToReg(*PredBB, Loc, CopyInfos[i].first,
 | 
				
			||||||
 | 
					                        CopyInfos[i].second, RC,RC);
 | 
				
			||||||
 | 
					      MachineInstr *CopyMI = prior(Loc);
 | 
				
			||||||
 | 
					      Copies.push_back(CopyMI);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    NumInstrDups += TailBB->size() - 1; // subtract one for removed branch
 | 
					    NumInstrDups += TailBB->size() - 1; // subtract one for removed branch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -553,14 +574,14 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			|||||||
          << "From MBB: " << *TailBB);
 | 
					          << "From MBB: " << *TailBB);
 | 
				
			||||||
    if (PreRegAlloc) {
 | 
					    if (PreRegAlloc) {
 | 
				
			||||||
      DenseMap<unsigned, unsigned> LocalVRMap;
 | 
					      DenseMap<unsigned, unsigned> LocalVRMap;
 | 
				
			||||||
      SmallVector<std::pair<unsigned,unsigned>, 4> Copies;
 | 
					      SmallVector<std::pair<unsigned,unsigned>, 4> CopyInfos;
 | 
				
			||||||
      MachineBasicBlock::iterator I = TailBB->begin();
 | 
					      MachineBasicBlock::iterator I = TailBB->begin();
 | 
				
			||||||
      // Process PHI instructions first.
 | 
					      // Process PHI instructions first.
 | 
				
			||||||
      while (I != TailBB->end() && I->getOpcode() == TargetInstrInfo::PHI) {
 | 
					      while (I != TailBB->end() && I->getOpcode() == TargetInstrInfo::PHI) {
 | 
				
			||||||
        // Replace the uses of the def of the PHI with the register coming
 | 
					        // Replace the uses of the def of the PHI with the register coming
 | 
				
			||||||
        // from PredBB.
 | 
					        // from PredBB.
 | 
				
			||||||
        MachineInstr *MI = &*I++;
 | 
					        MachineInstr *MI = &*I++;
 | 
				
			||||||
        ProcessPHI(MI, TailBB, PrevBB, LocalVRMap, Copies);
 | 
					        ProcessPHI(MI, TailBB, PrevBB, LocalVRMap, CopyInfos);
 | 
				
			||||||
        if (MI->getParent())
 | 
					        if (MI->getParent())
 | 
				
			||||||
          MI->eraseFromParent();
 | 
					          MI->eraseFromParent();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -574,9 +595,12 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
 | 
				
			|||||||
        MI->eraseFromParent();
 | 
					        MI->eraseFromParent();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      MachineBasicBlock::iterator Loc = PrevBB->getFirstTerminator();
 | 
					      MachineBasicBlock::iterator Loc = PrevBB->getFirstTerminator();
 | 
				
			||||||
      for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
 | 
					      for (unsigned i = 0, e = CopyInfos.size(); i != e; ++i) {
 | 
				
			||||||
        const TargetRegisterClass *RC = MRI->getRegClass(Copies[i].first);
 | 
					        const TargetRegisterClass *RC = MRI->getRegClass(CopyInfos[i].first);
 | 
				
			||||||
        TII->copyRegToReg(*PrevBB, Loc, Copies[i].first, Copies[i].second, RC, RC);
 | 
					        TII->copyRegToReg(*PrevBB, Loc, CopyInfos[i].first,
 | 
				
			||||||
 | 
					                          CopyInfos[i].second, RC, RC);
 | 
				
			||||||
 | 
					        MachineInstr *CopyMI = prior(Loc);
 | 
				
			||||||
 | 
					        Copies.push_back(CopyMI);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      // No PHIs to worry about, just splice the instructions over.
 | 
					      // No PHIs to worry about, just splice the instructions over.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user