1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[Attributor] Use the BumpPtrAllocator in InformationCache as well

We now also use the BumpPtrAllocator from the Attributor in the
InformationCache. The lifetime of objects in either is pretty much the
same and it should result in consistently good performance regardless of
the allocator.

Doing so requires to call more constructors manually but so far that
does not seem to be problematic or messy.

---

Single run of the Attributor module and then CGSCC pass (oldPM)
for SPASS/clause.c (~10k LLVM-IR loc):

Before:
```
calls to allocation functions: 615359 (368257/s)
temporary memory allocations: 83315 (49859/s)
peak heap memory consumption: 75.64MB
peak RSS (including heaptrack overhead): 163.43MB
total memory leaked: 269.04KB
```

After:
```
calls to allocation functions: 613042 (359555/s)
temporary memory allocations: 83322 (48869/s)
peak heap memory consumption: 75.64MB
peak RSS (including heaptrack overhead): 162.92MB
total memory leaked: 269.04KB
```

Difference:
```
calls to allocation functions: -2317 (-68147/s)
temporary memory allocations: 7 (205/s)
peak heap memory consumption: 2.23KB
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

---
This commit is contained in:
Johannes Doerfert 2020-04-16 17:54:40 -05:00
parent 5400acb27b
commit 62c312e2e4
2 changed files with 21 additions and 10 deletions

View File

@ -549,8 +549,8 @@ private:
/// instance down in the abstract attributes.
struct InformationCache {
InformationCache(const Module &M, AnalysisGetter &AG,
SetVector<Function *> *CGSCC)
: DL(M.getDataLayout()),
BumpPtrAllocator &Allocator, SetVector<Function *> *CGSCC)
: DL(M.getDataLayout()), Allocator(Allocator),
Explorer(
/* ExploreInterBlock */ true, /* ExploreCFGForward */ true,
/* ExploreCFGBackward */ true,
@ -567,7 +567,10 @@ struct InformationCache {
AG(AG), CGSCC(CGSCC) {}
~InformationCache() {
DeleteContainerSeconds(FuncInfoMap);
// The FunctionInfo objects are allocated via a BumpPtrAllocator, we call
// the destructor manually.
for (auto &It : FuncInfoMap)
It.getSecond()->~FunctionInfo();
}
/// A map type from opcodes to instructions with this opcode.
@ -652,7 +655,7 @@ private:
FunctionInfo &getFunctionInfo(const Function &F) {
FunctionInfo *&FI = FuncInfoMap[&F];
if (!FI) {
FI = new FunctionInfo();
FI = new (Allocator) FunctionInfo();
initializeInformationCache(F, *FI);
}
return *FI;
@ -667,6 +670,9 @@ private:
/// The datalayout used in the module.
const DataLayout &DL;
/// The allocator used to allocate memory, e.g. for `FunctionInfo`s.
BumpPtrAllocator &Allocator;
/// MustBeExecutedContextExplorer
MustBeExecutedContextExplorer Explorer;
@ -727,7 +733,8 @@ struct Attributor {
Attributor(SetVector<Function *> &Functions, InformationCache &InfoCache,
CallGraphUpdater &CGUpdater, unsigned DepRecomputeInterval,
DenseSet<const char *> *Whitelist = nullptr)
: Functions(Functions), InfoCache(InfoCache), CGUpdater(CGUpdater),
: Allocator(InfoCache.Allocator), Functions(Functions),
InfoCache(InfoCache), CGUpdater(CGUpdater),
DepRecomputeInterval(DepRecomputeInterval), Whitelist(Whitelist) {}
~Attributor();
@ -1100,7 +1107,7 @@ struct Attributor {
const DataLayout &getDataLayout() const { return InfoCache.DL; }
/// The allocator used to allocate memory, e.g. for `AbstractAttribute`s.
BumpPtrAllocator Allocator;
BumpPtrAllocator &Allocator;
private:
/// Check \p Pred on all call sites of \p Fn.

View File

@ -2010,7 +2010,8 @@ PreservedAnalyses AttributorPass::run(Module &M, ModuleAnalysisManager &AM) {
Functions.insert(&F);
CallGraphUpdater CGUpdater;
InformationCache InfoCache(M, AG, /* CGSCC */ nullptr);
BumpPtrAllocator Allocator;
InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ nullptr);
if (runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater)) {
// FIXME: Think about passes we will preserve and add them here.
return PreservedAnalyses::none();
@ -2036,7 +2037,8 @@ PreservedAnalyses AttributorCGSCCPass::run(LazyCallGraph::SCC &C,
Module &M = *Functions.back()->getParent();
CallGraphUpdater CGUpdater;
CGUpdater.initialize(CG, C, AM, UR);
InformationCache InfoCache(M, AG, /* CGSCC */ &Functions);
BumpPtrAllocator Allocator;
InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ &Functions);
if (runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater)) {
// FIXME: Think about passes we will preserve and add them here.
return PreservedAnalyses::none();
@ -2063,7 +2065,8 @@ struct AttributorLegacyPass : public ModulePass {
Functions.insert(&F);
CallGraphUpdater CGUpdater;
InformationCache InfoCache(M, AG, /* CGSCC */ nullptr);
BumpPtrAllocator Allocator;
InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ nullptr);
return runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater);
}
@ -2098,7 +2101,8 @@ struct AttributorCGSCCLegacyPass : public CallGraphSCCPass {
CallGraph &CG = const_cast<CallGraph &>(SCC.getCallGraph());
CGUpdater.initialize(CG, SCC);
Module &M = *Functions.back()->getParent();
InformationCache InfoCache(M, AG, /* CGSCC */ &Functions);
BumpPtrAllocator Allocator;
InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ &Functions);
return runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater);
}