[Mlir-commits] [mlir] 86bc2e3 - [MLIR] Add a number of methods to the C API
Jacques Pienaar
llvmlistbot at llvm.org
Wed Jul 12 22:10:35 PDT 2023
Author: Adam Paszke
Date: 2023-07-12T22:10:03-07:00
New Revision: 86bc2e3ae905f0668f12c6f52191c1273936da80
URL: https://github.com/llvm/llvm-project/commit/86bc2e3ae905f0668f12c6f52191c1273936da80
DIFF: https://github.com/llvm/llvm-project/commit/86bc2e3ae905f0668f12c6f52191c1273936da80.diff
LOG: [MLIR] Add a number of methods to the C API
Those include:
- mlirFuncSetArgAttr
- mlirOperationSetOperands
- mlirRegionTakeBody
- mlirBlockInsertArgument
Reviewed By: ftynse, jpienaar
Differential Revision: https://reviews.llvm.org/D155091
Added:
Modified:
mlir/include/mlir-c/Dialect/Func.h
mlir/include/mlir-c/IR.h
mlir/lib/CAPI/Dialect/Func.cpp
mlir/lib/CAPI/IR/IR.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/Dialect/Func.h b/mlir/include/mlir-c/Dialect/Func.h
index eeb6dfe05acf79..1df759f0e8e3fe 100644
--- 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 <stdint.h>
+
#include "mlir-c/IR.h"
+#include "mlir-c/Support.h"
#ifdef __cplusplus
extern "C" {
@@ -26,6 +29,12 @@ extern "C" {
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
index 26f7f0738b8bf1..5312db09179451 100644
--- a/mlir/include/mlir-c/IR.h
+++ b/mlir/include/mlir-c/IR.h
@@ -533,6 +533,11 @@ MLIR_CAPI_EXPORTED MlirValue mlirOperationGetOperand(MlirOperation op,
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 @@ MLIR_CAPI_EXPORTED MlirRegion mlirOperationGetFirstRegion(MlirOperation op);
/// 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 @@ MLIR_CAPI_EXPORTED MlirValue mlirBlockAddArgument(MlirBlock block,
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
index a49d2f4258ee34..942e090fdfc19d 100644
--- 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<mlir::func::FuncOp>(unwrap(op))
+ .setArgAttr(pos, unwrap(name), unwrap(attr));
+}
diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index 8c3ea09e9fb1a9..dedae3ddd2c1d9 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -497,6 +497,12 @@ void mlirOperationSetOperand(MlirOperation op, intptr_t pos,
unwrap(op)->setOperand(static_cast<unsigned>(pos), unwrap(newValue));
}
+void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands,
+ MlirValue const *operands) {
+ SmallVector<Value> ops;
+ unwrap(op)->setOperands(unwrapList(nOperands, operands, ops));
+}
+
intptr_t mlirOperationGetNumResults(MlirOperation op) {
return static_cast<intptr_t>(unwrap(op)->getNumResults());
}
@@ -632,6 +638,10 @@ void mlirRegionDestroy(MlirRegion region) {
delete static_cast<Region *>(region.ptr);
}
+void mlirRegionTakeBody(MlirRegion target, MlirRegion source) {
+ unwrap(target)->takeBody(*unwrap(source));
+}
+
//===----------------------------------------------------------------------===//
// Block API.
//===----------------------------------------------------------------------===//
@@ -730,6 +740,11 @@ MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type,
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<unsigned>(pos)));
}
More information about the Mlir-commits
mailing list