From fc8484f0e383cc5cf31d67ad3e762705955ea1ea Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Thu, 8 May 2025 08:22:38 +0200 Subject: [PATCH] [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. --- mlir/docs/DialectConversion.md | 4 ++-- .../mlir/Transforms/DialectConversion.h | 21 +++++++++---------- .../Transforms/Utils/DialectConversion.cpp | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mlir/docs/DialectConversion.md b/mlir/docs/DialectConversion.md index f67d1411b306..cf577eca5b9a 100644 --- a/mlir/docs/DialectConversion.md +++ b/mlir/docs/DialectConversion.md @@ -338,7 +338,7 @@ class TypeConverter { typename T = typename llvm::function_traits::template arg_t<1>> void addSourceMaterialization(FnT &&callback) { sourceMaterializations.emplace_back( - wrapMaterialization(std::forward(callback))); + wrapSourceMaterialization(std::forward(callback))); } /// This method registers a materialization that will be called when @@ -362,7 +362,7 @@ class TypeConverter { typename T = typename llvm::function_traits::template arg_t<1>> void addTargetMaterialization(FnT &&callback) { targetMaterializations.emplace_back( - wrapMaterialization(std::forward(callback))); + wrapTargetMaterialization(std::forward(callback))); } }; ``` diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h index b65b3ea971f9..e7d05c3ce1ad 100644 --- a/mlir/include/mlir/Transforms/DialectConversion.h +++ b/mlir/include/mlir/Transforms/DialectConversion.h @@ -186,7 +186,7 @@ public: std::decay_t>::template arg_t<1>> void addSourceMaterialization(FnT &&callback) { sourceMaterializations.emplace_back( - wrapMaterialization(std::forward(callback))); + wrapSourceMaterialization(std::forward(callback))); } /// This method registers a materialization that will be called when @@ -330,11 +330,10 @@ private: using ConversionCallbackFn = std::function( Type, SmallVectorImpl &)>; - /// The signature of the callback used to materialize a source/argument - /// conversion. + /// The signature of the callback used to materialize a source conversion. /// /// Arguments: builder, result type, inputs, location - using MaterializationCallbackFn = + using SourceMaterializationCallbackFn = std::function; /// The signature of the callback used to materialize a target conversion. @@ -387,12 +386,12 @@ private: cachedMultiConversions.clear(); } - /// Generate a wrapper for the given argument/source materialization - /// callback. The callback may take any subclass of `Type` and the - /// wrapper will check for the target type to be of the expected class - /// before calling the callback. + /// Generate a wrapper for the given source materialization callback. The + /// callback may take any subclass of `Type` and the wrapper will check for + /// the target type to be of the expected class before calling the callback. template - MaterializationCallbackFn wrapMaterialization(FnT &&callback) const { + SourceMaterializationCallbackFn + wrapSourceMaterialization(FnT &&callback) const { return [callback = std::forward(callback)]( OpBuilder &builder, Type resultType, ValueRange inputs, Location loc) -> Value { @@ -491,7 +490,7 @@ private: SmallVector conversions; /// The list of registered materialization functions. - SmallVector sourceMaterializations; + SmallVector sourceMaterializations; SmallVector targetMaterializations; /// The list of registered type attribute conversion functions. @@ -740,7 +739,7 @@ public: /// /// Optionally, a type converter can be provided to build materializations. /// Note: If no type converter was provided or the type converter does not - /// specify any suitable argument/target materialization rules, the dialect + /// specify any suitable source/target materialization rules, the dialect /// conversion may fail to legalize unresolved materializations. Block * applySignatureConversion(Block *block, diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp index d50c26a0fd92..0d208ce0f2f2 100644 --- a/mlir/lib/Transforms/Utils/DialectConversion.cpp +++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp @@ -2959,7 +2959,7 @@ TypeConverter::convertSignatureArgs(TypeRange types, Value TypeConverter::materializeSourceConversion(OpBuilder &builder, Location loc, Type resultType, ValueRange inputs) const { - for (const MaterializationCallbackFn &fn : + for (const SourceMaterializationCallbackFn &fn : llvm::reverse(sourceMaterializations)) if (Value result = fn(builder, resultType, inputs, loc)) return result;