|
10 | 10 | #include "mlir/CAPI/Registration.h" |
11 | 11 | #include "mlir/Dialect/EmitC/IR/EmitC.h" |
12 | 12 |
|
| 13 | +using namespace mlir; |
| 14 | + |
13 | 15 | MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(EmitC, emitc, mlir::emitc::EmitCDialect) |
| 16 | + |
| 17 | +// Ensure the C-API enums are uint64_t-castable to C++ equivalents. |
| 18 | +static_assert(static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_EQ) == |
| 19 | + static_cast<uint64_t>(emitc::CmpPredicate::eq) && |
| 20 | + static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_NE) == |
| 21 | + static_cast<uint64_t>(emitc::CmpPredicate::ne) && |
| 22 | + static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_LT) == |
| 23 | + static_cast<uint64_t>(emitc::CmpPredicate::lt) && |
| 24 | + static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_LE) == |
| 25 | + static_cast<uint64_t>(emitc::CmpPredicate::le) && |
| 26 | + static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_GT) == |
| 27 | + static_cast<uint64_t>(emitc::CmpPredicate::gt) && |
| 28 | + static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_GE) == |
| 29 | + static_cast<uint64_t>(emitc::CmpPredicate::ge) && |
| 30 | + static_cast<uint64_t>(MLIR_EMITC_CMP_PREDICATE_THREE_WAY) == |
| 31 | + static_cast<uint64_t>(emitc::CmpPredicate::three_way), |
| 32 | + "MlirEmitCCmpPredicate (C-API) and CmpPredicate (C++) mismatch"); |
| 33 | + |
| 34 | +//===---------------------------------------------------------------------===// |
| 35 | +// ArrayType |
| 36 | +//===---------------------------------------------------------------------===// |
| 37 | + |
| 38 | +bool mlirTypeIsAEmitCArrayType(MlirType type) { |
| 39 | + return isa<emitc::ArrayType>(unwrap(type)); |
| 40 | +} |
| 41 | + |
| 42 | +MlirTypeID mlirEmitCArrayTypeGetTypeID(void) { |
| 43 | + return wrap(emitc::ArrayType::getTypeID()); |
| 44 | +} |
| 45 | + |
| 46 | +MlirType mlirEmitCArrayTypeGet(intptr_t nDims, int64_t *shape, |
| 47 | + MlirType elementType) { |
| 48 | + return wrap( |
| 49 | + emitc::ArrayType::get(llvm::ArrayRef(shape, nDims), unwrap(elementType))); |
| 50 | +} |
| 51 | + |
| 52 | +//===---------------------------------------------------------------------===// |
| 53 | +// LValueType |
| 54 | +//===---------------------------------------------------------------------===// |
| 55 | + |
| 56 | +bool mlirTypeIsAEmitCLValueType(MlirType type) { |
| 57 | + return isa<emitc::LValueType>(unwrap(type)); |
| 58 | +} |
| 59 | + |
| 60 | +MlirTypeID mlirEmitCLValueTypeGetTypeID(void) { |
| 61 | + return wrap(emitc::LValueType::getTypeID()); |
| 62 | +} |
| 63 | + |
| 64 | +MlirType mlirEmitCLValueTypeGet(MlirType valueType) { |
| 65 | + return wrap(emitc::LValueType::get(unwrap(valueType))); |
| 66 | +} |
| 67 | + |
| 68 | +//===---------------------------------------------------------------------===// |
| 69 | +// OpaqueType |
| 70 | +//===---------------------------------------------------------------------===// |
| 71 | + |
| 72 | +bool mlirTypeIsAEmitCOpaqueType(MlirType type) { |
| 73 | + return isa<emitc::OpaqueType>(unwrap(type)); |
| 74 | +} |
| 75 | + |
| 76 | +MlirTypeID mlirEmitCOpaqueTypeGetTypeID(void) { |
| 77 | + return wrap(emitc::OpaqueType::getTypeID()); |
| 78 | +} |
| 79 | + |
| 80 | +MlirType mlirEmitCOpaqueTypeGet(MlirContext ctx, MlirStringRef value) { |
| 81 | + return wrap(emitc::OpaqueType::get(unwrap(ctx), unwrap(value))); |
| 82 | +} |
| 83 | + |
| 84 | +//===---------------------------------------------------------------------===// |
| 85 | +// PointerType |
| 86 | +//===---------------------------------------------------------------------===// |
| 87 | + |
| 88 | +bool mlirTypeIsAEmitCPointerType(MlirType type) { |
| 89 | + return isa<emitc::PointerType>(unwrap(type)); |
| 90 | +} |
| 91 | + |
| 92 | +MlirTypeID mlirEmitCPointerTypeGetTypeID(void) { |
| 93 | + return wrap(emitc::PointerType::getTypeID()); |
| 94 | +} |
| 95 | + |
| 96 | +MlirType mlirEmitCPointerTypeGet(MlirType pointee) { |
| 97 | + return wrap(emitc::PointerType::get(unwrap(pointee))); |
| 98 | +} |
| 99 | + |
| 100 | +//===---------------------------------------------------------------------===// |
| 101 | +// PtrDiffTType |
| 102 | +//===---------------------------------------------------------------------===// |
| 103 | + |
| 104 | +bool mlirTypeIsAEmitCPtrDiffTType(MlirType type) { |
| 105 | + return isa<emitc::PtrDiffTType>(unwrap(type)); |
| 106 | +} |
| 107 | + |
| 108 | +MlirTypeID mlirEmitCPtrDiffTTypeGetTypeID(void) { |
| 109 | + return wrap(emitc::PtrDiffTType::getTypeID()); |
| 110 | +} |
| 111 | + |
| 112 | +MlirType mlirEmitCPtrDiffTTypeGet(MlirContext ctx) { |
| 113 | + return wrap(emitc::PtrDiffTType::get(unwrap(ctx))); |
| 114 | +} |
| 115 | + |
| 116 | +//===---------------------------------------------------------------------===// |
| 117 | +// SignedSizeTType |
| 118 | +//===---------------------------------------------------------------------===// |
| 119 | + |
| 120 | +bool mlirTypeIsAEmitCSignedSizeTType(MlirType type) { |
| 121 | + return isa<emitc::SignedSizeTType>(unwrap(type)); |
| 122 | +} |
| 123 | + |
| 124 | +MlirTypeID mlirEmitCSignedSizeTTypeGetTypeID(void) { |
| 125 | + return wrap(emitc::SignedSizeTType::getTypeID()); |
| 126 | +} |
| 127 | + |
| 128 | +MlirType mlirEmitCSignedSizeTTypeGet(MlirContext ctx) { |
| 129 | + return wrap(emitc::SignedSizeTType::get(unwrap(ctx))); |
| 130 | +} |
| 131 | + |
| 132 | +//===---------------------------------------------------------------------===// |
| 133 | +// SizeTType |
| 134 | +//===---------------------------------------------------------------------===// |
| 135 | + |
| 136 | +bool mlirTypeIsAEmitCSizeTType(MlirType type) { |
| 137 | + return isa<emitc::SizeTType>(unwrap(type)); |
| 138 | +} |
| 139 | + |
| 140 | +MlirTypeID mlirEmitCSizeTTypeGetTypeID(void) { |
| 141 | + return wrap(emitc::SizeTType::getTypeID()); |
| 142 | +} |
| 143 | + |
| 144 | +MlirType mlirEmitCSizeTTypeGet(MlirContext ctx) { |
| 145 | + return wrap(emitc::SizeTType::get(unwrap(ctx))); |
| 146 | +} |
| 147 | + |
| 148 | +//===----------------------------------------------------------------------===// |
| 149 | +// CmpPredicate attribute. |
| 150 | +//===----------------------------------------------------------------------===// |
| 151 | + |
| 152 | +bool mlirAttributeIsAEmitCCmpPredicate(MlirAttribute attr) { |
| 153 | + return llvm::isa<emitc::CmpPredicateAttr>(unwrap(attr)); |
| 154 | +} |
| 155 | + |
| 156 | +MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx, |
| 157 | + MlirEmitCCmpPredicate val) { |
| 158 | + return wrap((Attribute)emitc::CmpPredicateAttr::get( |
| 159 | + unwrap(ctx), static_cast<emitc::CmpPredicate>(val))); |
| 160 | +} |
| 161 | + |
| 162 | +MlirEmitCCmpPredicate mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr) { |
| 163 | + return static_cast<MlirEmitCCmpPredicate>( |
| 164 | + llvm::cast<emitc::CmpPredicateAttr>(unwrap(attr)).getValue()); |
| 165 | +} |
| 166 | + |
| 167 | +MlirTypeID mlirEmitCCmpPredicateAttrGetTypeID(void) { |
| 168 | + return wrap(emitc::CmpPredicateAttr::getTypeID()); |
| 169 | +} |
| 170 | + |
| 171 | +//===----------------------------------------------------------------------===// |
| 172 | +// Opaque attribute. |
| 173 | +//===----------------------------------------------------------------------===// |
| 174 | + |
| 175 | +bool mlirAttributeIsAEmitCOpaque(MlirAttribute attr) { |
| 176 | + return llvm::isa<emitc::OpaqueAttr>(unwrap(attr)); |
| 177 | +} |
| 178 | + |
| 179 | +MlirAttribute mlirEmitCOpaqueAttrGet(MlirContext ctx, MlirStringRef value) { |
| 180 | + return wrap((Attribute)emitc::OpaqueAttr::get(unwrap(ctx), unwrap(value))); |
| 181 | +} |
| 182 | + |
| 183 | +MlirStringRef mlirEmitCOpaqueAttrGetValue(MlirAttribute attr) { |
| 184 | + return wrap(llvm::cast<emitc::OpaqueAttr>(unwrap(attr)).getValue()); |
| 185 | +} |
| 186 | + |
| 187 | +MlirTypeID mlirEmitCOpaqueAttrGetTypeID(void) { |
| 188 | + return wrap(emitc::OpaqueAttr::getTypeID()); |
| 189 | +} |
0 commit comments