MLIR: include/mlir/IR/IRMapping.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #ifndef MLIR_IR_IRMAPPING_H
15 #define MLIR_IR_IRMAPPING_H
16
18
19 namespace mlir {
20
21
22
23
24
25
27 public:
28
29
33
34 template <typename S, typename T,
35 std::enable_if_t<!std::is_assignable_v<Value, S> &&
36 !std::is_assignable_v<Block *, S> &&
37 !std::is_assignable_v<Operation *, S>> * = nullptr>
38 void map(S &&from, T &&to) {
39 for (auto [fromValue, toValue] : llvm::zip(from, to))
40 map(fromValue, toValue);
41 }
42
43
44 template
46 getMap().erase(from);
47 }
48
49
50 template
52 return getMap().count(from);
53 }
54
55
56
57 template
59 return lookupOrValue(from, T(nullptr));
60 }
61
62
63
64 template
66 return lookupOrValue(from, from);
67 }
68
69
70
71 template
74 assert(result && "expected 'from' to be contained within the map");
75 return result;
76 }
77
78
79 void clear() { valueMap.clear(); }
80
81
83
84
86
87
89 return operationMap;
90 }
91
92 private:
93
94 template
95 auto &getMap() const {
96 if constexpr (std::is_convertible_v<T, Value>)
98 else if constexpr (std::is_convertible_v<T, Block *>)
100 else
102 }
103
104
105
106 template
107 auto lookupOrValue(T from, T value) const {
108 auto &map = getMap();
109 auto it = map.find(from);
110 return it != map.end() ? it->second : value;
111 }
112
113 DenseMap<Value, Value> valueMap;
114 DenseMap<Block *, Block *> blockMap;
115 DenseMap<Operation *, Operation *> operationMap;
116 };
117
118 }
119
120 #endif
Block represents an ordered list of Operations.
This is a utility class for mapping one set of IR entities to another.
void erase(T from)
Erases a mapping for 'from'.
void map(Block *from, Block *to)
auto lookupOrDefault(T from) const
Lookup a mapped value within the map.
const DenseMap< Operation *, Operation * > & getOperationMap() const
Return the held operation mapping.
auto lookup(T from) const
Lookup a mapped value within the map.
const DenseMap< Block *, Block * > & getBlockMap() const
Return the held block mapping.
const DenseMap< Value, Value > & getValueMap() const
Return the held value mapping.
void map(Operation *from, Operation *to)
void map(S &&from, T &&to)
void clear()
Clears all mappings held by the mapper.
void map(Value from, Value to)
Inserts a new mapping for 'from' to 'to'.
bool contains(T from) const
Checks to see if a mapping for 'from' exists.
auto lookupOrNull(T from) const
Lookup a mapped value within the map.
Operation is the basic unit of execution within MLIR.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Include the generated interface declarations.