This is an archive of the discontinued LLVM Phabricator instance.

[llvm][AsmPrinter][NFC] Cleanup `GCMetadataPrinters` field
ClosedPublic

Authored by zero9178 on Dec 29 2022, 4:36 AM.

Details

Summary

The field is currently void*, which was originlly chosen in 2010 to not need to include DenseMap. Since then, DenseMap has been included in the header file anyways, so there is no more need to for the indirection via void* and the cruft around it can be removed.

Diff Detail

Event Timeline

zero9178 created this revision.Dec 29 2022, 4:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2022, 4:36 AM
zero9178 requested review of this revision.Dec 29 2022, 4:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2022, 4:36 AM
dblaikie accepted this revision.Dec 29 2022, 5:02 AM

Sounds good - if you've got any links to the previous conversation that mentions the justification of using void*, might be good to link to those references in the commit message for completeness.

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3822–3835

This could be modified (in a separate change) to avoid doing two lookups (one find, one insert) up GCMetadataPrinters in the cache miss case by doing something like this:

auto [GCPI, Inserted] = GCMetadataPrinters.insert({&S, nullptr});
if (!Inserted)
  return GCPI->second.get();
auto Name = S.getName();
for (...) {
  if (...) {
    ...
    GCPI->second = std::move(GMP);
    return GCPI->second.get();
  }
}

(assuming none of the operations (like GCMetaPrinter.instantiate()) cause other modifications to the map that would invalidate the iterator between the current find and insert calls)

This revision is now accepted and ready to land.Dec 29 2022, 5:02 AM
zero9178 updated this revision to Diff 485609.Dec 29 2022, 5:52 AM

Fold the find-insert calls in the dense map to a single insert

zero9178 marked an inline comment as done.Dec 29 2022, 5:54 AM

Sounds good - if you've got any links to the previous conversation that mentions the justification of using void*, might be good to link to those references in the commit message for completeness.

I thought I had found a more elaborate discussion back when I actually wrote this change, but right now I can only find the original commit that explicitly did that change (https://github.com/llvm/llvm-project/commit/2cf5f9ec05d62dac79c0df240e0b847d3658b084).
Not explicitly said, but its the only intention I can infer from the commit description

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
3822–3835

Thought it was a minor change so updated the diff to include it as well

MaskRay accepted this revision.Dec 29 2022, 10:25 AM
This revision was landed with ongoing or failed builds.Dec 29 2022, 11:47 AM
This revision was automatically updated to reflect the committed changes.
zero9178 marked an inline comment as done.