diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 19:02:06 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 19:02:06 +0000 |
| commit | 2711ca7c28da9134bda2308bb46ec34d189a0126 (patch) | |
| tree | 9fc000a3b386042c7f0b0ccf33d0d9ae1e7f3cb1 /llvm/lib | |
| parent | fcd4569af67b19e04aec436dbd31ad158d6d1e72 (diff) | |
| download | bcm5719-llvm-2711ca7c28da9134bda2308bb46ec34d189a0126.tar.gz bcm5719-llvm-2711ca7c28da9134bda2308bb46ec34d189a0126.zip | |
IR: Store RAUW support and Context in the same pointer, NFC
Add an `LLVMContext &` to `ReplaceableMetadataImpl`, create a class that
either holds a reference to an `LLVMContext` or owns a
`ReplaceableMetadataImpl`, and use the new class in `MDNode`.
- This saves a pointer in `UniquableMDNode` at the cost of a pointer
in `ValueAsMetadata` (which didn't used to store the `LLVMContext`).
There are far more of the former.
- Unifies RAUW support between `MDNodeFwdDecl` (which is going away,
see r226481) and `UniquableMDNode`.
llvm-svn: 226484
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/Metadata.cpp | 14 | ||||
| -rw-r--r-- | llvm/lib/IR/MetadataTracking.cpp | 7 |
2 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 93778c2ca54..5b196388fc4 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -401,6 +401,10 @@ MDNode::MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, MDNodeSubclassData(0) { for (unsigned I = 0, E = MDs.size(); I != E; ++I) setOperand(I, MDs[I]); + + if (Storage == Temporary) + this->Context.makeReplaceable( + make_unique<ReplaceableMetadataImpl>(Context)); } bool MDNode::isResolved() const { @@ -429,7 +433,7 @@ UniquableMDNode::UniquableMDNode(LLVMContext &C, unsigned ID, if (!NumUnresolved) return; - ReplaceableUses.reset(new ReplaceableMetadataImpl); + this->Context.makeReplaceable(make_unique<ReplaceableMetadataImpl>(C)); SubclassData32 = NumUnresolved; } @@ -437,7 +441,7 @@ void UniquableMDNode::resolve() { assert(!isResolved() && "Expected this to be unresolved"); // Move the map, so that this immediately looks resolved. - auto Uses = std::move(ReplaceableUses); + auto Uses = Context.takeReplaceableUses(); SubclassData32 = 0; assert(isResolved() && "Expected this to be resolved"); @@ -499,8 +503,8 @@ void MDNode::dropAllReferences() { setOperand(I, nullptr); if (auto *N = dyn_cast<UniquableMDNode>(this)) if (!N->isResolved()) { - N->ReplaceableUses->resolveAllUses(/* ResolveUsers */ false); - N->ReplaceableUses.reset(); + N->Context.getReplaceableUses()->resolveAllUses(/* ResolveUsers */ false); + (void)N->Context.takeReplaceableUses(); } } @@ -563,7 +567,7 @@ 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(Uniqued); + Context.getReplaceableUses()->replaceAllUsesWith(Uniqued); deleteAsSubclass(); return; } diff --git a/llvm/lib/IR/MetadataTracking.cpp b/llvm/lib/IR/MetadataTracking.cpp index ba97ca033a4..47f0b9366d7 100644 --- a/llvm/lib/IR/MetadataTracking.cpp +++ b/llvm/lib/IR/MetadataTracking.cpp @@ -17,11 +17,8 @@ using namespace llvm; ReplaceableMetadataImpl *ReplaceableMetadataImpl::get(Metadata &MD) { - if (auto *N = dyn_cast<MDNode>(&MD)) { - if (auto *U = dyn_cast<UniquableMDNode>(N)) - return U->ReplaceableUses.get(); - return cast<MDNodeFwdDecl>(N); - } + if (auto *N = dyn_cast<MDNode>(&MD)) + return N->Context.getReplaceableUses(); return dyn_cast<ValueAsMetadata>(&MD); } |

