Reduce duplicated hash map lookups.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162362 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2012-08-22 15:37:57 +00:00
parent fdeb9fe5e0
commit 05d96f98cb
7 changed files with 20 additions and 23 deletions

View File

@ -470,8 +470,10 @@ bool LazyValueInfoCache::hasBlockValue(Value *Val, BasicBlock *BB) {
return true; return true;
LVIValueHandle ValHandle(Val, this); LVIValueHandle ValHandle(Val, this);
if (!ValueCache.count(ValHandle)) return false; std::map<LVIValueHandle, ValueCacheEntryTy>::iterator I =
return ValueCache[ValHandle].count(BB); ValueCache.find(ValHandle);
if (I == ValueCache.end()) return false;
return I->second.count(BB);
} }
LVILatticeVal LazyValueInfoCache::getBlockValue(Value *Val, BasicBlock *BB) { LVILatticeVal LazyValueInfoCache::getBlockValue(Value *Val, BasicBlock *BB) {

View File

@ -429,8 +429,8 @@ void UnloopUpdater::updateSubloopParents() {
Unloop->removeChildLoop(llvm::prior(Unloop->end())); Unloop->removeChildLoop(llvm::prior(Unloop->end()));
assert(SubloopParents.count(Subloop) && "DFS failed to visit subloop"); assert(SubloopParents.count(Subloop) && "DFS failed to visit subloop");
if (SubloopParents[Subloop]) if (Loop *Parent = SubloopParents[Subloop])
SubloopParents[Subloop]->addChildLoop(Subloop); Parent->addChildLoop(Subloop);
else else
LI->addTopLevelLoop(Subloop); LI->addTopLevelLoop(Subloop);
} }
@ -456,9 +456,8 @@ Loop *UnloopUpdater::getNearestLoop(BasicBlock *BB, Loop *BBLoop) {
assert(Subloop && "subloop is not an ancestor of the original loop"); assert(Subloop && "subloop is not an ancestor of the original loop");
} }
// Get the current nearest parent of the Subloop exits, initially Unloop. // Get the current nearest parent of the Subloop exits, initially Unloop.
if (!SubloopParents.count(Subloop)) NearLoop =
SubloopParents[Subloop] = Unloop; SubloopParents.insert(std::make_pair(Subloop, Unloop)).first->second;
NearLoop = SubloopParents[Subloop];
} }
succ_iterator I = succ_begin(BB), E = succ_end(BB); succ_iterator I = succ_begin(BB), E = succ_end(BB);

View File

@ -1554,8 +1554,7 @@ MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
Uses.insert(*AI); Uses.insert(*AI);
} else { } else {
if (Uses.count(Reg)) { if (Uses.erase(Reg)) {
Uses.erase(Reg);
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs)
Uses.erase(*SubRegs); // Use sub-registers to be conservative Uses.erase(*SubRegs); // Use sub-registers to be conservative
} }

View File

@ -996,14 +996,13 @@ static void UpdatePredRedefs(MachineInstr *MI, SmallSet<unsigned,4> &Redefs,
} }
for (unsigned i = 0, e = Defs.size(); i != e; ++i) { for (unsigned i = 0, e = Defs.size(); i != e; ++i) {
unsigned Reg = Defs[i]; unsigned Reg = Defs[i];
if (Redefs.count(Reg)) { if (!Redefs.insert(Reg)) {
if (AddImpUse) if (AddImpUse)
// Treat predicated update as read + write. // Treat predicated update as read + write.
MI->addOperand(MachineOperand::CreateReg(Reg, false/*IsDef*/, MI->addOperand(MachineOperand::CreateReg(Reg, false/*IsDef*/,
true/*IsImp*/,false/*IsKill*/, true/*IsImp*/,false/*IsKill*/,
false/*IsDead*/,true/*IsUndef*/)); false/*IsDead*/,true/*IsUndef*/));
} else { } else {
Redefs.insert(Reg);
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs)
Redefs.insert(*SubRegs); Redefs.insert(*SubRegs);
} }

View File

@ -404,9 +404,9 @@ bool StrongPHIElimination::runOnMachineFunction(MachineFunction &MF) {
} }
void StrongPHIElimination::addReg(unsigned Reg) { void StrongPHIElimination::addReg(unsigned Reg) {
if (RegNodeMap.count(Reg)) Node *&N = RegNodeMap[Reg];
return; if (!N)
RegNodeMap[Reg] = new (Allocator) Node(Reg); N = new (Allocator) Node(Reg);
} }
StrongPHIElimination::Node* StrongPHIElimination::Node*
@ -714,8 +714,9 @@ void StrongPHIElimination::InsertCopiesForPHI(MachineInstr *PHI,
assert(getRegColor(CopyReg) == CopyReg); assert(getRegColor(CopyReg) == CopyReg);
} }
if (!InsertedSrcCopyMap.count(std::make_pair(PredBB, PHIColor))) // Insert into map if not already there.
InsertedSrcCopyMap[std::make_pair(PredBB, PHIColor)] = CopyInstr; InsertedSrcCopyMap.insert(std::make_pair(std::make_pair(PredBB, PHIColor),
CopyInstr));
} }
SrcMO.setReg(CopyReg); SrcMO.setReg(CopyReg);

View File

@ -396,8 +396,7 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) {
continue; continue;
// Initialize the section indirect symbol base, if necessary. // Initialize the section indirect symbol base, if necessary.
if (!IndirectSymBase.count(it->SectionData)) IndirectSymBase.insert(std::make_pair(it->SectionData, IndirectIndex));
IndirectSymBase[it->SectionData] = IndirectIndex;
Asm.getOrCreateSymbolData(*it->Symbol); Asm.getOrCreateSymbolData(*it->Symbol);
} }
@ -414,8 +413,7 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) {
continue; continue;
// Initialize the section indirect symbol base, if necessary. // Initialize the section indirect symbol base, if necessary.
if (!IndirectSymBase.count(it->SectionData)) IndirectSymBase.insert(std::make_pair(it->SectionData, IndirectIndex));
IndirectSymBase[it->SectionData] = IndirectIndex;
// Set the symbol type to undefined lazy, but only on construction. // Set the symbol type to undefined lazy, but only on construction.
// //

View File

@ -1388,10 +1388,9 @@ bool ARMConstantIslands::handleConstantPoolUser(unsigned CPUserIndex) {
// If the original WaterList entry was "new water" on this iteration, // If the original WaterList entry was "new water" on this iteration,
// propagate that to the new island. This is just keeping NewWaterList // propagate that to the new island. This is just keeping NewWaterList
// updated to match the WaterList, which will be updated below. // updated to match the WaterList, which will be updated below.
if (NewWaterList.count(WaterBB)) { if (NewWaterList.erase(WaterBB))
NewWaterList.erase(WaterBB);
NewWaterList.insert(NewIsland); NewWaterList.insert(NewIsland);
}
// The new CPE goes before the following block (NewMBB). // The new CPE goes before the following block (NewMBB).
NewMBB = llvm::next(MachineFunction::iterator(WaterBB)); NewMBB = llvm::next(MachineFunction::iterator(WaterBB));