Cache the isTrivial property.

The check for isTrivial takes ~20% of the optimizer compile time (in debug
mode) and using a cache accelerates the compile time.



Swift SVN r14346
This commit is contained in:
Nadav Rotem
2014-02-25 18:15:45 +00:00
parent 70f637242f
commit bc6fcc4475
2 changed files with 17 additions and 1 deletions

View File

@@ -127,6 +127,9 @@ private:
/// This is a cache of builtin Function declarations to numeric ID mappings.
llvm::DenseMap<Identifier, BuiltinInfo> BuiltinIDCache;
/// This is a cache of the isTrivial property for SILTypes.
llvm::DenseMap<SILType, bool> TrivialTypeCache;
/// This is the set of undef values we've created, for uniquing purposes.
llvm::DenseMap<SILType, SILUndef*> UndefValues;
@@ -163,6 +166,19 @@ public:
FunctionTable.erase(F->getName());
}
bool isTrivialType(SILType Ty) {
auto It = TrivialTypeCache.find(Ty);
// Check if this type is already in the cache.
if (It != TrivialTypeCache.end())
return It->second;
// Check if the type is trivial and store the result in the cache.
bool IsTriv = getTypeLowering(Ty).isTrivial();
TrivialTypeCache[Ty] = IsTriv;
return IsTriv;
}
/// Construct a SIL module from an AST module.
///
/// The module will be constructed in the Raw stage. The provided AST module