[llvm-branch-commits] [mlir] [mlir-c] Add 1:N TypeConverter conversion and materialization bindings (PR #208935)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 17 21:21:45 PDT 2026
================
@@ -664,50 +680,139 @@ void mlirTypeConverterAddConversion(
});
}
+void mlirTypeConverterConversionResultsAppend(
+ MlirTypeConverterConversionResults results, MlirType type) {
+ static_cast<SmallVectorImpl<Type> *>(results.ptr)->push_back(unwrap(type));
+}
+
+void mlirTypeConverterAdd1ToNConversion(
+ MlirTypeConverter typeConverter,
+ MlirTypeConverter1ToNConversionCallback convertType, void *userData) {
+ unwrap(typeConverter)
+ ->addConversion(
+ [convertType, userData](Type type, SmallVectorImpl<Type> &results)
+ -> std::optional<LogicalResult> {
+ size_t numPriorResults = results.size();
+ MlirTypeConverterConversionResults wrappedResults{&results};
+ MlirLogicalResult result =
+ convertType(wrap(type), wrappedResults, userData);
+ if (mlirLogicalResultIsFailure(result)) {
+ // The callback declined. Restore any types it appended so the
+ // driver's "try the next conversion" invariant holds (a declining
+ // conversion function must not mutate `results`).
+ results.truncate(numPriorResults);
+ return std::nullopt;
+ }
+ return success();
----------------
PragmaTwice wrote:
It seems that in the C++ API there's three states: `success`, `failure` (don't try another) and `nullopt` (try another) but here users cannot specify a `failure` state?
https://github.com/llvm/llvm-project/pull/208935
More information about the llvm-branch-commits
mailing list