[PATCH] D124548: [Metadata] Add a resize/reserve capability for MDNodes
Wolfgang Pieb via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 27 11:49:42 PDT 2022
wolfgangp created this revision.
wolfgangp added a reviewer: dexonsmith.
Herald added a subscriber: hiraditya.
Herald added a project: All.
wolfgangp requested review of this revision.
Herald added a project: LLVM.
This patch a starting point for what's discussed in D118416 <https://reviews.llvm.org/D118416>, which is adding a resize capability to MDNodes.
We're distinguishing between small (< 16 operands) and large MDNodes, with the latter having their operands allocated in hung-off storage. Temporary and distinct MDNodes can be resized (to a larger operand capacity, they can't be made smaller), to which end a pointer to separately allocated hung-off storage is kept in the location of the co-allocated operands. This means that MDNodes with 0 operands ('tiny') need some extra space allocated for the pointer, which is not necessary for uniqued MDNodes with 0 operands. In order to distinguish the 2 tiny node types we use the concept 'tiny resizable' and 'tiny fixed' MDNodes (in addition to large and small). Note that this extra complexity could be eliminated if we're OK with allocating extra space even for uniqued tiny nodes. Only 2-3% of MDNodes seem to have 0 operands, so maybe this would not be a big deal.
The patch does not (yet) address the O(N) issue that arises from handling ModuleFlags of type "Append" during LTO, though it does fix the memory issue mentioned in 51893 <https://github.com/llvm/llvm-project/issues/51893>. For that we'd presumably want to scan all participating modules and reserve enough space for the operands from the start. This will be addressed in a later patch.
I didn't add a push_back() interface because there wasn't a client for it, but it can be easily added if needed. I named the resize method 'reserve' because we don't support shrinking anything.
For now, only MDTuples can be resized.
AFAICT, there is no effect on bitcode reading or writing.
https://reviews.llvm.org/D124548
Files:
llvm/include/llvm/IR/Metadata.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/IR/Metadata.cpp
llvm/lib/Linker/IRMover.cpp
llvm/lib/Transforms/Instrumentation/CGProfile.cpp
llvm/test/Instrumentation/cgprofile.ll
llvm/test/Linker/module-flags-8-a.ll
llvm/test/Linker/module-flags-dont-change-others.ll
llvm/test/Transforms/FunctionImport/cg_profile.ll
llvm/unittests/IR/MetadataTest.cpp
llvm/unittests/Linker/LinkModulesTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124548.425572.patch
Type: text/x-patch
Size: 33709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220427/2992be35/attachment.bin>
More information about the llvm-commits
mailing list