[Mlir-commits] [mlir] [mlir][CAPI] Add MlirOpFoldResult type to C API (PR #187247)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 19 03:13:47 PDT 2026
================
@@ -40,4 +41,15 @@ DEFINE_C_API_METHODS(MlirModule, mlir::ModuleOp)
DEFINE_C_API_METHODS(MlirType, mlir::Type)
DEFINE_C_API_METHODS(MlirValue, mlir::Value)
+static inline MlirOpFoldResult wrap(mlir::OpFoldResult ofr) {
+ return MlirOpFoldResult{ofr.getOpaqueValue()};
+}
+static inline mlir::OpFoldResult unwrap(MlirOpFoldResult result) {
+ using PU = llvm::PointerUnion<mlir::Attribute, mlir::Value>;
+ PU pu = PU::getFromOpaqueValue(const_cast<void *>(result.ptr));
+ if (llvm::isa<mlir::Attribute>(pu))
+ return llvm::cast<mlir::Attribute>(pu);
+ return llvm::cast<mlir::Value>(pu);
----------------
PragmaTwice wrote:
Hmm I think you don't need to touch `mlir/include/mlir/IR/OpDefinition.h`. You can just do a `static_cast`.
https://github.com/llvm/llvm-project/pull/187247
More information about the Mlir-commits
mailing list