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 @@ -505,6 +505,11 @@ /// Returns the number of arguments of the block. MLIR_CAPI_EXPORTED intptr_t mlirBlockGetNumArguments(MlirBlock block); +/// Appends an argument of the specified type to the block. Returns the newly +/// added argument. +MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block, + MlirType type); + /// Returns `pos`-th argument of the block. MLIR_CAPI_EXPORTED MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos); 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 @@ -525,6 +525,10 @@ return static_cast(unwrap(block)->getNumArguments()); } +MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type) { + return wrap(unwrap(block)->addArgument(unwrap(type))); +} + MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos) { return wrap(unwrap(block)->getArgument(static_cast(pos))); } diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -128,7 +128,8 @@ mlirBlockAppendOwnedOperation(funcBody, dim); MlirRegion loopBodyRegion = mlirRegionCreate(); - MlirBlock loopBody = mlirBlockCreate(/*nArgs=*/1, &indexType); + MlirBlock loopBody = mlirBlockCreate(0, NULL); + mlirBlockAddArgument(loopBody, indexType); mlirRegionAppendOwnedBlock(loopBodyRegion, loopBody); MlirAttribute indexOneLiteral =