forked from OSchip/llvm-project
[TableGen] TypeSetByHwMode::insert - cache the default MVT. NFCI.
Avoids repeated count()/find() calls that we've already have the default values for. llvm-svn: 340020
This commit is contained in:
parent
0ac44c18b7
commit
16a2f54eee
|
@ -99,22 +99,29 @@ bool TypeSetByHwMode::isPossible() const {
|
||||||
|
|
||||||
bool TypeSetByHwMode::insert(const ValueTypeByHwMode &VVT) {
|
bool TypeSetByHwMode::insert(const ValueTypeByHwMode &VVT) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
bool ContainsDefault = false;
|
||||||
|
MVT DT = MVT::Other;
|
||||||
|
|
||||||
SmallDenseSet<unsigned, 4> Modes;
|
SmallDenseSet<unsigned, 4> Modes;
|
||||||
for (const auto &P : VVT) {
|
for (const auto &P : VVT) {
|
||||||
unsigned M = P.first;
|
unsigned M = P.first;
|
||||||
Modes.insert(M);
|
Modes.insert(M);
|
||||||
// Make sure there exists a set for each specific mode from VVT.
|
// Make sure there exists a set for each specific mode from VVT.
|
||||||
Changed |= getOrCreate(M).insert(P.second).second;
|
Changed |= getOrCreate(M).insert(P.second).second;
|
||||||
|
// Cache VVT's default mode.
|
||||||
|
if (DefaultMode == M) {
|
||||||
|
ContainsDefault = true;
|
||||||
|
DT = P.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If VVT has a default mode, add the corresponding type to all
|
// If VVT has a default mode, add the corresponding type to all
|
||||||
// modes in "this" that do not exist in VVT.
|
// modes in "this" that do not exist in VVT.
|
||||||
if (Modes.count(DefaultMode)) {
|
if (ContainsDefault)
|
||||||
MVT DT = VVT.getType(DefaultMode);
|
|
||||||
for (auto &I : *this)
|
for (auto &I : *this)
|
||||||
if (!Modes.count(I.first))
|
if (!Modes.count(I.first))
|
||||||
Changed |= I.second.insert(DT).second;
|
Changed |= I.second.insert(DT).second;
|
||||||
}
|
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue