mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-28 06:00:28 +00:00
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`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244301 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e06606ffd1
commit
db5b592a6e
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user