[Mlir-commits] [mlir] [mlir][emitc] Expose emitc dialect types (PR #119645)
Eliud de León
llvmlistbot at llvm.org
Sat Dec 28 22:00:44 PST 2024
https://github.com/TGMM updated https://github.com/llvm/llvm-project/pull/119645
>From 1e75aa3dd955478f5223f052c93260976ac0b1e4 Mon Sep 17 00:00:00 2001
From: TGMM <tgmm.1000 at gmail.com>
Date: Wed, 11 Dec 2024 17:36:30 -0800
Subject: [PATCH 1/4] [mlir][emitc] Expose emitc dialect types
---
mlir/include/mlir-c/Dialect/EmitC.h | 62 +++++++++++++++++
mlir/lib/CAPI/Dialect/EmitC.cpp | 100 ++++++++++++++++++++++++++++
2 files changed, 162 insertions(+)
diff --git a/mlir/include/mlir-c/Dialect/EmitC.h b/mlir/include/mlir-c/Dialect/EmitC.h
index 82e698344bf1e7..384e695e429ef0 100644
--- a/mlir/include/mlir-c/Dialect/EmitC.h
+++ b/mlir/include/mlir-c/Dialect/EmitC.h
@@ -19,6 +19,68 @@ extern "C" {
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(EmitC, emitc);
+//===---------------------------------------------------------------------===//
+// ArrayType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCArrayType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCArrayTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCArrayTypeGet(intptr_t nDims,
+ int64_t *shape,
+ MlirType elementType);
+//===---------------------------------------------------------------------===//
+// OpaqueType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCOpaqueType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCOpaqueTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCOpaqueTypeGet(MlirContext ctx,
+ MlirStringRef value);
+
+//===---------------------------------------------------------------------===//
+// PointerType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCPointerType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCPointerTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCPointerTypeGet(MlirType pointee);
+
+//===---------------------------------------------------------------------===//
+// PtrDiffTType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCPtrDiffTType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCPtrDiffTTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCPtrDiffTTypeGet(MlirContext ctx);
+
+//===---------------------------------------------------------------------===//
+// SignedSizeTType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCSignedSizeTType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCSignedSizeTTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCSignedSizeTTypeGet(MlirContext ctx);
+
+//===---------------------------------------------------------------------===//
+// SizeTType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCSizeTType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCSizeTTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCSizeTTypeGet(MlirContext ctx);
+
#ifdef __cplusplus
}
#endif
diff --git a/mlir/lib/CAPI/Dialect/EmitC.cpp b/mlir/lib/CAPI/Dialect/EmitC.cpp
index 3dcb7038a57981..57619ff776843d 100644
--- a/mlir/lib/CAPI/Dialect/EmitC.cpp
+++ b/mlir/lib/CAPI/Dialect/EmitC.cpp
@@ -10,4 +10,104 @@
#include "mlir/CAPI/Registration.h"
#include "mlir/Dialect/EmitC/IR/EmitC.h"
+using namespace mlir;
+
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(EmitC, emitc, mlir::emitc::EmitCDialect)
+
+//===---------------------------------------------------------------------===//
+// ArrayType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCArrayType(MlirType type) {
+ return isa<emitc::ArrayType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCArrayTypeGetTypeID(void) {
+ return wrap(emitc::ArrayType::getTypeID());
+}
+
+MlirType mlirEmitCArrayTypeGet(intptr_t nDims, int64_t *shape,
+ MlirType elementType) {
+ return wrap(
+ emitc::ArrayType::get(llvm::ArrayRef(shape, nDims), unwrap(elementType)));
+}
+
+//===---------------------------------------------------------------------===//
+// OpaqueType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCOpaqueType(MlirType type) {
+ return isa<emitc::OpaqueType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCOpaqueTypeGetTypeID(void) {
+ return wrap(emitc::OpaqueType::getTypeID());
+}
+
+MlirType mlirEmitCOpaqueTypeGet(MlirContext ctx, MlirStringRef value) {
+ return wrap(emitc::OpaqueType::get(unwrap(ctx), unwrap(value)));
+}
+
+//===---------------------------------------------------------------------===//
+// PointerType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCPointerType(MlirType type) {
+ return isa<emitc::PointerType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCPointerTypeGetTypeID(void) {
+ return wrap(emitc::PointerType::getTypeID());
+}
+
+MlirType mlirEmitCPointerTypeGet(MlirType pointee) {
+ return wrap(emitc::PointerType::get(unwrap(pointee)));
+}
+
+//===---------------------------------------------------------------------===//
+// PtrDiffTType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCPtrDiffTType(MlirType type) {
+ return isa<emitc::PtrDiffTType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCPtrDiffTTypeGetTypeID(void) {
+ return wrap(emitc::PtrDiffTType::getTypeID());
+}
+
+MlirType mlirEmitCPtrDiffTTypeGet(MlirContext ctx) {
+ return wrap(emitc::PtrDiffTType::get(unwrap(ctx)));
+}
+
+//===---------------------------------------------------------------------===//
+// SignedSizeTType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCSignedSizeTType(MlirType type) {
+ return isa<emitc::SignedSizeTType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCSignedSizeTTypeGetTypeID(void) {
+ return wrap(emitc::SignedSizeTType::getTypeID());
+}
+
+MlirType mlirEmitCSignedSizeTTypeGet(MlirContext ctx) {
+ return wrap(emitc::SignedSizeTType::get(unwrap(ctx)));
+}
+
+//===---------------------------------------------------------------------===//
+// SizeTType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCSizeTType(MlirType type) {
+ return isa<emitc::SizeTType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCSizeTTypeGetTypeID(void) {
+ return wrap(emitc::SizeTType::getTypeID());
+}
+
+MlirType mlirEmitCSizeTTypeGet(MlirContext ctx) {
+ return wrap(emitc::SizeTType::get(unwrap(ctx)));
+}
>From f36ca23d933f469daf261498f159704a8c573710 Mon Sep 17 00:00:00 2001
From: TGMM <tgmm.1000 at gmail.com>
Date: Wed, 11 Dec 2024 23:09:18 -0800
Subject: [PATCH 2/4] Added LValue type to CAPI
---
mlir/include/mlir-c/Dialect/EmitC.h | 11 +++++++++++
mlir/lib/CAPI/Dialect/EmitC.cpp | 16 ++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/mlir/include/mlir-c/Dialect/EmitC.h b/mlir/include/mlir-c/Dialect/EmitC.h
index 384e695e429ef0..23e30f9d67fe94 100644
--- a/mlir/include/mlir-c/Dialect/EmitC.h
+++ b/mlir/include/mlir-c/Dialect/EmitC.h
@@ -30,6 +30,17 @@ MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCArrayTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType mlirEmitCArrayTypeGet(intptr_t nDims,
int64_t *shape,
MlirType elementType);
+
+//===---------------------------------------------------------------------===//
+// LValueType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAEmitCLValueType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCLValueTypeGetTypeID(void);
+
+MLIR_CAPI_EXPORTED MlirType mlirEmitCLValueTypeGet(MlirType valueType);
+
//===---------------------------------------------------------------------===//
// OpaqueType
//===---------------------------------------------------------------------===//
diff --git a/mlir/lib/CAPI/Dialect/EmitC.cpp b/mlir/lib/CAPI/Dialect/EmitC.cpp
index 57619ff776843d..0672c2278790a2 100644
--- a/mlir/lib/CAPI/Dialect/EmitC.cpp
+++ b/mlir/lib/CAPI/Dialect/EmitC.cpp
@@ -32,6 +32,22 @@ MlirType mlirEmitCArrayTypeGet(intptr_t nDims, int64_t *shape,
emitc::ArrayType::get(llvm::ArrayRef(shape, nDims), unwrap(elementType)));
}
+//===---------------------------------------------------------------------===//
+// LValueType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAEmitCLValueType(MlirType type) {
+ return isa<emitc::LValueType>(unwrap(type));
+}
+
+MlirTypeID mlirEmitCLValueTypeGetTypeID(void) {
+ return wrap(emitc::LValueType::getTypeID());
+}
+
+MlirType mlirEmitCLValueTypeGet(MlirType valueType) {
+ return wrap(emitc::LValueType::get(unwrap(valueType)));
+}
+
//===---------------------------------------------------------------------===//
// OpaqueType
//===---------------------------------------------------------------------===//
>From dbaf3d9240cd507f97251cba7458734ae96bbf9d Mon Sep 17 00:00:00 2001
From: TGMM <tgmm.1000 at gmail.com>
Date: Thu, 12 Dec 2024 00:48:29 -0800
Subject: [PATCH 3/4] Added EmitC attrs to CAPI
---
mlir/include/mlir-c/Dialect/EmitC.h | 28 +++++++++++++++++++
mlir/lib/CAPI/Dialect/EmitC.cpp | 42 +++++++++++++++++++++++++++++
2 files changed, 70 insertions(+)
diff --git a/mlir/include/mlir-c/Dialect/EmitC.h b/mlir/include/mlir-c/Dialect/EmitC.h
index 23e30f9d67fe94..9a7e4c2f462f1c 100644
--- a/mlir/include/mlir-c/Dialect/EmitC.h
+++ b/mlir/include/mlir-c/Dialect/EmitC.h
@@ -92,6 +92,34 @@ MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCSizeTTypeGetTypeID(void);
MLIR_CAPI_EXPORTED MlirType mlirEmitCSizeTTypeGet(MlirContext ctx);
+//===----------------------------------------------------------------------===//
+// CmpPredicate attribute.
+//===----------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirAttributeIsAEmitCCmpPredicate(MlirAttribute attr);
+
+MLIR_CAPI_EXPORTED MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx,
+ uint64_t val);
+
+MLIR_CAPI_EXPORTED uint64_t
+mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCCmpPredicateAttrGetTypeID(void);
+
+//===----------------------------------------------------------------------===//
+// Opaque attribute.
+//===----------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirAttributeIsAEmitCOpaque(MlirAttribute attr);
+
+MLIR_CAPI_EXPORTED MlirAttribute mlirEmitCOpaqueAttrGet(MlirContext ctx,
+ MlirStringRef value);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirEmitCOpaqueAttrGetValue(MlirAttribute attr);
+
+MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCOpaqueAttrGetTypeID(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/mlir/lib/CAPI/Dialect/EmitC.cpp b/mlir/lib/CAPI/Dialect/EmitC.cpp
index 0672c2278790a2..bfc3330e8e1150 100644
--- a/mlir/lib/CAPI/Dialect/EmitC.cpp
+++ b/mlir/lib/CAPI/Dialect/EmitC.cpp
@@ -127,3 +127,45 @@ MlirTypeID mlirEmitCSizeTTypeGetTypeID(void) {
MlirType mlirEmitCSizeTTypeGet(MlirContext ctx) {
return wrap(emitc::SizeTType::get(unwrap(ctx)));
}
+
+//===----------------------------------------------------------------------===//
+// CmpPredicate attribute.
+//===----------------------------------------------------------------------===//
+
+bool mlirAttributeIsAEmitCCmpPredicate(MlirAttribute attr) {
+ return llvm::isa<emitc::CmpPredicateAttr>(unwrap(attr));
+}
+
+MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx, uint64_t val) {
+ return wrap((Attribute)emitc::CmpPredicateAttr::get(
+ unwrap(ctx), static_cast<emitc::CmpPredicate>(val)));
+}
+
+uint64_t mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr) {
+ return static_cast<uint64_t>(
+ llvm::cast<emitc::CmpPredicateAttr>(unwrap(attr)).getValue());
+}
+
+MlirTypeID mlirEmitCCmpPredicateAttrGetTypeID(void) {
+ return wrap(emitc::CmpPredicateAttr::getTypeID());
+}
+
+//===----------------------------------------------------------------------===//
+// Opaque attribute.
+//===----------------------------------------------------------------------===//
+
+bool mlirAttributeIsAEmitCOpaque(MlirAttribute attr) {
+ return llvm::isa<emitc::OpaqueAttr>(unwrap(attr));
+}
+
+MlirAttribute mlirEmitCOpaqueAttrGet(MlirContext ctx, MlirStringRef value) {
+ return wrap((Attribute)emitc::OpaqueAttr::get(unwrap(ctx), unwrap(value)));
+}
+
+MlirStringRef mlirEmitCOpaqueAttrGetValue(MlirAttribute attr) {
+ return wrap(llvm::cast<emitc::OpaqueAttr>(unwrap(attr)).getValue());
+}
+
+MlirTypeID mlirEmitCOpaqueAttrGetTypeID(void) {
+ return wrap(emitc::OpaqueAttr::getTypeID());
+}
>From 1b498bd4f427b3951a596e7ebb9d4c813857e487 Mon Sep 17 00:00:00 2001
From: TGMM <tgmm.1000 at gmail.com>
Date: Sat, 28 Dec 2024 21:59:50 -0800
Subject: [PATCH 4/4] Changed MlirEmitCCmpPredicate from uint64_t to enum
---
mlir/include/mlir-c/Dialect/EmitC.h | 16 +++++++++++++---
mlir/lib/CAPI/Dialect/EmitC.cpp | 24 +++++++++++++++++++++---
2 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/mlir/include/mlir-c/Dialect/EmitC.h b/mlir/include/mlir-c/Dialect/EmitC.h
index 9a7e4c2f462f1c..a0e3ea08a5a9f7 100644
--- a/mlir/include/mlir-c/Dialect/EmitC.h
+++ b/mlir/include/mlir-c/Dialect/EmitC.h
@@ -19,6 +19,16 @@ extern "C" {
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(EmitC, emitc);
+enum MlirEmitCCmpPredicate : uint64_t {
+ MLIR_EMITC_CMP_PREDICATE_EQ = 0,
+ MLIR_EMITC_CMP_PREDICATE_NE = 1,
+ MLIR_EMITC_CMP_PREDICATE_LT = 2,
+ MLIR_EMITC_CMP_PREDICATE_LE = 3,
+ MLIR_EMITC_CMP_PREDICATE_GT = 4,
+ MLIR_EMITC_CMP_PREDICATE_GE = 5,
+ MLIR_EMITC_CMP_PREDICATE_THREE_WAY = 6,
+};
+
//===---------------------------------------------------------------------===//
// ArrayType
//===---------------------------------------------------------------------===//
@@ -98,10 +108,10 @@ MLIR_CAPI_EXPORTED MlirType mlirEmitCSizeTTypeGet(MlirContext ctx);
MLIR_CAPI_EXPORTED bool mlirAttributeIsAEmitCCmpPredicate(MlirAttribute attr);
-MLIR_CAPI_EXPORTED MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx,
- uint64_t val);
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirEmitCCmpPredicateAttrGet(MlirContext ctx, enum MlirEmitCCmpPredicate val);
-MLIR_CAPI_EXPORTED uint64_t
+MLIR_CAPI_EXPORTED enum MlirEmitCCmpPredicate
mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr);
MLIR_CAPI_EXPORTED MlirTypeID mlirEmitCCmpPredicateAttrGetTypeID(void);
diff --git a/mlir/lib/CAPI/Dialect/EmitC.cpp b/mlir/lib/CAPI/Dialect/EmitC.cpp
index bfc3330e8e1150..b6d197366f6221 100644
--- a/mlir/lib/CAPI/Dialect/EmitC.cpp
+++ b/mlir/lib/CAPI/Dialect/EmitC.cpp
@@ -14,6 +14,23 @@ using namespace mlir;
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(EmitC, emitc, mlir::emitc::EmitCDialect)
+// Ensure the C-API enums are uint64_t-castable to C++ equivalents.
+static_assert(static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_EQ) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::eq) &&
+ static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_NE) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::ne) &&
+ static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_LT) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::lt) &&
+ static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_LE) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::le) &&
+ static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_GT) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::gt) &&
+ static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_GE) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::ge) &&
+ static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_THREE_WAY) ==
+ static_cast<uint64_t>(emitc::CmpPredicate::three_way),
+ "MlirEmitCCmpPredicate (C-API) and CmpPredicate (C++) mismatch");
+
//===---------------------------------------------------------------------===//
// ArrayType
//===---------------------------------------------------------------------===//
@@ -136,13 +153,14 @@ bool mlirAttributeIsAEmitCCmpPredicate(MlirAttribute attr) {
return llvm::isa<emitc::CmpPredicateAttr>(unwrap(attr));
}
-MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx, uint64_t val) {
+MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx,
+ MlirEmitCCmpPredicate val) {
return wrap((Attribute)emitc::CmpPredicateAttr::get(
unwrap(ctx), static_cast<emitc::CmpPredicate>(val)));
}
-uint64_t mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr) {
- return static_cast<uint64_t>(
+MlirEmitCCmpPredicate mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr) {
+ return static_cast<MlirEmitCCmpPredicate>(
llvm::cast<emitc::CmpPredicateAttr>(unwrap(attr)).getValue());
}
More information about the Mlir-commits
mailing list