IR: Add MDNode::replaceWithPermanent()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 10 Feb 2015 19:13:46 +0000 (19:13 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 10 Feb 2015 19:13:46 +0000 (19:13 +0000)
commit4ee4a98eaae16bbf9041acd3bc0f605b03d196e2
treed96a528b2f7d05c661b4ebd3084552754202c905
parent82f1c775a074feaa724948cbc1795336deaa2b4f
IR: Add MDNode::replaceWithPermanent()

Add new API for converting temporaries that may self-reference.
Self-referencing nodes are not allowed to be uniqued, so sending them
into `replaceWithUniqued()` is dangerous (and this commit adds
assertions that prevent it).

`replaceWithPermanent()` has similar semantics to `get()` followed by
calls to `replaceOperandWith()`.  In particular, if there's a
self-reference, it returns a distinct node; otherwise, it returns a
uniqued one.  Like `replaceWithUniqued()` and `replaceWithDistinct()`
(well, it calls out to them) it mutates the temporary node in place if
possible, only calling `replaceAllUsesWith()` on a uniquing collision.

llvm-svn: 228726
llvm/include/llvm/IR/Metadata.h
llvm/lib/IR/Metadata.cpp
llvm/unittests/IR/MetadataTest.cpp