Land the long talked about "type system rewrite" patch. This
[llvm/stm8.git] / include / llvm / Transforms / Utils / ValueMapper.h
blobc786342debb1ccd796a8252ee0c62e36e4bddcae
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.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
16 #define LLVM_TRANSFORMS_UTILS_VALUEMAPPER_H
18 #include "llvm/ADT/ValueMap.h"
20 namespace llvm {
21 class Value;
22 class Instruction;
23 typedef ValueMap<const Value *, TrackingVH<Value> > ValueToValueMapTy;
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 ~ValueMapTypeRemapper() {}
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;
37 /// RemapFlags - These are flags that the value mapping APIs allow.
38 enum RemapFlags {
39 RF_None = 0,
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,
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
52 static inline RemapFlags operator|(RemapFlags LHS, RemapFlags RHS) {
53 return RemapFlags(unsigned(LHS)|unsigned(RHS));
56 Value *MapValue(const Value *V, ValueToValueMapTy &VM,
57 RemapFlags Flags = RF_None,
58 ValueMapTypeRemapper *TypeMapper = 0);
60 void RemapInstruction(Instruction *I, ValueToValueMapTy &VM,
61 RemapFlags Flags = RF_None,
62 ValueMapTypeRemapper *TypeMapper = 0);
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 (MDNode*)MapValue((const Value*)V, VM, Flags, TypeMapper);
71 inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM,
72 RemapFlags Flags = RF_None,
73 ValueMapTypeRemapper *TypeMapper = 0) {
74 return (Constant*)MapValue((const Value*)V, VM, Flags, TypeMapper);
78 } // End llvm namespace
80 #endif