diff options
author | Brian Gesiak <modocache@gmail.com> | 2020-01-15 16:39:39 -0500 |
---|---|---|
committer | Brian Gesiak <modocache@gmail.com> | 2020-01-15 18:27:25 -0500 |
commit | daab9227ff013db431e4ab6045bdbba55b3dd4f3 (patch) | |
tree | 885de8639ac463c9456f4e6ae96e8dbeec3cb3a5 /llvm/lib/IR/Module.cpp | |
parent | 81fc1be601e7a8b73b675d318af9b1ba046fb5f5 (diff) | |
download | llvm-daab9227ff013db431e4ab6045bdbba55b3dd4f3.zip llvm-daab9227ff013db431e4ab6045bdbba55b3dd4f3.tar.gz llvm-daab9227ff013db431e4ab6045bdbba55b3dd4f3.tar.bz2 |
[IR] Module's NamedMD table needn't be 'void *'
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`).
Reviewers: aprantl, dblaikie, chandlerc, pcc, echristo
Reviewed By: dblaikie
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72812
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 271ae12..8ddbffc 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -73,7 +73,6 @@ template class llvm::SymbolTableListTraits<GlobalIFunc>; Module::Module(StringRef MID, LLVMContext &C) : Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL("") { ValSymTab = new ValueSymbolTable(); - NamedMDSymTab = new StringMap<NamedMDNode *>(); Context.addModule(this); } @@ -85,8 +84,8 @@ Module::~Module() { AliasList.clear(); IFuncList.clear(); NamedMDList.clear(); + NamedMDSymTab.clear(); delete ValSymTab; - delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab); } std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const { @@ -250,15 +249,14 @@ GlobalIFunc *Module::getNamedIFunc(StringRef Name) const { NamedMDNode *Module::getNamedMetadata(const Twine &Name) const { SmallString<256> NameData; StringRef NameRef = Name.toStringRef(NameData); - return static_cast<StringMap<NamedMDNode*> *>(NamedMDSymTab)->lookup(NameRef); + return NamedMDSymTab.lookup(NameRef); } /// getOrInsertNamedMetadata - Return the first named MDNode in the module /// with the specified name. This method returns a new NamedMDNode if a /// NamedMDNode with the specified name is not found. NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) { - NamedMDNode *&NMD = - (*static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab))[Name]; + NamedMDNode *&NMD = NamedMDSymTab[Name]; if (!NMD) { NMD = new NamedMDNode(Name); NMD->setParent(this); @@ -270,7 +268,7 @@ NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) { /// eraseNamedMetadata - Remove the given NamedMDNode from this module and /// delete it. void Module::eraseNamedMetadata(NamedMDNode *NMD) { - static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName()); + NamedMDSymTab.erase(NMD->getName()); NamedMDList.erase(NMD->getIterator()); } |