[llvm] r244301 - ValueMapper: Pull out helper to resolve cycles, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 17:39:26 PDT 2015


Author: dexonsmith
Date: Thu Aug  6 19:39:26 2015
New Revision: 244301

URL: http://llvm.org/viewvc/llvm-project?rev=244301&view=rev
Log:
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`.

Modified:
    llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp

Modified: llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp?rev=244301&r1=244300&r2=244301&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Thu Aug  6 19:39:26 2015
@@ -183,6 +183,13 @@ static Metadata *mapMetadataOp(Metadata
   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 Metada
   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 Metada
     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;




More information about the llvm-commits mailing list