summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 20:36:39 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 20:36:39 +0000
commit946fdcc50cbda9cc30bb78f6c71aa49f3c3ae7ae (patch)
tree0e036a4f09e4072d6ae5ab6faac355df0b5862b5 /llvm/lib/IR
parent0ee02fc9fea7107898390680d925238fa5cc0924 (diff)
downloadbcm5719-llvm-946fdcc50cbda9cc30bb78f6c71aa49f3c3ae7ae.tar.gz
bcm5719-llvm-946fdcc50cbda9cc30bb78f6c71aa49f3c3ae7ae.zip
IR: Remove MDNodeFwdDecl
Remove `MDNodeFwdDecl` (as promised in r226481). Aside from API changes, there's no real functionality change here. `MDNode::getTemporary()` now forwards to `MDTuple::getTemporary()`, which returns a tuple with `isTemporary()` equal to true. The main point is that we can now add temporaries of other `MDNode` subclasses, needed for PR22235 (I introduced `MDNodeFwdDecl` in the first place because I didn't recognize this need, and thought they were only needed to handle forward references). A few things left out of (or highlighted by) this commit: - I've had to remove the (few) uses of `std::unique_ptr<>` to deal with temporaries, since the destructor is no longer public. `getTemporary()` should probably return the equivalent of `std::unique_ptr<T, MDNode::deleteTemporary>`. - `MDLocation::getTemporary()` doesn't exist yet (worse, it actually does exist, but does the wrong thing: `MDNode::getTemporary()` is inherited and returns an `MDTuple`). - `MDNode` now only has one subclass, `UniquableMDNode`, and the distinction between them is actually somewhat confusing. I'll fix those up next. llvm-svn: 226501
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp6
-rw-r--r--llvm/lib/IR/Metadata.cpp24
-rw-r--r--llvm/lib/IR/Verifier.cpp2
3 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 290dbe29c70..c5c11157971 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -337,7 +337,8 @@ void DIDescriptor::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) {
DN = MDNode::get(VMContext, Ops);
}
- auto *Node = cast<MDNodeFwdDecl>(const_cast<MDNode *>(DbgNode));
+ assert(DbgNode->isTemporary() && "Expected temporary node");
+ auto *Node = const_cast<MDNode *>(DbgNode);
Node->replaceAllUsesWith(const_cast<MDNode *>(DN));
MDNode::deleteTemporary(Node);
DbgNode = DN;
@@ -346,7 +347,8 @@ void DIDescriptor::replaceAllUsesWith(LLVMContext &VMContext, DIDescriptor D) {
void DIDescriptor::replaceAllUsesWith(MDNode *D) {
assert(DbgNode && "Trying to replace an unverified type!");
assert(DbgNode != D && "This replacement should always happen");
- auto *Node = cast<MDNodeFwdDecl>(const_cast<MDNode *>(DbgNode));
+ assert(DbgNode->isTemporary() && "Expected temporary node");
+ auto *Node = const_cast<MDNode *>(DbgNode);
Node->replaceAllUsesWith(D);
MDNode::deleteTemporary(Node);
}
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 8d83e1652cd..01394137e8e 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -155,7 +155,8 @@ void ReplaceableMetadataImpl::moveRef(void *Ref, void *New,
}
void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {
- assert(!(MD && isa<MDNodeFwdDecl>(MD)) && "Expected non-temp node");
+ assert(!(MD && isa<MDNode>(MD) && cast<MDNode>(MD)->isTemporary()) &&
+ "Expected non-temp node");
if (UseMap.empty())
return;
@@ -471,13 +472,14 @@ void UniquableMDNode::resolveCycles() {
// Resolve all operands.
for (const auto &Op : operands()) {
- if (!Op)
+ auto *N = dyn_cast_or_null<UniquableMDNode>(Op);
+ if (!N)
continue;
- assert(!isa<MDNodeFwdDecl>(Op) &&
+
+ assert(!N->isTemporary() &&
"Expected all forward declarations to be resolved");
- if (auto *N = dyn_cast<UniquableMDNode>(Op))
- if (!N->isResolved())
- N->resolveCycles();
+ if (!N->isResolved())
+ N->resolveCycles();
}
}
@@ -621,7 +623,7 @@ T *UniquableMDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
N->storeDistinctInContext();
break;
case Temporary:
- llvm_unreachable("Unexpected temporary node");
+ break;
}
return N;
}
@@ -723,13 +725,11 @@ void MDLocation::eraseFromStoreImpl() {
getContext().pImpl->MDLocations.erase(this);
}
-MDNodeFwdDecl *MDNode::getTemporary(LLVMContext &Context,
- ArrayRef<Metadata *> MDs) {
- return MDNodeFwdDecl::get(Context, MDs);
+void MDNode::deleteTemporary(MDNode *N) {
+ assert(N->isTemporary() && "Expected temporary node");
+ cast<UniquableMDNode>(N)->deleteAsSubclass();
}
-void MDNode::deleteTemporary(MDNode *N) { delete cast<MDNodeFwdDecl>(N); }
-
void UniquableMDNode::storeDistinctInContext() {
assert(isResolved() && "Expected resolved nodes");
Storage = Distinct;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4bf2d1a6dc6..f0a149354ae 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -617,7 +617,7 @@ void Verifier::visitMDNode(MDNode &MD) {
}
// Check these last, so we diagnose problems in operands first.
- Assert1(!isa<MDNodeFwdDecl>(MD), "Expected no forward declarations!", &MD);
+ Assert1(!MD.isTemporary(), "Expected no forward declarations!", &MD);
Assert1(MD.isResolved(), "All nodes should be resolved!", &MD);
}
OpenPOWER on IntegriCloud