From 9786f33c04ee94d60171f99a44185a1c57046bf6 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sun, 3 Apr 2016 19:31:01 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265270 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/ValueMapper.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 64e91852a58..01a29cd60e7 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -62,6 +62,9 @@ private: Metadata *mapMetadataImpl(const Metadata *MD); Metadata *mapMetadataOp(Metadata *Op); + /// Map metadata that doesn't require visiting operands. + Optional 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 MDNode *Node) { return MDNode::replaceWithUniqued(std::move(ClonedMD)); } -Metadata *Mapper::mapMetadataImpl(const Metadata *MD) { +Optional Mapper::mapSimpleMetadata(const Metadata *MD) { // If the value already exists in the map, use it. if (Optional NewMD = VM.getMappedMD(MD)) return *NewMD; @@ -346,16 +349,22 @@ Metadata *Mapper::mapMetadataImpl(const Metadata *MD) { return nullptr; } - // Note: this cast precedes the Flags check so we always get its associated - // assertion. - const MDNode *Node = cast(MD); + assert(isa(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 NewMD = mapSimpleMetadata(MD)) + return *NewMD; + // Require resolved nodes whenever metadata might be remapped. + auto *Node = cast(MD); assert(Node->isResolved() && "Unexpected unresolved node"); if (Node->isDistinct()) -- 2.11.0