forked from OSchip/llvm-project
[Attributor] Replace AccessKind2Accesses map with an "array map"
The number of different access location kinds we track is relatively small (8 so far). With this patch we replace the DenseMap that mapped from index (0-7) to the access set pointer with an array of access set pointers. This reduces memory consumption. No functional change is intended. --- Single run of the Attributor module and then CGSCC pass (oldPM) for SPASS/clause.c (~10k LLVM-IR loc): Before: ``` calls to allocation functions: 472499 (215654/s) temporary memory allocations: 77794 (35506/s) peak heap memory consumption: 35.28MB peak RSS (including heaptrack overhead): 125.46MB total memory leaked: 269.04KB ``` After: ``` calls to allocation functions: 472270 (308673/s) temporary memory allocations: 77578 (50704/s) peak heap memory consumption: 32.70MB peak RSS (including heaptrack overhead): 121.78MB total memory leaked: 269.04KB ``` Difference: ``` calls to allocation functions: -229 (346/s) temporary memory allocations: -216 (326/s) peak heap memory consumption: -2.58MB peak RSS (including heaptrack overhead): 0B total memory leaked: 0B ``` ---
This commit is contained in:
parent
f20ff4b17d
commit
ca59ff5af9
|
@ -6010,13 +6010,17 @@ std::string AAMemoryLocation::getMemoryLocationsAsStr(
|
|||
struct AAMemoryLocationImpl : public AAMemoryLocation {
|
||||
|
||||
AAMemoryLocationImpl(const IRPosition &IRP, Attributor &A)
|
||||
: AAMemoryLocation(IRP, A), Allocator(A.Allocator) {}
|
||||
: AAMemoryLocation(IRP, A), Allocator(A.Allocator) {
|
||||
for (unsigned u = 0; u < llvm::CTLog2<VALID_STATE>(); ++u)
|
||||
AccessKind2Accesses[u] = nullptr;
|
||||
}
|
||||
|
||||
~AAMemoryLocationImpl() {
|
||||
// The AccessSets are allocated via a BumpPtrAllocator, we call
|
||||
// the destructor manually.
|
||||
for (auto &It : AccessKind2Accesses)
|
||||
It.getSecond()->~AccessSet();
|
||||
for (unsigned u = 0; u < llvm::CTLog2<VALID_STATE>(); ++u)
|
||||
if (AccessKind2Accesses[u])
|
||||
AccessKind2Accesses[u]->~AccessSet();
|
||||
}
|
||||
|
||||
/// See AbstractAttribute::initialize(...).
|
||||
|
@ -6106,11 +6110,13 @@ struct AAMemoryLocationImpl : public AAMemoryLocation {
|
|||
if (AssumedMLK == NO_LOCATIONS)
|
||||
return true;
|
||||
|
||||
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; CurMLK *= 2) {
|
||||
unsigned Idx = 0;
|
||||
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS;
|
||||
CurMLK *= 2, ++Idx) {
|
||||
if (CurMLK & RequestedMLK)
|
||||
continue;
|
||||
|
||||
if (const AccessSet *Accesses = AccessKind2Accesses.lookup(CurMLK))
|
||||
if (const AccessSet *Accesses = AccessKind2Accesses[Idx])
|
||||
for (const AccessInfo &AI : *Accesses)
|
||||
if (!Pred(AI.I, AI.Ptr, AI.Kind, CurMLK))
|
||||
return false;
|
||||
|
@ -6163,9 +6169,8 @@ protected:
|
|||
|
||||
/// Mapping from *single* memory location kinds, e.g., LOCAL_MEM with the
|
||||
/// value of NO_LOCAL_MEM, to the accesses encountered for this memory kind.
|
||||
using AccessSet = SmallSet<AccessInfo, 8, AccessInfo>;
|
||||
using AccessKind2AccessSetTy = DenseMap<unsigned, AccessSet *>;
|
||||
AccessKind2AccessSetTy AccessKind2Accesses;
|
||||
using AccessSet = SmallSet<AccessInfo, 2, AccessInfo>;
|
||||
AccessSet *AccessKind2Accesses[llvm::CTLog2<VALID_STATE>()];
|
||||
|
||||
/// Return the kind(s) of location that may be accessed by \p V.
|
||||
AAMemoryLocation::MemoryLocationsKind
|
||||
|
@ -6185,7 +6190,7 @@ protected:
|
|||
}
|
||||
|
||||
assert(isPowerOf2_32(MLK) && "Expected a single location set!");
|
||||
auto *&Accesses = AccessKind2Accesses[MLK];
|
||||
auto *&Accesses = AccessKind2Accesses[llvm::Log2_32(MLK)];
|
||||
if (!Accesses)
|
||||
Accesses = new (Allocator) AccessSet();
|
||||
Changed |= Accesses->insert(AccessInfo{I, Ptr, Kind}).second;
|
||||
|
|
Loading…
Reference in New Issue