[Mlir-commits] [mlir] [mlir][CAPI] Add MlirOpFoldResult type to C API (PR #187247)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 20 06:45:26 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:
Ahh sorry, I tried on my local, and the cast should be like:
```
static_cast<OpFoldResult&&>(OpFoldResult::getFromOpaqueValue(..))
```
> There is no copy constructor from the base type
Hmm that's not correct. Both `OpFoldResult` and `PointerUnion` have copy constructors.
https://github.com/llvm/llvm-project/pull/187247
More information about the Mlir-commits
mailing list