[GMR] Switch to a DenseMap and clean up the iteration loop. NFC.

Since we have to iterate this map not that infrequently, we should use
a map that is efficient for iteration. It is also almost certainly much
faster for lookups as well. There is more to do in terms of reducing the
wasted overhead of GMR's runtime though. Not sure how much is worthwhile
though.

The loop improvements should hopefully address the code review that
Duncan gave when he saw this code as I moved it around.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth 2015-07-22 11:36:09 +00:00
parent e284e481f2
commit f28cb39e4c

View File

@ -97,7 +97,7 @@ class GlobalsModRef : public ModulePass, public AliasAnalysis {
/// AllocsForIndirectGlobals - If an instruction allocates memory for an
/// indirect global, this map indicates which one.
std::map<const Value *, const GlobalValue *> AllocsForIndirectGlobals;
DenseMap<const Value *, const GlobalValue *> AllocsForIndirectGlobals;
/// FunctionInfo - For each function, keep track of what globals are
/// modified or read.
@ -120,16 +120,11 @@ class GlobalsModRef : public ModulePass, public AliasAnalysis {
// any AllocRelatedValues for it.
if (GMR.IndirectGlobals.erase(GV)) {
// Remove any entries in AllocsForIndirectGlobals for this global.
for (std::map<const Value *, const GlobalValue *>::iterator
I = GMR.AllocsForIndirectGlobals.begin(),
E = GMR.AllocsForIndirectGlobals.end();
I != E;) {
if (I->second == GV) {
GMR.AllocsForIndirectGlobals.erase(I++);
} else {
++I;
}
}
for (auto I = GMR.AllocsForIndirectGlobals.begin(),
E = GMR.AllocsForIndirectGlobals.end();
I != E; ++I)
if (I->second == GV)
GMR.AllocsForIndirectGlobals.erase(I);
}
}
}