[Attributor][NFC] Replace the nested AAMap with a key pair

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: 512375 (362871/s)
temporary memory allocations: 98746 (69933/s)
peak heap memory consumption: 22.54MB
peak RSS (including heaptrack overhead): 106.78MB
total memory leaked: 269.10KB
```

After:
```
calls to allocation functions: 509833 (338534/s)
temporary memory allocations: 98902 (65671/s)
peak heap memory consumption: 18.71MB
peak RSS (including heaptrack overhead): 103.00MB
total memory leaked: 269.10KB
```

Difference:
```
calls to allocation functions: -2542 (-27042/s)
temporary memory allocations: 156 (1659/s)
peak heap memory consumption: -3.83MB
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B
```
This commit is contained in:
Johannes Doerfert 2020-04-21 21:34:39 -05:00
parent 95e0d28b71
commit 14cb0bdf2b
2 changed files with 8 additions and 18 deletions

View File

@ -885,12 +885,10 @@ struct Attributor {
// Put the attribute in the lookup map structure and the container we use to
// keep track of all attributes.
const IRPosition &IRP = AA.getIRPosition();
Kind2AAMapTy *&Kind2AA = AAMap[IRP];
if (!Kind2AA)
Kind2AA = new (Allocator) Kind2AAMapTy();
AbstractAttribute *&AAPtr = AAMap[{&AAType::ID, IRP}];
assert(!(*Kind2AA)[&AAType::ID] && "Attribute already in map!");
(*Kind2AA)[&AAType::ID] = &AA;
assert(!AAPtr && "Attribute already in map!");
AAPtr = &AA;
AllAbstractAttributes.push_back(&AA);
return AA;
@ -1278,13 +1276,11 @@ private:
// Lookup the abstract attribute of type AAType. If found, return it after
// registering a dependence of QueryingAA on the one returned attribute.
Kind2AAMapTy *Kind2AA = AAMap.lookup(IRP);
if (!Kind2AA)
AbstractAttribute *AAPtr = AAMap.lookup({&AAType::ID, IRP});
if (!AAPtr)
return nullptr;
AAType *AA = static_cast<AAType *>((*Kind2AA)[&AAType::ID]);
if (!AA)
return nullptr;
AAType *AA = static_cast<AAType *>(AAPtr);
// Do not register a dependence on an attribute with an invalid state.
if (TrackDependence && AA->getState().isValidState())
@ -1309,9 +1305,8 @@ private:
/// on the outer level, and the addresses of the static member (AAType::ID) on
/// the inner level.
///{
using Kind2AAMapTy =
SmallDenseMap<const char *, AbstractAttribute *, /*InlineBuckets=*/32>;
DenseMap<IRPosition, Kind2AAMapTy *> AAMap;
using AAMapKeyTy = std::pair<const char *, IRPosition>;
DenseMap<AAMapKeyTy, AbstractAttribute *> AAMap;
///}
/// A map from abstract attributes to the ones that queried them through calls

View File

@ -493,11 +493,6 @@ Attributor::~Attributor() {
for (AbstractAttribute *AA : AllAbstractAttributes)
AA->~AbstractAttribute();
// The Kind2AAMap objects are allocated via a BumpPtrAllocator, we call
// the destructor manually.
for (auto &It : AAMap)
It.getSecond()->~Kind2AAMapTy();
// The QueryMapValueTy objects are allocated via a BumpPtrAllocator, we call
// the destructor manually.
for (auto &It : QueryMap)