diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2011-03-08 22:46:11 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2011-03-08 22:46:11 +0000 |
commit | 5881799d0cccbd814ec1b0f0509df9be1f63c6cb (patch) | |
tree | 3877f470995699b287a14a2b4a5d66f9ffe6e112 /lib/CodeGen/LiveRangeEdit.cpp | |
parent | 5aa3fa6d827e162893534454b2a2c4b6e50884fc (diff) | |
download | llvm-5881799d0cccbd814ec1b0f0509df9be1f63c6cb.tar.gz llvm-5881799d0cccbd814ec1b0f0509df9be1f63c6cb.tar.bz2 llvm-5881799d0cccbd814ec1b0f0509df9be1f63c6cb.tar.xz |
Delete dead code after rematerializing.
LiveRangeEdit::eliminateDeadDefs() will eventually be used by coalescing,
splitting, and spilling for dead code elimination. It can delete chains of dead
instructions as long as there are no dependency loops.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127287 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LiveRangeEdit.cpp')
-rw-r--r-- | lib/CodeGen/LiveRangeEdit.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/CodeGen/LiveRangeEdit.cpp b/lib/CodeGen/LiveRangeEdit.cpp index 7de1284cb9..4e2c00df38 100644 --- a/lib/CodeGen/LiveRangeEdit.cpp +++ b/lib/CodeGen/LiveRangeEdit.cpp @@ -13,9 +13,12 @@ #include "LiveRangeEdit.h" #include "VirtRegMap.h" +#include "llvm/ADT/SetVector.h" #include "llvm/CodeGen/LiveIntervalAnalysis.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -128,3 +131,59 @@ SlotIndex LiveRangeEdit::rematerializeAt(MachineBasicBlock &MBB, return lis.InsertMachineInstrInMaps(--MI).getDefIndex(); } +void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead, + LiveIntervals &LIS, + const TargetInstrInfo &TII) { + SetVector<LiveInterval*, + SmallVector<LiveInterval*, 8>, + SmallPtrSet<LiveInterval*, 8> > ToShrink; + + for (;;) { + // Erase all dead defs. + while (!Dead.empty()) { + MachineInstr *MI = Dead.pop_back_val(); + assert(MI->allDefsAreDead() && "Def isn't really dead"); + + // Never delete inline asm. + if (MI->isInlineAsm()) + continue; + + // Use the same criteria as DeadMachineInstructionElim. + bool SawStore = false; + if (!MI->isSafeToMove(&TII, 0, SawStore)) + continue; + + SlotIndex Idx = LIS.getInstructionIndex(MI).getDefIndex(); + DEBUG(dbgs() << "Deleting dead def " << Idx << '\t' << *MI); + + // Check for live intervals that may shrink + for (MachineInstr::mop_iterator MOI = MI->operands_begin(), + MOE = MI->operands_end(); MOI != MOE; ++MOI) { + if (!MOI->isReg()) + continue; + unsigned Reg = MOI->getReg(); + if (!TargetRegisterInfo::isVirtualRegister(Reg)) + continue; + LiveInterval &LI = LIS.getInterval(Reg); + // Remove defined value. + if (MOI->isDef()) + if (VNInfo *VNI = LI.getVNInfoAt(Idx)) + LI.removeValNo(VNI); + // Shrink read registers. + if (MI->readsVirtualRegister(Reg)) + ToShrink.insert(&LI); + } + + LIS.RemoveMachineInstrFromMaps(MI); + MI->eraseFromParent(); + } + + if (ToShrink.empty()) + break; + + // Shrink just one live interval. Then delete new dead defs. + LIS.shrinkToUses(ToShrink.back(), &Dead); + ToShrink.pop_back(); + } +} + |