llvm::MapMetadata

Lookup or compute a mapping for a piece of metadata.

Synopsis

Declared in <llvm/Transforms/Utils/ValueMapper.h>

Metadata*
MapMetadata(
    Metadata const* MD,
    ValueToValueMapTy& VM,
    RemapFlags Flags = RF_None,
    ValueMapTypeRemapper* TypeMapper = nullptr,
    ValueMaterializer* Materializer = nullptr,
    MetadataPredicate const* IdentityMD = nullptr);

Description

Compute and memoize a mapping for MD.

1. If MD is mapped, return it. 2. Else if RF_NoModuleLevelChanges or MD is an MDString, return MD. 3. Else if MD is a ConstantAsMetadata, call MapValue() and re-wrap its return (returning nullptr on nullptr). 4. Else if IdentityMD predicate returns true for MD then add an identity mapping for it and return it. 5. Else, MD is an MDNode. These are remapped, along with their transitive operands. Distinct nodes are duplicated or moved depending on RF_MoveDistinctNodes. Uniqued nodes are remapped like constants.

NOTE

LocalAsMetadata is completely unsupported by MapMetadata. Instead, use MapValue() with its wrapping MetadataAsValue instance.

Return Value

The mapped metadata, or nullptr when mapping fails.

Parameters

NameDescription
MDMetadata to look up or map.
VMMapping from original values to remapped values.
FlagsRemapping flags that control mapper behavior.
TypeMapperOptional callback that remaps types while mapping values.
MaterializerOptional callback that materializes unmapped values.
IdentityMDOptional predicate for metadata that maps onto itself.