LLVM  3.7.0
ValueMapper.h
Go to the documentation of this file.
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/IR/ValueMap.h"
19 
20 namespace llvm {
21  class Value;
22  class Instruction;
24 
25  /// ValueMapTypeRemapper - This is a class that can be implemented by clients
26  /// to remap types when cloning constants and instructions.
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  /// ValueMaterializer - This is a class that can be implemented by clients
38  /// to materialize Values on demand.
40  virtual void anchor(); // Out of line method.
41  public:
42  virtual ~ValueMaterializer() {}
43 
44  /// materializeValueFor - The client should implement this method if they
45  /// want to generate a mapped Value on demand. For example, if linking
46  /// lazily.
47  virtual Value *materializeValueFor(Value *V) = 0;
48  };
49 
50  /// RemapFlags - These are flags that the value mapping APIs allow.
51  enum RemapFlags {
52  RF_None = 0,
53 
54  /// RF_NoModuleLevelChanges - If this flag is set, the remapper knows that
55  /// only local values within a function (such as an instruction or argument)
56  /// are mapped, not global values like functions and global metadata.
58 
59  /// RF_IgnoreMissingEntries - If this flag is set, the remapper ignores
60  /// entries that are not in the value map. If it is unset, it aborts if an
61  /// operand is asked to be remapped which doesn't exist in the mapping.
63  };
64 
65  static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {
66  return RemapFlags(unsigned(LHS)|unsigned(RHS));
67  }
68 
69  Value *MapValue(const Value *V, ValueToValueMapTy &VM,
71  ValueMapTypeRemapper *TypeMapper = nullptr,
72  ValueMaterializer *Materializer = nullptr);
73 
74  Metadata *MapMetadata(const Metadata *MD, ValueToValueMapTy &VM,
76  ValueMapTypeRemapper *TypeMapper = nullptr,
77  ValueMaterializer *Materializer = nullptr);
78 
79  /// MapMetadata - provide versions that preserve type safety for MDNodes.
80  MDNode *MapMetadata(const MDNode *MD, ValueToValueMapTy &VM,
82  ValueMapTypeRemapper *TypeMapper = nullptr,
83  ValueMaterializer *Materializer = nullptr);
84 
85  void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
87  ValueMapTypeRemapper *TypeMapper = nullptr,
88  ValueMaterializer *Materializer = nullptr);
89 
90  /// MapValue - provide versions that preserve type safety for Constants.
93  ValueMapTypeRemapper *TypeMapper = nullptr,
94  ValueMaterializer *Materializer = nullptr) {
95  return cast<Constant>(MapValue((const Value*)V, VM, Flags, TypeMapper,
96  Materializer));
97  }
98 
99 } // End llvm namespace
100 
101 #endif
virtual ~ValueMaterializer()
Definition: ValueMapper.h:42
SmallBitVector operator|(const SmallBitVector &LHS, const SmallBitVector &RHS)
RF_NoModuleLevelChanges - If this flag is set, the remapper knows that only local values within a fun...
Definition: ValueMapper.h:57
RF_IgnoreMissingEntries - If this flag is set, the remapper ignores entries that are not in the value...
Definition: ValueMapper.h:62
ValueMaterializer - This is a class that can be implemented by clients to materialize Values on deman...
Definition: ValueMapper.h:39
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important base class in LLVM.
Definition: Constant.h:41
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Definition: ValueMapper.cpp:28
ValueMap< const Value *, WeakVH > ValueToValueMapTy
Definition: ValueMapper.h:22
virtual Value * materializeValueFor(Value *V)=0
materializeValueFor - The client should implement this method if they want to generate a mapped Value...
RemapFlags
RemapFlags - These are flags that the value mapping APIs allow.
Definition: ValueMapper.h:51
void RemapInstruction(Instruction *I, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
RemapInstruction - Convert the instruction operands from referencing the current values into those sp...
ValueMapTypeRemapper - This is a class that can be implemented by clients to remap types when cloning...
Definition: ValueMapper.h:27
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM Value Representation.
Definition: Value.h:69
virtual Type * remapType(Type *SrcTy)=0
remapType - The client should implement this method if they want to remap types while mapping values...