Use a SmallVector and linear lookup instead of a DenseSet - SourceMap values

will always be tiny sets, so DenseSet is overkill (SmallSet won't work as we
need iteration support). 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153529 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames 2012-03-27 19:10:45 +00:00
parent 95f95a783f
commit 5f46eb157e

View File

@ -22,7 +22,6 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/BitVector.h" #include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h" #include "llvm/ADT/Statistic.h"
@ -44,8 +43,11 @@ namespace {
virtual bool runOnMachineFunction(MachineFunction &MF); virtual bool runOnMachineFunction(MachineFunction &MF);
private: private:
typedef SmallVector<unsigned, 4> DestList;
typedef DenseMap<unsigned, DestList> SourceMap;
void SourceNoLongerAvailable(unsigned Reg, void SourceNoLongerAvailable(unsigned Reg,
DenseMap<unsigned, DenseSet<unsigned> > &SrcMap, SourceMap &SrcMap,
DenseMap<unsigned, MachineInstr*> &AvailCopyMap); DenseMap<unsigned, MachineInstr*> &AvailCopyMap);
bool CopyPropagateBlock(MachineBasicBlock &MBB); bool CopyPropagateBlock(MachineBasicBlock &MBB);
}; };
@ -58,12 +60,12 @@ INITIALIZE_PASS(MachineCopyPropagation, "machine-cp",
void void
MachineCopyPropagation::SourceNoLongerAvailable(unsigned Reg, MachineCopyPropagation::SourceNoLongerAvailable(unsigned Reg,
DenseMap<unsigned, DenseSet<unsigned> > &SrcMap, SourceMap &SrcMap,
DenseMap<unsigned, MachineInstr*> &AvailCopyMap) { DenseMap<unsigned, MachineInstr*> &AvailCopyMap) {
DenseMap<unsigned, DenseSet<unsigned> >::iterator SI = SrcMap.find(Reg); SourceMap::iterator SI = SrcMap.find(Reg);
if (SI != SrcMap.end()) { if (SI != SrcMap.end()) {
const DenseSet<unsigned>& Defs = SI->second; const DestList& Defs = SI->second;
for (DenseSet<unsigned>::const_iterator I = Defs.begin(), E = Defs.end(); for (DestList::const_iterator I = Defs.begin(), E = Defs.end();
I != E; ++I) { I != E; ++I) {
unsigned MappedDef = *I; unsigned MappedDef = *I;
// Source of copy is no longer available for propagation. // Source of copy is no longer available for propagation.
@ -76,8 +78,8 @@ MachineCopyPropagation::SourceNoLongerAvailable(unsigned Reg,
for (const uint16_t *AS = TRI->getAliasSet(Reg); *AS; ++AS) { for (const uint16_t *AS = TRI->getAliasSet(Reg); *AS; ++AS) {
SI = SrcMap.find(*AS); SI = SrcMap.find(*AS);
if (SI != SrcMap.end()) { if (SI != SrcMap.end()) {
const DenseSet<unsigned>& Defs = SI->second; const DestList& Defs = SI->second;
for (DenseSet<unsigned>::const_iterator I = Defs.begin(), E = Defs.end(); for (DestList::const_iterator I = Defs.begin(), E = Defs.end();
I != E; ++I) { I != E; ++I) {
unsigned MappedDef = *I; unsigned MappedDef = *I;
if (AvailCopyMap.erase(MappedDef)) { if (AvailCopyMap.erase(MappedDef)) {
@ -137,7 +139,7 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion SmallSetVector<MachineInstr*, 8> MaybeDeadCopies; // Candidates for deletion
DenseMap<unsigned, MachineInstr*> AvailCopyMap; // Def -> available copies map DenseMap<unsigned, MachineInstr*> AvailCopyMap; // Def -> available copies map
DenseMap<unsigned, MachineInstr*> CopyMap; // Def -> copies map DenseMap<unsigned, MachineInstr*> CopyMap; // Def -> copies map
DenseMap<unsigned, DenseSet<unsigned> > SrcMap; // Src -> Def map SourceMap SrcMap; // Src -> Def map
bool Changed = false; bool Changed = false;
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ) { for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ) {
@ -222,7 +224,10 @@ bool MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
// Remember source that's copied to Def. Once it's clobbered, then // Remember source that's copied to Def. Once it's clobbered, then
// it's no longer available for copy propagation. // it's no longer available for copy propagation.
SrcMap[Src].insert(Def); if (std::find(SrcMap[Src].begin(), SrcMap[Src].end(), Def) ==
SrcMap[Src].end()) {
SrcMap[Src].push_back(Def);
}
continue; continue;
} }