diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h index 2af813fbcdad7..8bee618213ff6 100644 --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -505,6 +505,11 @@ mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference, /// 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 index bf240046be250..fdb830e4940f0 100644 --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -525,6 +525,10 @@ intptr_t mlirBlockGetNumArguments(MlirBlock block) { 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 index d19ab47971cf0..c2b13d55473f4 100644 --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -128,7 +128,8 @@ MlirModule makeAndDumpAdd(MlirContext ctx, MlirLocation location) { 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 =