LLVM API Documentation

ValueMapper.h
Go to the documentation of this file.
00001 //===- ValueMapper.h - Remapping for constants and metadata -----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the MapValue interface which is used by various parts of
00011 // the Transforms/Utils library to implement cloning and linking facilities.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
00016 #define LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
00017 
00018 #include "llvm/IR/ValueMap.h"
00019 
00020 namespace llvm {
00021   class Value;
00022   class Instruction;
00023   typedef ValueMap<const Value *, WeakVH> ValueToValueMapTy;
00024 
00025   /// ValueMapTypeRemapper - This is a class that can be implemented by clients
00026   /// to remap types when cloning constants and instructions.
00027   class ValueMapTypeRemapper {
00028     virtual void anchor();  // Out of line method.
00029   public:
00030     virtual ~ValueMapTypeRemapper() {}
00031 
00032     /// remapType - The client should implement this method if they want to
00033     /// remap types while mapping values.
00034     virtual Type *remapType(Type *SrcTy) = 0;
00035   };
00036 
00037   /// ValueMaterializer - This is a class that can be implemented by clients
00038   /// to materialize Values on demand.
00039   class ValueMaterializer {
00040     virtual void anchor(); // Out of line method.
00041   public:
00042     virtual ~ValueMaterializer() {}
00043 
00044     /// materializeValueFor - The client should implement this method if they
00045     /// want to generate a mapped Value on demand. For example, if linking
00046     /// lazily.
00047     virtual Value *materializeValueFor(Value *V) = 0;
00048   };
00049 
00050   /// RemapFlags - These are flags that the value mapping APIs allow.
00051   enum RemapFlags {
00052     RF_None = 0,
00053 
00054     /// RF_NoModuleLevelChanges - If this flag is set, the remapper knows that
00055     /// only local values within a function (such as an instruction or argument)
00056     /// are mapped, not global values like functions and global metadata.
00057     RF_NoModuleLevelChanges = 1,
00058 
00059     /// RF_IgnoreMissingEntries - If this flag is set, the remapper ignores
00060     /// entries that are not in the value map.  If it is unset, it aborts if an
00061     /// operand is asked to be remapped which doesn't exist in the mapping.
00062     RF_IgnoreMissingEntries = 2
00063   };
00064 
00065   static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {
00066     return RemapFlags(unsigned(LHS)|unsigned(RHS));
00067   }
00068 
00069   Value *MapValue(const Value *V, ValueToValueMapTy &VM,
00070                   RemapFlags Flags = RF_None,
00071                   ValueMapTypeRemapper *TypeMapper = nullptr,
00072                   ValueMaterializer *Materializer = nullptr);
00073 
00074   Metadata *MapMetadata(const Metadata *MD, ValueToValueMapTy &VM,
00075                         RemapFlags Flags = RF_None,
00076                         ValueMapTypeRemapper *TypeMapper = nullptr,
00077                         ValueMaterializer *Materializer = nullptr);
00078 
00079   /// MapMetadata - provide versions that preserve type safety for MDNodes.
00080   MDNode *MapMetadata(const MDNode *MD, ValueToValueMapTy &VM,
00081                       RemapFlags Flags = RF_None,
00082                       ValueMapTypeRemapper *TypeMapper = nullptr,
00083                       ValueMaterializer *Materializer = nullptr);
00084 
00085   void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
00086                         RemapFlags Flags = RF_None,
00087                         ValueMapTypeRemapper *TypeMapper = nullptr,
00088                         ValueMaterializer *Materializer = nullptr);
00089 
00090   /// MapValue - provide versions that preserve type safety for Constants.
00091   inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM,
00092                             RemapFlags Flags = RF_None,
00093                             ValueMapTypeRemapper *TypeMapper = nullptr,
00094                             ValueMaterializer *Materializer = nullptr) {
00095     return cast<Constant>(MapValue((const Value*)V, VM, Flags, TypeMapper,
00096                                    Materializer));
00097   }
00098 
00099 } // End llvm namespace
00100 
00101 #endif