[llvm] r265270 - ValueMapper: Split out mapSimpleMetadata, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 3 12:31:01 PDT 2016
Author: dexonsmith
Date: Sun Apr 3 14:31:01 2016
New Revision: 265270
URL: http://llvm.org/viewvc/llvm-project?rev=265270&view=rev
Log:
ValueMapper: Split out mapSimpleMetadata, NFC
Split out a helper for mapping metadata without operands. This is any
metadata that is not an MDNode, and any MDNode where the answer is known
without looking at operands.
Through some weird twists, this function is co-recursive:
mapSimpleMetadata
=> MapValue
=> materializeInitFor
=> linkFunctionBody
=> RemapInstructions
=> MapMetadata
=> mapSimpleMetadata
I plan to break the recursion in a follow-up.
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=265270&r1=265269&r2=265270&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/ValueMapper.cpp Sun Apr 3 14:31:01 2016
@@ -62,6 +62,9 @@ private:
Metadata *mapMetadataImpl(const Metadata *MD);
Metadata *mapMetadataOp(Metadata *Op);
+ /// Map metadata that doesn't require visiting operands.
+ Optional<Metadata *> mapSimpleMetadata(const Metadata *MD);
+
/// Remap the operands of an MDNode.
///
/// If \c Node is temporary, uniquing cycles are ignored. If \c Node is
@@ -317,7 +320,7 @@ Metadata *Mapper::mapUniquedNode(const M
return MDNode::replaceWithUniqued(std::move(ClonedMD));
}
-Metadata *Mapper::mapMetadataImpl(const Metadata *MD) {
+Optional<Metadata *> Mapper::mapSimpleMetadata(const Metadata *MD) {
// If the value already exists in the map, use it.
if (Optional<Metadata *> NewMD = VM.getMappedMD(MD))
return *NewMD;
@@ -346,16 +349,22 @@ Metadata *Mapper::mapMetadataImpl(const
return nullptr;
}
- // Note: this cast precedes the Flags check so we always get its associated
- // assertion.
- const MDNode *Node = cast<MDNode>(MD);
+ assert(isa<MDNode>(MD) && "Expected a metadata node");
// If this is a module-level metadata and we know that nothing at the
// module level is changing, then use an identity mapping.
if (Flags & RF_NoModuleLevelChanges)
return mapToSelf(MD);
+ return None;
+}
+
+Metadata *Mapper::mapMetadataImpl(const Metadata *MD) {
+ if (Optional<Metadata *> NewMD = mapSimpleMetadata(MD))
+ return *NewMD;
+
// Require resolved nodes whenever metadata might be remapped.
+ auto *Node = cast<MDNode>(MD);
assert(Node->isResolved() && "Unexpected unresolved node");
if (Node->isDistinct())
More information about the llvm-commits
mailing list