Home | History | Annotate | Download | only in Utils
      1 //===- ValueMapper.h - Remapping for constants and metadata -----*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines the MapValue interface which is used by various parts of
     11 // the Transforms/Utils library to implement cloning and linking facilities.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
     16 #define LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
     17 
     18 #include "llvm/ADT/ValueMap.h"
     19 
     20 namespace llvm {
     21   class Value;
     22   class Instruction;
     23   typedef ValueMap<const Value *, TrackingVH<Value> > ValueToValueMapTy;
     24 
     25   /// ValueMapTypeRemapper - This is a class that can be implemented by clients
     26   /// to remap types when cloning constants and instructions.
     27   class ValueMapTypeRemapper {
     28     virtual void Anchor();  // Out of line method.
     29   public:
     30     virtual ~ValueMapTypeRemapper() {}
     31 
     32     /// remapType - The client should implement this method if they want to
     33     /// remap types while mapping values.
     34     virtual Type *remapType(Type *SrcTy) = 0;
     35   };
     36 
     37   /// RemapFlags - These are flags that the value mapping APIs allow.
     38   enum RemapFlags {
     39     RF_None = 0,
     40 
     41     /// RF_NoModuleLevelChanges - If this flag is set, the remapper knows that
     42     /// only local values within a function (such as an instruction or argument)
     43     /// are mapped, not global values like functions and global metadata.
     44     RF_NoModuleLevelChanges = 1,
     45 
     46     /// RF_IgnoreMissingEntries - If this flag is set, the remapper ignores
     47     /// entries that are not in the value map.  If it is unset, it aborts if an
     48     /// operand is asked to be remapped which doesn't exist in the mapping.
     49     RF_IgnoreMissingEntries = 2
     50   };
     51 
     52   static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {
     53     return RemapFlags(unsigned(LHS)|unsigned(RHS));
     54   }
     55 
     56   Value *MapValue(const Value *V, ValueToValueMapTy &VM,
     57                   RemapFlags Flags = RF_None,
     58                   ValueMapTypeRemapper *TypeMapper = 0);
     59 
     60   void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
     61                         RemapFlags Flags = RF_None,
     62                         ValueMapTypeRemapper *TypeMapper = 0);
     63 
     64   /// MapValue - provide versions that preserve type safety for MDNode and
     65   /// Constants.
     66   inline MDNode *MapValue(const MDNode *V, ValueToValueMapTy &VM,
     67                           RemapFlags Flags = RF_None,
     68                           ValueMapTypeRemapper *TypeMapper = 0) {
     69     return cast<MDNode>(MapValue((const Value*)V, VM, Flags, TypeMapper));
     70   }
     71   inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM,
     72                             RemapFlags Flags = RF_None,
     73                             ValueMapTypeRemapper *TypeMapper = 0) {
     74     return cast<Constant>(MapValue((const Value*)V, VM, Flags, TypeMapper));
     75   }
     76 
     77 
     78 } // End llvm namespace
     79 
     80 #endif
     81