Use a bump pointer allocator in the callee set creation.

Shaves about 19% of the time from the construction of these sets. The
SmallVector size was chosen to minimize the number of dynamic
allocations we end up doing while building the stdlib. This should be a
reasonable size for most projects, too. It's a bit wasteful in space,
but the total amount of allocated space here is pretty small to begin
with.
This commit is contained in:
Mark Lacey
2016-05-11 17:01:02 -07:00
parent 405fb1339d
commit 921dededad
2 changed files with 7 additions and 6 deletions

View File

@@ -22,6 +22,7 @@
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Support/Allocator.h"
namespace swift {
class ClassDecl;
@@ -73,13 +74,16 @@ public:
/// any function application site (including those that are simple
/// function_ref, thin_to_thick, or partial_apply callees).
class CalleeCache {
typedef llvm::SmallVector<SILFunction *, 4> Callees;
typedef llvm::SmallVector<SILFunction *, 16> Callees;
typedef llvm::PointerIntPair<Callees *, 1> CalleesAndCanCallUnknown;
typedef llvm::DenseMap<AbstractFunctionDecl *, CalleesAndCanCallUnknown>
CacheType;
SILModule &M;
// Allocator for the SmallVectors that we will be allocating.
llvm::SpecificBumpPtrAllocator<Callees> Allocator;
// The cache of precomputed callee lists for function decls appearing
// in class virtual dispatch tables and witness tables.
CacheType TheCache;
@@ -91,10 +95,7 @@ public:
}
~CalleeCache() {
for (auto &Pair : TheCache) {
auto *Callees = Pair.second.getPointer();
delete Callees;
}
Allocator.DestroyAll();
}
/// Return the list of callees that can potentially be called at the