[PATCH] D137933: [llvm-debuginfo-analyzer] 08a - Memory Management

Carlos Alberto Enciso via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 04:31:41 PST 2023


CarlosAlbertoEnciso added a comment.

I have explored several options for how to model the pointer ownership, and I think `SpecificBumpPtrAllocator` is probably the best, my reasoning is below.

Explored options:
**Move ownership to scope nodes with SmartPointers (Very difficult).**
The containers within the scope, will contain smart pointers. The main complication is that there are quite few functions that are executed from the point where the logical element is created up to the point where the element is added to its scope:

  Element is created: createElement() -> SmartPointer
  ...
  Element attributes are updated: func1(), ... -> rawPointer
  ...
  Element is added to scope parent: addElement() --> rawPointer

- The functions `addElement()`, `func1()`, ... can use a raw pointer extracted from the smart pointer.
- This involves quite a lot of changes specially in the `CodeView Reader` which uses visitor modules (logical, types and symbols) to traverse the debug information.

**Using LLVM's BumpPtrAllocator (Discarded).**
Destructors are not called.

**Using SpecificBumpPtrAllocator (Small changes).**
As the Reader creates different variants of logical elements (see above), it is required to have individual allocators for each variant:

  SpecificBumpPtrAllocator<LVScope> Scopes;
  SpecificBumpPtrAllocator<LVScopeRoot> ScopesRoot;
  ...
  SpecificBumpPtrAllocator<LVType> Types;
  SpecificBumpPtrAllocator<LVTypeDefinition> TypesDefinition;
  ...
  SpecificBumpPtrAllocator<LVLine> Lines;
  SpecificBumpPtrAllocator<LVLineDebug> LinesDebug;
  ...

Each variant will be created by a specific function:

  createScope(), createScopeRoot(), ...
  createType(), createTypeDefinition(), ...
  createLine(), createLineDebug(), ...

**Options summary:**
//a) Keep the bucket with smart pointers//

  class LVReader {
    // Allocated logical elements.
    SmallVector<std::unique_ptr<LVObject>> AllocatedObjects;
  };

//b) Use SpecificBumpPtrAllocator//

  class LVReader {
    ...
    SpecificBumpPtrAllocator<LVScope> Scopes;
    SpecificBumpPtrAllocator<LVScopeRoot> ScopesRoot;
    ...
  };

The current patch implements option** (b).**


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137933/new/

https://reviews.llvm.org/D137933



More information about the llvm-commits mailing list