IR: Return unique_ptr from MDNode::getTemporary()

Change `MDTuple::getTemporary()` and `MDLocation::getTemporary()` to
return (effectively) `std::unique_ptr<T, MDNode::deleteTemporary>`, and
clean up call sites.  (For now, `DIBuilder` call sites just call
`release()` immediately.)

There's an accompanying change in each of clang and polly to use the new
API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226504 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-19 21:30:18 +00:00
parent a23cc6a1ea
commit f9eaea701d
10 changed files with 77 additions and 81 deletions
+4 -7
View File
@@ -249,12 +249,11 @@ static Metadata *mapDistinctNode(const UniquableMDNode *Node,
// In general we need a dummy node, since whether the operands are null can
// affect the size of the node.
MDTuple *Dummy = MDTuple::getTemporary(Node->getContext(), None);
mapToMetadata(VM, Node, Dummy);
auto Dummy = MDTuple::getTemporary(Node->getContext(), None);
mapToMetadata(VM, Node, Dummy.get());
Metadata *NewMD = cloneMDNode(Node, VM, Flags, TypeMapper, Materializer,
/* IsDistinct */ true);
Dummy->replaceAllUsesWith(NewMD);
MDNode::deleteTemporary(Dummy);
return mapToMetadata(VM, Node, NewMD);
}
@@ -285,14 +284,13 @@ static Metadata *mapUniquedNode(const UniquableMDNode *Node,
assert(Node->isUniqued() && "Expected uniqued node");
// Create a dummy node in case we have a metadata cycle.
MDTuple *Dummy = MDTuple::getTemporary(Node->getContext(), None);
mapToMetadata(VM, Node, Dummy);
auto Dummy = MDTuple::getTemporary(Node->getContext(), None);
mapToMetadata(VM, Node, Dummy.get());
// Check all operands to see if any need to be remapped.
if (!shouldRemapUniquedNode(Node, VM, Flags, TypeMapper, Materializer)) {
// Use an identity mapping.
mapToSelf(VM, Node);
MDNode::deleteTemporary(Dummy);
return const_cast<Metadata *>(static_cast<const Metadata *>(Node));
}
@@ -300,7 +298,6 @@ static Metadata *mapUniquedNode(const UniquableMDNode *Node,
Metadata *NewMD = cloneMDNode(Node, VM, Flags, TypeMapper, Materializer,
/* IsDistinct */ false);
Dummy->replaceAllUsesWith(NewMD);
MDNode::deleteTemporary(Dummy);
return mapToMetadata(VM, Node, NewMD);
}