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   void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
00075                         RemapFlags Flags = RF_None,
00076                         ValueMapTypeRemapper *TypeMapper = nullptr,
00077                         ValueMaterializer *Materializer = nullptr);
00078   
00079   /// MapValue - provide versions that preserve type safety for MDNode and
00080   /// Constants.
00081   inline MDNode *MapValue(const MDNode *V, ValueToValueMapTy &VM,
00082                           RemapFlags Flags = RF_None,
00083                           ValueMapTypeRemapper *TypeMapper = nullptr,
00084                           ValueMaterializer *Materializer = nullptr) {
00085     return cast<MDNode>(MapValue((const Value*)V, VM, Flags, TypeMapper,
00086                                  Materializer));
00087   }
00088   inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM,
00089                             RemapFlags Flags = RF_None,
00090                             ValueMapTypeRemapper *TypeMapper = nullptr,
00091                             ValueMaterializer *Materializer = nullptr) {
00092     return cast<Constant>(MapValue((const Value*)V, VM, Flags, TypeMapper,
00093                                    Materializer));
00094   }
00095   
00096 
00097 } // End llvm namespace
00098 
00099 #endif