diff --git a/mlir/include/mlir-c/Dialect/Func.h b/mlir/include/mlir-c/Dialect/Func.h --- a/mlir/include/mlir-c/Dialect/Func.h +++ b/mlir/include/mlir-c/Dialect/Func.h @@ -18,7 +18,10 @@ #ifndef MLIR_C_DIALECT_FUNC_H #define MLIR_C_DIALECT_FUNC_H +#include + #include "mlir-c/IR.h" +#include "mlir-c/Support.h" #ifdef __cplusplus extern "C" { @@ -26,6 +29,12 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Func, func); +/// Sets the argument attribute 'name' of an argument at index 'pos'. +/// Asserts that the operation is a FuncOp. +MLIR_CAPI_EXPORTED void mlirFuncSetArgAttr(MlirOperation op, intptr_t pos, + MlirStringRef name, + MlirAttribute attr); + #ifdef __cplusplus } #endif diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -533,6 +533,11 @@ MLIR_CAPI_EXPORTED void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue); +/// Replaces the operands of the operation. +MLIR_CAPI_EXPORTED void mlirOperationSetOperands(MlirOperation op, + intptr_t nOperands, + MlirValue const *operands); + /// Returns the number of results of the operation. MLIR_CAPI_EXPORTED intptr_t mlirOperationGetNumResults(MlirOperation op); @@ -664,6 +669,10 @@ /// operation. MLIR_CAPI_EXPORTED MlirRegion mlirRegionGetNextInOperation(MlirRegion region); +/// Moves the entire content of the source region to the target region. +MLIR_CAPI_EXPORTED void mlirRegionTakeBody(MlirRegion target, + MlirRegion source); + //===----------------------------------------------------------------------===// // Block API. //===----------------------------------------------------------------------===// @@ -737,6 +746,13 @@ MlirType type, MlirLocation loc); +/// Inserts an argument of the specified type at a specified index to the block. +/// Returns the newly added argument. +MLIR_CAPI_EXPORTED MlirValue mlirBlockInsertArgument(MlirBlock block, + intptr_t pos, + MlirType type, + MlirLocation loc); + /// Returns `pos`-th argument of the block. MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos); diff --git a/mlir/lib/CAPI/Dialect/Func.cpp b/mlir/lib/CAPI/Dialect/Func.cpp --- a/mlir/lib/CAPI/Dialect/Func.cpp +++ b/mlir/lib/CAPI/Dialect/Func.cpp @@ -7,7 +7,15 @@ //===----------------------------------------------------------------------===// #include "mlir-c/Dialect/Func.h" +#include "mlir-c/IR.h" +#include "mlir-c/Support.h" #include "mlir/CAPI/Registration.h" #include "mlir/Dialect/Func/IR/FuncOps.h" MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Func, func, mlir::func::FuncDialect) + +void mlirFuncSetArgAttr(MlirOperation op, intptr_t pos, MlirStringRef name, + MlirAttribute attr) { + llvm::cast(unwrap(op)) + .setArgAttr(pos, unwrap(name), unwrap(attr)); +} diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -497,6 +497,12 @@ unwrap(op)->setOperand(static_cast(pos), unwrap(newValue)); } +void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, + MlirValue const *operands) { + SmallVector ops; + unwrap(op)->setOperands(unwrapList(nOperands, operands, ops)); +} + intptr_t mlirOperationGetNumResults(MlirOperation op) { return static_cast(unwrap(op)->getNumResults()); } @@ -632,6 +638,10 @@ delete static_cast(region.ptr); } +void mlirRegionTakeBody(MlirRegion target, MlirRegion source) { + unwrap(target)->takeBody(*unwrap(source)); +} + //===----------------------------------------------------------------------===// // Block API. //===----------------------------------------------------------------------===// @@ -730,6 +740,11 @@ return wrap(unwrap(block)->addArgument(unwrap(type), unwrap(loc))); } +MlirValue mlirBlockInsertArgument(MlirBlock block, intptr_t pos, MlirType type, + MlirLocation loc) { + return wrap(unwrap(block)->insertArgument(pos, unwrap(type), unwrap(loc))); +} + MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos) { return wrap(unwrap(block)->getArgument(static_cast(pos))); }