diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-12 20:56:33 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-12 20:56:33 +0000 |
commit | bf68e80d0650c816f0ba8ed1a1f90c0f43701996 (patch) | |
tree | dff4dd11f37cf7c7fac036699af37851149bcea4 /llvm/lib | |
parent | 6b1f4659f98d3471dd8e821b5e60ca9abdb78421 (diff) | |
download | bcm5719-llvm-bf68e80d0650c816f0ba8ed1a1f90c0f43701996.tar.gz bcm5719-llvm-bf68e80d0650c816f0ba8ed1a1f90c0f43701996.zip |
IR: Prepare for a new UniquableMDNode subclass, NFC
Add generic dispatch for the parts of `UniquableMDNode` that cast to
`MDTuple`. This makes adding other subclasses (like PR21433's
`MDLocation`) easier.
llvm-svn: 225697
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 67 |
2 files changed, 57 insertions, 12 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index c78b76021da..d47a0d332fb 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -142,7 +142,7 @@ LLVMContextImpl::~LLVMContextImpl() { I->dropAllReferences(); for (UniquableMDNode *I : DistinctMDNodes) - delete cast<MDTuple>(I); + I->deleteAsSubclass(); for (MDTuple *I : MDTuples) delete I; diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index fa1f302568f..13844313925 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -525,8 +525,8 @@ void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) { return; } - auto &Store = getContext().pImpl->MDTuples; - Store.erase(cast<MDTuple>(this)); + // This node is uniqued. + eraseFromStore(); Metadata *Old = getOperand(Op); setOperand(Op, New); @@ -540,15 +540,10 @@ void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) { } // Re-unique the node. - cast<MDTuple>(this)->recalculateHash(); - MDTupleInfo::KeyTy Key(cast<MDTuple>(this)); - auto I = Store.find_as(Key); - if (I == Store.end()) { - Store.insert(cast<MDTuple>(this)); - + auto *Uniqued = uniquify(); + if (Uniqued == this) { if (!isResolved()) resolveAfterOperandChange(Old, New); - return; } @@ -560,8 +555,8 @@ void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) { // dropAllReferences(), but we still need the use-list). for (unsigned O = 0, E = getNumOperands(); O != E; ++O) setOperand(O, nullptr); - ReplaceableUses->replaceAllUsesWith(*I); - delete cast<MDTuple>(this); + ReplaceableUses->replaceAllUsesWith(Uniqued); + deleteAsSubclass(); return; } @@ -569,6 +564,41 @@ void UniquableMDNode::handleChangedOperand(void *Ref, Metadata *New) { storeDistinctInContext(); } +void UniquableMDNode::deleteAsSubclass() { + switch (getMetadataID()) { + default: + llvm_unreachable("Invalid subclass of UniquableMDNode"); +#define HANDLE_UNIQUABLE_LEAF(CLASS) \ + case CLASS##Kind: \ + delete cast<CLASS>(this); \ + break; +#include "llvm/IR/Metadata.def" + } +} + +UniquableMDNode *UniquableMDNode::uniquify() { + switch (getMetadataID()) { + default: + llvm_unreachable("Invalid subclass of UniquableMDNode"); +#define HANDLE_UNIQUABLE_LEAF(CLASS) \ + case CLASS##Kind: \ + return cast<CLASS>(this)->uniquifyImpl(); +#include "llvm/IR/Metadata.def" + } +} + +void UniquableMDNode::eraseFromStore() { + switch (getMetadataID()) { + default: + llvm_unreachable("Invalid subclass of UniquableMDNode"); +#define HANDLE_UNIQUABLE_LEAF(CLASS) \ + case CLASS##Kind: \ + cast<CLASS>(this)->eraseFromStoreImpl(); \ + break; +#include "llvm/IR/Metadata.def" + } +} + MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs, bool ShouldCreate) { MDTupleInfo::KeyTy Key(MDs); @@ -593,6 +623,21 @@ MDTuple *MDTuple::getDistinct(LLVMContext &Context, ArrayRef<Metadata *> MDs) { return N; } +MDTuple *MDTuple::uniquifyImpl() { + recalculateHash(); + MDTupleInfo::KeyTy Key(this); + + auto &Store = getContext().pImpl->MDTuples; + auto I = Store.find_as(Key); + if (I == Store.end()) { + Store.insert(this); + return this; + } + return *I; +} + +void MDTuple::eraseFromStoreImpl() { getContext().pImpl->MDTuples.erase(this); } + MDNodeFwdDecl *MDNode::getTemporary(LLVMContext &Context, ArrayRef<Metadata *> MDs) { return MDNodeFwdDecl::get(Context, MDs); |