@@ -131,11 +131,6 @@ struct ConversionValueMapping {
131
131
// / value.
132
132
ValueVector lookupOrDefault (Value from, TypeRange desiredTypes = {}) const ;
133
133
134
- // / Lookup the given value within the map, or return an empty vector if the
135
- // / value is not mapped. If it is mapped, this follows the same behavior
136
- // / as `lookupOrDefault`.
137
- ValueVector lookupOrNull (Value from, TypeRange desiredTypes = {}) const ;
138
-
139
134
template <typename T>
140
135
struct IsValueVector : std::is_same<std::decay_t <T>, ValueVector> {};
141
136
@@ -238,15 +233,6 @@ ConversionValueMapping::lookupOrDefault(Value from,
238
233
return !desiredValue.empty () ? std::move (desiredValue) : std::move (current);
239
234
}
240
235
241
- ValueVector ConversionValueMapping::lookupOrNull (Value from,
242
- TypeRange desiredTypes) const {
243
- ValueVector result = lookupOrDefault (from, desiredTypes);
244
- if (result == ValueVector{from} ||
245
- (!desiredTypes.empty () && TypeRange (ValueRange (result)) != desiredTypes))
246
- return {};
247
- return result;
248
- }
249
-
250
236
// ===----------------------------------------------------------------------===//
251
237
// Rewriter and Translation State
252
238
// ===----------------------------------------------------------------------===//
@@ -927,6 +913,23 @@ struct ConversionPatternRewriterImpl : public RewriterBase::Listener {
927
913
// / Return "true" if the given operation was replaced or erased.
928
914
bool wasOpReplaced (Operation *op) const ;
929
915
916
+ // / Lookup the most recently mapped values with the desired types in the
917
+ // / mapping.
918
+ // /
919
+ // / Special cases:
920
+ // / - If the desired type range is empty, simply return the most recently
921
+ // / mapped values.
922
+ // / - If there is no mapping to the desired types, also return the most
923
+ // / recently mapped values.
924
+ // / - If there is no mapping for the given values at all, return the given
925
+ // / value.
926
+ ValueVector lookupOrDefault (Value from, TypeRange desiredTypes = {}) const ;
927
+
928
+ // / Lookup the given value within the map, or return an empty vector if the
929
+ // / value is not mapped. If it is mapped, this follows the same behavior
930
+ // / as `lookupOrDefault`.
931
+ ValueVector lookupOrNull (Value from, TypeRange desiredTypes = {}) const ;
932
+
930
933
// ===--------------------------------------------------------------------===//
931
934
// IR Rewrites / Type Conversion
932
935
// ===--------------------------------------------------------------------===//
@@ -1249,6 +1252,22 @@ void ConversionPatternRewriterImpl::applyRewrites() {
1249
1252
// State Management
1250
1253
// ===----------------------------------------------------------------------===//
1251
1254
1255
+ ValueVector
1256
+ ConversionPatternRewriterImpl::lookupOrDefault (Value from,
1257
+ TypeRange desiredTypes) const {
1258
+ return mapping.lookupOrDefault (from, desiredTypes);
1259
+ }
1260
+
1261
+ ValueVector
1262
+ ConversionPatternRewriterImpl::lookupOrNull (Value from,
1263
+ TypeRange desiredTypes) const {
1264
+ ValueVector result = lookupOrDefault (from, desiredTypes);
1265
+ if (result == ValueVector{from} ||
1266
+ (!desiredTypes.empty () && TypeRange (ValueRange (result)) != desiredTypes))
1267
+ return {};
1268
+ return result;
1269
+ }
1270
+
1252
1271
RewriterState ConversionPatternRewriterImpl::getCurrentState () {
1253
1272
return RewriterState (rewrites.size (), ignoredOps.size (), replacedOps.size ());
1254
1273
}
@@ -1296,7 +1315,7 @@ LogicalResult ConversionPatternRewriterImpl::remapValues(
1296
1315
// The current pattern does not have a type converter. I.e., it does not
1297
1316
// distinguish between legal and illegal types. For each operand, simply
1298
1317
// pass through the most recently mapped values.
1299
- remapped.push_back (mapping. lookupOrDefault (operand));
1318
+ remapped.push_back (lookupOrDefault (operand));
1300
1319
continue ;
1301
1320
}
1302
1321
@@ -1315,7 +1334,7 @@ LogicalResult ConversionPatternRewriterImpl::remapValues(
1315
1334
continue ;
1316
1335
}
1317
1336
1318
- ValueVector repl = mapping. lookupOrDefault (operand, legalTypes);
1337
+ ValueVector repl = lookupOrDefault (operand, legalTypes);
1319
1338
if (!repl.empty () && TypeRange (ValueRange (repl)) == legalTypes) {
1320
1339
// Mapped values have the correct type or there is an existing
1321
1340
// materialization. Or the operand is not mapped at all and has the
@@ -1325,7 +1344,7 @@ LogicalResult ConversionPatternRewriterImpl::remapValues(
1325
1344
}
1326
1345
1327
1346
// Create a materialization for the most recently mapped values.
1328
- repl = mapping. lookupOrDefault (operand);
1347
+ repl = lookupOrDefault (operand);
1329
1348
ValueRange castValues = buildUnresolvedMaterialization (
1330
1349
MaterializationKind::Target, computeInsertPoint (repl), operandLoc,
1331
1350
/* valuesToMap=*/ repl, /* inputs=*/ repl, /* outputTypes=*/ legalTypes,
@@ -1520,7 +1539,7 @@ Value ConversionPatternRewriterImpl::findOrBuildReplacementValue(
1520
1539
// Try to find a replacement value with the same type in the conversion value
1521
1540
// mapping. This includes cached materializations. We try to reuse those
1522
1541
// instead of generating duplicate IR.
1523
- ValueVector repl = mapping. lookupOrNull (value, value.getType ());
1542
+ ValueVector repl = lookupOrNull (value, value.getType ());
1524
1543
if (!repl.empty ())
1525
1544
return repl.front ();
1526
1545
@@ -1536,7 +1555,7 @@ Value ConversionPatternRewriterImpl::findOrBuildReplacementValue(
1536
1555
// No replacement value was found. Get the latest replacement value
1537
1556
// (regardless of the type) and build a source materialization to the
1538
1557
// original type.
1539
- repl = mapping. lookupOrNull (value);
1558
+ repl = lookupOrNull (value);
1540
1559
if (repl.empty ()) {
1541
1560
// No replacement value is registered in the mapping. This means that the
1542
1561
// value is dropped and no longer needed. (If the value were still needed,
0 commit comments