ValueMapper: Resolve cycles on the new nodes

Fix a major bug from r265456.  Although it's now much rarer, ValueMapper
sometimes has to duplicate cycles.  The
might-transitively-reference-a-temporary counts don't decrement on their
own when there are cycles, and you need to call MDNode::resolveCycles to
fix it.

r265456 was checking the input nodes to see if they were unresolved.
This is useless; they should never be unresolved.  Instead we should
check the output nodes and resolve cycles on them.

llvm-svn: 266258
This commit is contained in:
Duncan P. N. Exon Smith
2016-04-13 22:54:01 +00:00
parent 3ef4e4a98c
commit 11f60fd65a
2 changed files with 46 additions and 2 deletions

View File

@@ -587,6 +587,7 @@ void MDNodeMapper::mapDistinctNodes() {
void MDNodeMapper::mapUniquedNodes() {
// Construct uniqued nodes, building forward references as necessary.
SmallVector<MDNode *, 16> CyclicNodes;
for (auto *N : POT) {
if (N->isDistinct())
continue;
@@ -601,11 +602,12 @@ void MDNodeMapper::mapUniquedNodes() {
TempMDNode ClonedN = D.Placeholder ? std::move(D.Placeholder) : N->clone();
remapOperands(D, *ClonedN);
M.mapToMetadata(N, MDNode::replaceWithUniqued(std::move(ClonedN)));
CyclicNodes.push_back(MDNode::replaceWithUniqued(std::move(ClonedN)));
M.mapToMetadata(N, CyclicNodes.back());
}
// Resolve cycles.
for (auto *N : POT)
for (auto *N : CyclicNodes)
if (!N->isResolved())
N->resolveCycles();
}