IR: Allow temporary nodes to become uniqued or distinct

Add `MDNode::replaceWithUniqued()` and `MDNode::replaceWithDistinct()`,
which mutate temporary nodes to become uniqued or distinct.  On uniquing
collisions, the unique version is returned and the node is deleted.

This takes advantage of temporary nodes being folded back in, and should
let me clean up some awkward logic in `MapMetadata()`.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-19 22:24:52 +00:00
parent 65bb48b6fc
commit 37c7ccc40c
3 changed files with 161 additions and 0 deletions

View File

@@ -436,6 +436,33 @@ unsigned UniquableMDNode::countUnresolvedOperands() const {
return NumUnresolved;
}
void UniquableMDNode::makeUniqued() {
assert(isTemporary() && "Expected this to be temporary");
assert(!isResolved() && "Expected this to be unresolved");
// Make this 'uniqued'.
Storage = Uniqued;
if (unsigned NumUnresolved = countUnresolvedOperands())
SubclassData32 = NumUnresolved;
else
resolve();
assert(isUniqued() && "Expected this to be uniqued");
}
void UniquableMDNode::makeDistinct() {
assert(isTemporary() && "Expected this to be temporary");
assert(!isResolved() && "Expected this to be unresolved");
// Pretend to be uniqued, resolve the node, and then store in distinct table.
Storage = Uniqued;
resolve();
storeDistinctInContext();
assert(isDistinct() && "Expected this to be distinct");
assert(isResolved() && "Expected this to be resolved");
}
void UniquableMDNode::resolve() {
assert(isUniqued() && "Expected this to be uniqued");
assert(!isResolved() && "Expected this to be unresolved");