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/ADT/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   /// RemapFlags - These are flags that the value mapping APIs allow.
00038   enum RemapFlags {
00039     RF_None = 0,
00040     
00041     /// RF_NoModuleLevelChanges - If this flag is set, the remapper knows that
00042     /// only local values within a function (such as an instruction or argument)
00043     /// are mapped, not global values like functions and global metadata.
00044     RF_NoModuleLevelChanges = 1,
00045     
00046     /// RF_IgnoreMissingEntries - If this flag is set, the remapper ignores
00047     /// entries that are not in the value map.  If it is unset, it aborts if an
00048     /// operand is asked to be remapped which doesn't exist in the mapping.
00049     RF_IgnoreMissingEntries = 2
00050   };
00051   
00052   static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {
00053     return RemapFlags(unsigned(LHS)|unsigned(RHS));
00054   }
00055   
00056   Value *MapValue(const Value *V, ValueToValueMapTy &VM,
00057                   RemapFlags Flags = RF_None,
00058                   ValueMapTypeRemapper *TypeMapper = 0);
00059 
00060   void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
00061                         RemapFlags Flags = RF_None,
00062                         ValueMapTypeRemapper *TypeMapper = 0);
00063   
00064   /// MapValue - provide versions that preserve type safety for MDNode and
00065   /// Constants.
00066   inline MDNode *MapValue(const MDNode *V, ValueToValueMapTy &VM,
00067                           RemapFlags Flags = RF_None,
00068                           ValueMapTypeRemapper *TypeMapper = 0) {
00069     return cast<MDNode>(MapValue((const Value*)V, VM, Flags, TypeMapper));
00070   }
00071   inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM,
00072                             RemapFlags Flags = RF_None,
00073                             ValueMapTypeRemapper *TypeMapper = 0) {
00074     return cast<Constant>(MapValue((const Value*)V, VM, Flags, TypeMapper));
00075   }
00076   
00077 
00078 } // End llvm namespace
00079 
00080 #endif