summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Metadata.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 22:24:52 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 22:24:52 +0000
commite33530909ddf2b72dc4a93f610803f9c129eece1 (patch)
treebd930e72a8f1778b31aa251868c478864b91aad8 /llvm/lib/IR/Metadata.cpp
parent434d4a5a0681bc511eaa899df7b3e9c49358db55 (diff)
downloadbcm5719-llvm-e33530909ddf2b72dc4a93f610803f9c129eece1.tar.gz
bcm5719-llvm-e33530909ddf2b72dc4a93f610803f9c129eece1.zip
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()`. llvm-svn: 226510
Diffstat (limited to 'llvm/lib/IR/Metadata.cpp')
-rw-r--r--llvm/lib/IR/Metadata.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 0e258623368..822a9f5237c 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -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");
OpenPOWER on IntegriCloud