This is an archive of the discontinued LLVM Phabricator instance.

[IR] Module's NamedMD table needn't be 'void *'
ClosedPublic

Authored by modocache on Jan 15 2020, 3:13 PM.

Details

Summary

In July 21 2010 llvm::NamedMDNode was refactored such that it would no
longer subclass llvm::Value:
https://github.com/llvm/llvm-project/commit/2637cc1a38d7336ea30caf

As part of this change, a map type from metadata names to their named
metadata, llvm::MDSymbolTable, was deleted. In its place, the type
of member llvm::Module::NamedMDSymTab was changed, from
llvm::MDSymbolTable to void *. The underlying memory allocations
for this pointer were changed to new StringMap<NamedMDNode *>().

However, as far as I can tell, there's no need for obscuring the
underlying type being pointed to by the void *, and no need for
static casts from void * to StringMap. In fact, I don't think
there's a need for explicit calls to new and delete at all.

This commit changes NamedMDSymTab from a pointer to a reference, which
automatically couples its lifetime with the lifetime of its owning
llvm::Module instance, thus removing the explicit calls to new and
delete in the llvm::Module constructor and destructor. It also
changes the type from void * to a newly defined NamedMDSymTabType,
and removes the static casts.

Test Plan:
An ASAN-enabled build and run of check-all succeeds with this change
(aside from some tests that always fail for me in ASAN for some reason,
such as check-clang SemaTemplate/stack-exhaustion.cpp).

Diff Detail

Event Timeline

modocache created this revision.Jan 15 2020, 3:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2020, 3:13 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
dblaikie accepted this revision.Jan 15 2020, 3:24 PM

Sounds good -t hanks for all the context. Previously this might've been an effort to keep the dependencies of a core header like Module.h small, but since it now has the dependencies this relies on - this change isn't making the situation worse in any way I can think of.

This revision is now accepted and ready to land.Jan 15 2020, 3:24 PM

Previously this might've been an effort to keep the dependencies of a core header like Module.h small, but since it now has the dependencies this relies on - this change isn't making the situation worse in any way I can think of.

I see, thanks, that makes sense. And thanks for the review!

This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.
llvm/lib/IR/Module.cpp
87

Nit: Is this clear useful/needed?

(I don't know about the other ones, but the previous code wasn't doing any explicit "clear()" of the map before deleting it).

dblaikie added inline comments.Jan 17 2020, 5:34 PM
llvm/lib/IR/Module.cpp
87

Faoir point - did that & cleaned up a couple of other things in 46ed93315fceec4c8c3cd3defada501a55eb96e2