Add API for adding arguments to blocks

This just exposes a missing API

Differential Revision: https://reviews.llvm.org/D95968
This commit is contained in:
George 2021-02-03 12:34:29 -08:00
parent ea5b75de49
commit 9db6114296
3 changed files with 11 additions and 1 deletions

View File

@ -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);

View File

@ -525,6 +525,10 @@ intptr_t mlirBlockGetNumArguments(MlirBlock block) {
return static_cast<intptr_t>(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<unsigned>(pos)));
}

View File

@ -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 =