diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-20 00:01:43 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-20 00:01:43 +0000 |
commit | fed199a75859a176a22e4135980a1a497b64e628 (patch) | |
tree | 28f0d754ef17b6a0eaa6db860f2865b37b25a800 /llvm/lib/IR/Metadata.cpp | |
parent | d5ac1ab65d4c305cfbf107f2dedfdd94474ffa37 (diff) | |
download | bcm5719-llvm-fed199a75859a176a22e4135980a1a497b64e628.tar.gz bcm5719-llvm-fed199a75859a176a22e4135980a1a497b64e628.zip |
IR: Introduce GenericDwarfNode
As part of PR22235, introduce `DwarfNode` and `GenericDwarfNode`. The
former is a metadata node with a DWARF tag. The latter matches our
current (generic) schema of a header with string (and stringified
integer) data and an arbitrary number of operands.
This doesn't move it into place yet; that change will require a large
number of testcase updates.
llvm-svn: 226529
Diffstat (limited to 'llvm/lib/IR/Metadata.cpp')
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 0ce704c7c3d..5f5708565d4 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -397,11 +397,14 @@ void MDNode::operator delete(void *Mem) { } MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, - ArrayRef<Metadata *> MDs) - : Metadata(ID, Storage), NumOperands(MDs.size()), NumUnresolved(0), - Context(Context) { - for (unsigned I = 0, E = MDs.size(); I != E; ++I) - setOperand(I, MDs[I]); + ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2) + : Metadata(ID, Storage), NumOperands(Ops1.size() + Ops2.size()), + NumUnresolved(0), Context(Context) { + unsigned Op = 0; + for (Metadata *MD : Ops1) + setOperand(Op++, MD); + for (Metadata *MD : Ops2) + setOperand(Op++, MD); if (isDistinct()) return; @@ -527,6 +530,10 @@ void MDTuple::recalculateHash() { setHash(MDTupleInfo::KeyTy::calculateHash(this)); } +void GenericDwarfNode::recalculateHash() { + setHash(GenericDwarfNodeInfo::KeyTy::calculateHash(this)); +} + void MDNode::dropAllReferences() { for (unsigned I = 0, E = NumOperands; I != E; ++I) setOperand(I, nullptr); @@ -621,6 +628,9 @@ MDNode *MDNode::uniquify() { case MDTupleKind: cast<MDTuple>(this)->recalculateHash(); break; + case GenericDwarfNodeKind: + cast<GenericDwarfNode>(this)->recalculateHash(); + break; } // Try to insert into uniquing store. @@ -733,6 +743,29 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line, Storage, Context.pImpl->MDLocations); } +GenericDwarfNode *GenericDwarfNode::getImpl(LLVMContext &Context, unsigned Tag, + MDString *Header, + ArrayRef<Metadata *> DwarfOps, + StorageType Storage, + bool ShouldCreate) { + unsigned Hash = 0; + if (Storage == Uniqued) { + GenericDwarfNodeInfo::KeyTy Key(Tag, Header, DwarfOps); + if (auto *N = getUniqued(Context.pImpl->GenericDwarfNodes, Key)) + return N; + if (!ShouldCreate) + return nullptr; + Hash = Key.getHash(); + } else { + assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); + } + + Metadata *PreOps[] = {Header}; + return storeImpl(new (DwarfOps.size() + 1) GenericDwarfNode( + Context, Storage, Hash, Tag, PreOps, DwarfOps), + Storage, Context.pImpl->GenericDwarfNodes); +} + void MDNode::deleteTemporary(MDNode *N) { assert(N->isTemporary() && "Expected temporary node"); N->deleteAsSubclass(); @@ -743,6 +776,8 @@ void MDNode::storeDistinctInContext() { Storage = Distinct; if (auto *T = dyn_cast<MDTuple>(this)) T->setHash(0); + else if (auto *G = dyn_cast<GenericDwarfNode>(this)) + G->setHash(0); getContext().pImpl->DistinctMDNodes.insert(this); } |