[RFC] Remove User::OperandList

Pete Cooper peter_cooper at apple.com
Thu May 28 11:30:50 PDT 2015


Hi all

This series of patches removes around 2.5% of peak memory by computing OperandList instead of always storing it in User.

The majority of the patches are cleanup and refactoring to make OperandList and NumOperands be managed entirely in User and not have subclasses changing their values directly.  The first few patches also move all the ‘hung off uses’ logic for PhiNode/SwitchInst/LandingPadInst/IndirectBr in to User as that code was particularly heavy on hacking on the OperandList.

The OperandList itself was never actually required for all subclasses of User.  The hung off cases needed it as they actually allocate memory for operands, but the majority of instructions for example allocate a fixed size array of Use intrusively in User::new.  We can get to the first operand for these instructions by subtracting (NumOperands * sizeof(Use)) from the User this pointer.  We use the pointer arithmetic on these cases, and in the hung off case we allocate the Use* in User::new instead of the Use[N] array.  This requires that we have another User::new for hung off uses.

The main change here is actually in 0008 which changes getOperandList() from

Use *getOperandList() const {
  return LegacyOperandList;
}

to

  const Use *getOperandList() const {
    if (HasHungOffUses) {
      Use * const*Storage = reinterpret_cast<Use* const*>(this) - 1;
      return *Storage;
    }
    const Use *Storage = reinterpret_cast<const Use*>(this) - NumOperands;
    return Storage;
  }

The numbers are also in 0008, but to give them here:

On 'opt -O2 verify-uselistorder.lto.bc', peak memory usage prior to this change is 149MB and after is 143MB so the savings are around 2.5% of peak.

Looking at some passes which allocate many Instructions and Values, parseIR drops from 54.25MB to 52.21MB while the Inliner calls to Instruction::clone() drops from 28.20MB to 27.05MB.

Comments welcome.

Cheers,
Pete

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Move-the-special-Phi-logic-for-hung-off-uses-in-to-U.patch
Type: application/octet-stream
Size: 4062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Make-User-track-whether-a-class-has-hung-off-uses-an.patch
Type: application/octet-stream
Size: 4356 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Delete-User-dropHungOffUses-and-move-it-in-to-User-w.patch
Type: application/octet-stream
Size: 2577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Add-User-reallocHungoffUses-and-use-it-to-grow-the-h.patch
Type: application/octet-stream
Size: 4774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Stop-returning-a-Use-from-allocHungOffUses.patch
Type: application/octet-stream
Size: 6336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Added-a-version-of-User-new-for-hung-off-uses.patch
Type: application/octet-stream
Size: 24750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-Replace-all-accesses-to-User-OperandList-with-getter.patch
Type: application/octet-stream
Size: 12278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-Move-OperandList-to-be-allocated-prior-to-User-for-h.patch
Type: application/octet-stream
Size: 6331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0007.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-Rename-NumOperands-to-make-it-clear-its-managed-by-t.patch
Type: application/octet-stream
Size: 17184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150528/13ad4883/attachment-0008.obj>


More information about the llvm-commits mailing list