[flang-commits] [flang] [mlir] [mlir][Transforms] Dialect conversion: add `originalType` param to materializations (PR #112128)
Markus Böck via flang-commits
flang-commits at lists.llvm.org
Sun Oct 13 03:54:40 PDT 2024
================
@@ -170,21 +170,27 @@ class TypeConverter {
/// All of the following materializations require function objects that are
/// convertible to the following form:
- /// `std::optional<Value>(OpBuilder &, T, ValueRange, Location)`,
+ /// `std::optional<Value>(OpBuilder &, Location, T, ValueRange, Type)`,
/// where `T` is any subclass of `Type`. This function is responsible for
/// creating an operation, using the OpBuilder and Location provided, that
/// "casts" a range of values into a single value of the given type `T`. It
/// must return a Value of the type `T` on success, an `std::nullopt` if
/// it failed but other materialization can be attempted, and `nullptr` on
/// unrecoverable failure. Materialization functions must be provided when a
/// type conversion may persist after the conversion has finished.
+ ///
+ /// The type that is provided as the 5-th argument is the original type of
+ /// value. For more details, see the documentation below.
/// This method registers a materialization that will be called when
/// converting (potentially multiple) block arguments that were the result of
/// a signature conversion of a single block argument, to a single SSA value
/// with the old block argument type.
+ ///
+ /// Note: The original type matches the result type `T` for argument
+ /// materializations.
template <typename FnT, typename T = typename llvm::function_traits<
- std::decay_t<FnT>>::template arg_t<1>>
+ std::decay_t<FnT>>::template arg_t<2>>
void addArgumentMaterialization(FnT &&callback) {
----------------
zero9178 wrote:
Could we nevertheless allow to pass callables to this and source materializations that do not have the `Type` parameter as fifth argument?
I think this should greatly reduce churn downstream and also keep argument and source materializations cleaner conceptually.
I believe this should be achievable by either usign `if constexpr` or an extra overload of `wrapMaterialization` by checking whether its callable using the 5 parameter variant or the 4 parameter variant.
https://github.com/llvm/llvm-project/pull/112128
More information about the flang-commits
mailing list