Skip to content

Commit fc8484f

Browse files
[mlir][Transforms][NFC] Rename MaterializationCallbackFn (#138814)
There are two kind of materialization callbacks: one for target materializations and one for source materializations. The callback type for target materializations is `TargetMaterializationCallbackFn`. This commit renames the one for source materializations from `MaterializationCallbackFn` to `SourceMaterializationCallbackFn`, for consistency. There used to be a single callback type for both kind of materializations, but the materialization function signatures have changed over time. Also clean up a few places in the documentation that still referred to argument materializations.
1 parent df4eac2 commit fc8484f

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

mlir/docs/DialectConversion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class TypeConverter {
338338
typename T = typename llvm::function_traits<FnT>::template arg_t<1>>
339339
void addSourceMaterialization(FnT &&callback) {
340340
sourceMaterializations.emplace_back(
341-
wrapMaterialization<T>(std::forward<FnT>(callback)));
341+
wrapSourceMaterialization<T>(std::forward<FnT>(callback)));
342342
}
343343
344344
/// This method registers a materialization that will be called when
@@ -362,7 +362,7 @@ class TypeConverter {
362362
typename T = typename llvm::function_traits<FnT>::template arg_t<1>>
363363
void addTargetMaterialization(FnT &&callback) {
364364
targetMaterializations.emplace_back(
365-
wrapMaterialization<T>(std::forward<FnT>(callback)));
365+
wrapTargetMaterialization<T>(std::forward<FnT>(callback)));
366366
}
367367
};
368368
```

mlir/include/mlir/Transforms/DialectConversion.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class TypeConverter {
186186
std::decay_t<FnT>>::template arg_t<1>>
187187
void addSourceMaterialization(FnT &&callback) {
188188
sourceMaterializations.emplace_back(
189-
wrapMaterialization<T>(std::forward<FnT>(callback)));
189+
wrapSourceMaterialization<T>(std::forward<FnT>(callback)));
190190
}
191191

192192
/// This method registers a materialization that will be called when
@@ -330,11 +330,10 @@ class TypeConverter {
330330
using ConversionCallbackFn = std::function<std::optional<LogicalResult>(
331331
Type, SmallVectorImpl<Type> &)>;
332332

333-
/// The signature of the callback used to materialize a source/argument
334-
/// conversion.
333+
/// The signature of the callback used to materialize a source conversion.
335334
///
336335
/// Arguments: builder, result type, inputs, location
337-
using MaterializationCallbackFn =
336+
using SourceMaterializationCallbackFn =
338337
std::function<Value(OpBuilder &, Type, ValueRange, Location)>;
339338

340339
/// The signature of the callback used to materialize a target conversion.
@@ -387,12 +386,12 @@ class TypeConverter {
387386
cachedMultiConversions.clear();
388387
}
389388

390-
/// Generate a wrapper for the given argument/source materialization
391-
/// callback. The callback may take any subclass of `Type` and the
392-
/// wrapper will check for the target type to be of the expected class
393-
/// before calling the callback.
389+
/// Generate a wrapper for the given source materialization callback. The
390+
/// callback may take any subclass of `Type` and the wrapper will check for
391+
/// the target type to be of the expected class before calling the callback.
394392
template <typename T, typename FnT>
395-
MaterializationCallbackFn wrapMaterialization(FnT &&callback) const {
393+
SourceMaterializationCallbackFn
394+
wrapSourceMaterialization(FnT &&callback) const {
396395
return [callback = std::forward<FnT>(callback)](
397396
OpBuilder &builder, Type resultType, ValueRange inputs,
398397
Location loc) -> Value {
@@ -491,7 +490,7 @@ class TypeConverter {
491490
SmallVector<ConversionCallbackFn, 4> conversions;
492491

493492
/// The list of registered materialization functions.
494-
SmallVector<MaterializationCallbackFn, 2> sourceMaterializations;
493+
SmallVector<SourceMaterializationCallbackFn, 2> sourceMaterializations;
495494
SmallVector<TargetMaterializationCallbackFn, 2> targetMaterializations;
496495

497496
/// The list of registered type attribute conversion functions.
@@ -740,7 +739,7 @@ class ConversionPatternRewriter final : public PatternRewriter {
740739
///
741740
/// Optionally, a type converter can be provided to build materializations.
742741
/// Note: If no type converter was provided or the type converter does not
743-
/// specify any suitable argument/target materialization rules, the dialect
742+
/// specify any suitable source/target materialization rules, the dialect
744743
/// conversion may fail to legalize unresolved materializations.
745744
Block *
746745
applySignatureConversion(Block *block,

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2959,7 +2959,7 @@ TypeConverter::convertSignatureArgs(TypeRange types,
29592959
Value TypeConverter::materializeSourceConversion(OpBuilder &builder,
29602960
Location loc, Type resultType,
29612961
ValueRange inputs) const {
2962-
for (const MaterializationCallbackFn &fn :
2962+
for (const SourceMaterializationCallbackFn &fn :
29632963
llvm::reverse(sourceMaterializations))
29642964
if (Value result = fn(builder, resultType, inputs, loc))
29652965
return result;

0 commit comments

Comments
 (0)