summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-08-07 00:39:26 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-08-07 00:39:26 +0000
commitc9fdbdb78dd06ca1cf3d87f98c75ba7e4fe529e1 (patch)
tree920639ee93cb7c2bd208bd58431584a654d26184 /llvm/lib/Transforms/Utils
parentdb8803b05af9a7ae7bcf254f35fcabd50e2af976 (diff)
downloadbcm5719-llvm-c9fdbdb78dd06ca1cf3d87f98c75ba7e4fe529e1.tar.gz
bcm5719-llvm-c9fdbdb78dd06ca1cf3d87f98c75ba7e4fe529e1.zip
ValueMapper: Pull out helper to resolve cycles, NFC
Pull out a helper for resolving uniquing cycles of `Metadata` to remove the boiler-plate of downcasting to `MDNode`. llvm-svn: 244301
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 5fdd890e5d8..85c751f311d 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -183,6 +183,13 @@ static Metadata *mapMetadataOp(Metadata *Op,
return nullptr;
}
+/// Resolve uniquing cycles involving the given metadata.
+static void resolveCycles(Metadata *MD) {
+ if (auto *N = dyn_cast_or_null<MDNode>(MD))
+ if (!N->isResolved())
+ N->resolveCycles();
+}
+
/// Remap the operands of an MDNode.
static bool remapOperands(MDNode &Node,
SmallVectorImpl<MDNode *> &DistinctWorklist,
@@ -321,11 +328,8 @@ Metadata *llvm::MapMetadata(const Metadata *MD, ValueToValueMapTy &VM,
if (Flags & RF_NoModuleLevelChanges)
return NewMD;
- // If the top-level metadata was a uniqued MDNode, it could be involved in a
- // uniquing cycle.
- if (auto *N = dyn_cast<MDNode>(NewMD))
- if (!N->isResolved())
- N->resolveCycles();
+ // Resolve cycles involving the entry metadata.
+ resolveCycles(NewMD);
// Remap the operands of distinct MDNodes.
while (!DistinctWorklist.empty()) {
@@ -335,9 +339,7 @@ Metadata *llvm::MapMetadata(const Metadata *MD, ValueToValueMapTy &VM,
if (remapOperands(*N, DistinctWorklist, VM, Flags, TypeMapper,
Materializer))
for (Metadata *MD : N->operands())
- if (auto *Op = dyn_cast_or_null<MDNode>(MD))
- if (!Op->isResolved())
- Op->resolveCycles();
+ resolveCycles(MD);
}
return NewMD;
OpenPOWER on IntegriCloud