1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[TableGen] TypeInfer - Cache the legal types as TypeSetByHwMode

We were just caching the MVT set of legal types, then every call creating a new TypeSetByHwMode with it and passing it back on the stack. There's no need to do this - we can create and cache the whole TypeSetByHwMode once and return a const reference to it each time.

Additionally, TypeInfer::expandOverloads wasn't making use of the fact that the cache just contains a default mode containing all the types.

Saves up to 30secs in debug builds of x86 -gen-dag-isel.

Differential Revision: https://reviews.llvm.org/D50903

llvm-svn: 340042
This commit is contained in:
Simon Pilgrim 2018-08-17 15:54:07 +00:00
parent 412b962dd9
commit 594d93848a
2 changed files with 13 additions and 18 deletions

View File

@ -740,17 +740,12 @@ bool TypeInfer::EnforceSameSize(TypeSetByHwMode &A, TypeSetByHwMode &B) {
void TypeInfer::expandOverloads(TypeSetByHwMode &VTS) { void TypeInfer::expandOverloads(TypeSetByHwMode &VTS) {
ValidateOnExit _1(VTS, *this); ValidateOnExit _1(VTS, *this);
TypeSetByHwMode Legal = getLegalTypes(); const TypeSetByHwMode &Legal = getLegalTypes();
bool HaveLegalDef = Legal.hasDefault(); assert(Legal.isDefaultOnly() && "Default-mode only expected");
const TypeSetByHwMode::SetType &LegalTypes = Legal.get(DefaultMode);
for (auto &I : VTS) { for (auto &I : VTS)
unsigned M = I.first; expandOverloads(I.second, LegalTypes);
if (!Legal.hasMode(M) && !HaveLegalDef) {
TP.error("Invalid mode " + Twine(M));
return;
}
expandOverloads(I.second, Legal.get(M));
}
} }
void TypeInfer::expandOverloads(TypeSetByHwMode::SetType &Out, void TypeInfer::expandOverloads(TypeSetByHwMode::SetType &Out,
@ -802,17 +797,17 @@ void TypeInfer::expandOverloads(TypeSetByHwMode::SetType &Out,
} }
} }
TypeSetByHwMode TypeInfer::getLegalTypes() { const TypeSetByHwMode &TypeInfer::getLegalTypes() {
if (!LegalTypesCached) { if (!LegalTypesCached) {
TypeSetByHwMode::SetType &LegalTypes = LegalCache.getOrCreate(DefaultMode);
// Stuff all types from all modes into the default mode. // Stuff all types from all modes into the default mode.
const TypeSetByHwMode &LTS = TP.getDAGPatterns().getLegalTypes(); const TypeSetByHwMode &LTS = TP.getDAGPatterns().getLegalTypes();
for (const auto &I : LTS) for (const auto &I : LTS)
LegalCache.insert(I.second); LegalTypes.insert(I.second);
LegalTypesCached = true; LegalTypesCached = true;
} }
TypeSetByHwMode VTS; assert(LegalCache.isDefaultOnly() && "Default-mode only expected");
VTS.getOrCreate(DefaultMode) = LegalCache; return LegalCache;
return VTS;
} }
#ifndef NDEBUG #ifndef NDEBUG

View File

@ -350,11 +350,11 @@ struct TypeInfer {
bool Validate = true; // Indicate whether to validate types. bool Validate = true; // Indicate whether to validate types.
private: private:
TypeSetByHwMode getLegalTypes(); const TypeSetByHwMode &getLegalTypes();
/// Cached legal types. /// Cached legal types (in default mode).
bool LegalTypesCached = false; bool LegalTypesCached = false;
TypeSetByHwMode::SetType LegalCache = {}; TypeSetByHwMode LegalCache;
}; };
/// Set type used to track multiply used variables in patterns /// Set type used to track multiply used variables in patterns