forked from OSchip/llvm-project
[LV] Simplify register usage code and avoid double map lookups. NFC
Instead of checking whether a map entry exists to decide if we should initialize it or add to it, we can rely on the map entry being constructed and initialized to 0 before the addition happens. For the std::max case, I've made a reference to the map entry to avoid looking it up twice. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D135977
This commit is contained in:
parent
657f68b1f2
commit
d3366efd43
|
@ -6026,10 +6026,9 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<ElementCount> VFs) {
|
|||
if (VFs[j].isScalar()) {
|
||||
for (auto *Inst : OpenIntervals) {
|
||||
unsigned ClassID = TTI.getRegisterClassForType(false, Inst->getType());
|
||||
if (RegUsage.find(ClassID) == RegUsage.end())
|
||||
RegUsage[ClassID] = 1;
|
||||
else
|
||||
RegUsage[ClassID] += 1;
|
||||
// If RegUsage[ClassID] doesn't exist, it will be default
|
||||
// constructed as 0 before the addition
|
||||
RegUsage[ClassID] += 1;
|
||||
}
|
||||
} else {
|
||||
collectUniformsAndScalars(VFs[j]);
|
||||
|
@ -6039,25 +6038,21 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<ElementCount> VFs) {
|
|||
continue;
|
||||
if (isScalarAfterVectorization(Inst, VFs[j])) {
|
||||
unsigned ClassID = TTI.getRegisterClassForType(false, Inst->getType());
|
||||
if (RegUsage.find(ClassID) == RegUsage.end())
|
||||
RegUsage[ClassID] = 1;
|
||||
else
|
||||
RegUsage[ClassID] += 1;
|
||||
// If RegUsage[ClassID] doesn't exist, it will be default
|
||||
// constructed as 0 before the addition
|
||||
RegUsage[ClassID] += 1;
|
||||
} else {
|
||||
unsigned ClassID = TTI.getRegisterClassForType(true, Inst->getType());
|
||||
if (RegUsage.find(ClassID) == RegUsage.end())
|
||||
RegUsage[ClassID] = GetRegUsage(Inst->getType(), VFs[j]);
|
||||
else
|
||||
RegUsage[ClassID] += GetRegUsage(Inst->getType(), VFs[j]);
|
||||
// If RegUsage[ClassID] doesn't exist, it will be default
|
||||
// constructed as 0 before the addition
|
||||
RegUsage[ClassID] += GetRegUsage(Inst->getType(), VFs[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& pair : RegUsage) {
|
||||
if (MaxUsages[j].find(pair.first) != MaxUsages[j].end())
|
||||
MaxUsages[j][pair.first] = std::max(MaxUsages[j][pair.first], pair.second);
|
||||
else
|
||||
MaxUsages[j][pair.first] = pair.second;
|
||||
auto &Entry = MaxUsages[j][pair.first];
|
||||
Entry = std::max(Entry, pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue