[Mlir-commits] [mlir] 9db6114 - Add API for adding arguments to blocks
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Feb 3 13:15:40 PST 2021
Author: George
Date: 2021-02-03T13:14:48-08:00
New Revision: 9db61142965e6f4b382e7ff7bde8af5d8396fe98
URL: https://github.com/llvm/llvm-project/commit/9db61142965e6f4b382e7ff7bde8af5d8396fe98
DIFF: https://github.com/llvm/llvm-project/commit/9db61142965e6f4b382e7ff7bde8af5d8396fe98.diff
LOG: Add API for adding arguments to blocks
This just exposes a missing API
Differential Revision: https://reviews.llvm.org/D95968
Added:
Modified:
mlir/include/mlir-c/IR.h
mlir/lib/CAPI/IR/IR.cpp
mlir/test/CAPI/ir.c
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h
index 2af813fbcdad..8bee618213ff 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 bf240046be25..fdb830e4940f 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<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)));
}
diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index d19ab47971cf..c2b13d55473f 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 =
More information about the Mlir-commits
mailing list