diff options
author | Lang Hames <lhames@gmail.com> | 2012-03-27 00:44:47 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2012-03-27 00:44:47 +0000 |
commit | d9eb1d77979f10d0237af22d87789803162044fa (patch) | |
tree | 0eb2e555402eb8abfc25242e57f53e3d274b16bb | |
parent | 7067d4e4de8e0d795fb16c7c10fcf98028ca7577 (diff) | |
download | external_llvm-d9eb1d77979f10d0237af22d87789803162044fa.zip external_llvm-d9eb1d77979f10d0237af22d87789803162044fa.tar.gz external_llvm-d9eb1d77979f10d0237af22d87789803162044fa.tar.bz2 |
During MachineCopyPropagation a register may be the source operand of multiple
copies being considered for removal. Make sure to track all of the copies,
rather than just the most recent encountered, by holding a DenseSet instead of
an unsigned in SrcMap.
No test case - couldn't reduce something with a sane size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153487 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/MachineCopyPropagation.cpp | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/CodeGen/MachineCopyPropagation.cpp b/lib/CodeGen/MachineCopyPropagation.cpp index 9aa74f1..565efb3 100644 --- a/lib/CodeGen/MachineCopyPropagation.cpp +++ b/lib/CodeGen/MachineCopyPropagation.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/BitVector.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" @@ -44,7 +45,7 @@ namespace { private: void SourceNoLongerAvailable(unsigned Reg, - DenseMap<unsigned, unsigned> &SrcMap, + DenseMap<unsigned, DenseSet<unsigned> > &SrcMap, DenseMap<unsigned, MachineInstr*> &AvailCopyMap); bool CopyPropagateBlock(MachineBasicBlock &MBB); }; @@ -57,24 +58,32 @@ INITIALIZE_PASS(MachineCopyPropagation, "machine-cp", void MachineCopyPropagation::SourceNoLongerAvailable(unsigned Reg, - DenseMap<unsigned, unsigned> &SrcMap, + DenseMap<unsigned, DenseSet<unsigned> > &SrcMap, DenseMap<unsigned, MachineInstr*> &AvailCopyMap) { - DenseMap<unsigned, unsigned>::iterator SI = SrcMap.find(Reg); + DenseMap<unsigned, DenseSet<unsigned> >::iterator SI = SrcMap.find(Reg); if (SI != SrcMap.end()) { - unsigned MappedDef = SI->second; - // Source of copy is no longer available for propagation. - if (AvailCopyMap.erase(MappedDef)) { - for (const uint16_t *SR = TRI->getSubRegisters(MappedDef); *SR; ++SR) - AvailCopyMap.erase(*SR); + const DenseSet<unsigned>& Defs = SI->second; + for (DenseSet<unsigned>::const_iterator I = Defs.begin(), E = Defs.end(); + I != E; ++I) { + unsigned MappedDef = *I; + // Source of copy is no longer available for propagation. + if (AvailCopyMap.erase(MappedDef)) { + for (const uint16_t *SR = TRI->getSubRegisters(MappedDef); *SR; ++SR) + AvailCopyMap.erase(*SR); + } } } for (const uint16_t *AS = TRI->getAliasSet(Reg); *AS; ++AS) { SI = SrcMap.find(*AS); if (SI != SrcMap.end()) { - unsigned MappedDef = SI->second; - if (AvailCopyMap.erase(MappedDef)) { - for (const uint16_t *SR = TRI->getSubRegisters(MappedDef); *SR; ++SR) - AvailCopyMap.erase(*SR); + const DenseSet<unsigned>& Defs = SI->second; + for (DenseSet<unsigned>::const_iterator I = Defs.begin(), E = Defs.end(); + I != E; ++I) { + unsigned MappedDef = *I; + if (AvailCopyMap.erase(MappedDef)) { + for (const uint16_t *SR = TRI->getSubRegisters(MappedDef); *SR; ++SR) + AvailCopyMap.erase(*SR); + } } } } @@ -125,10 +134,10 @@ static bool isNopCopy(MachineInstr *CopyMI, unsigned Def, unsigned Src, } bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { - SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion - DenseMap<unsigned, MachineInstr*> AvailCopyMap; // Def -> available copies map - DenseMap<unsigned, MachineInstr*> CopyMap; // Def -> copies map - DenseMap<unsigned, unsigned> SrcMap; // Src -> Def map + SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion + DenseMap<unsigned, MachineInstr*> AvailCopyMap; // Def -> available copies map + DenseMap<unsigned, MachineInstr*> CopyMap; // Def -> copies map + DenseMap<unsigned, DenseSet<unsigned> > SrcMap; // Src -> Def map bool Changed = false; for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ) { @@ -213,7 +222,7 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) { // Remember source that's copied to Def. Once it's clobbered, then // it's no longer available for copy propagation. - SrcMap[Src] = Def; + SrcMap[Src].insert(Def); continue; } |