|
| 1 | +//===- SMT.cpp - C interface for the SMT dialect --------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "mlir-c/Dialect/SMT.h" |
| 10 | +#include "mlir/CAPI/Registration.h" |
| 11 | +#include "mlir/Dialect/SMT/IR/SMTDialect.h" |
| 12 | +#include "mlir/Dialect/SMT/IR/SMTOps.h" |
| 13 | + |
| 14 | +using namespace mlir; |
| 15 | +using namespace smt; |
| 16 | + |
| 17 | +//===----------------------------------------------------------------------===// |
| 18 | +// Dialect API. |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | + |
| 21 | +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SMT, smt, mlir::smt::SMTDialect) |
| 22 | + |
| 23 | +//===----------------------------------------------------------------------===// |
| 24 | +// Type API. |
| 25 | +//===----------------------------------------------------------------------===// |
| 26 | + |
| 27 | +bool smtTypeIsAnyNonFuncSMTValueType(MlirType type) { |
| 28 | + return isAnyNonFuncSMTValueType(unwrap(type)); |
| 29 | +} |
| 30 | + |
| 31 | +bool smtTypeIsAnySMTValueType(MlirType type) { |
| 32 | + return isAnySMTValueType(unwrap(type)); |
| 33 | +} |
| 34 | + |
| 35 | +bool smtTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); } |
| 36 | + |
| 37 | +MlirType smtTypeGetArray(MlirContext ctx, MlirType domainType, |
| 38 | + MlirType rangeType) { |
| 39 | + return wrap( |
| 40 | + ArrayType::get(unwrap(ctx), unwrap(domainType), unwrap(rangeType))); |
| 41 | +} |
| 42 | + |
| 43 | +bool smtTypeIsABitVector(MlirType type) { |
| 44 | + return isa<BitVectorType>(unwrap(type)); |
| 45 | +} |
| 46 | + |
| 47 | +MlirType smtTypeGetBitVector(MlirContext ctx, int32_t width) { |
| 48 | + return wrap(BitVectorType::get(unwrap(ctx), width)); |
| 49 | +} |
| 50 | + |
| 51 | +bool smtTypeIsABool(MlirType type) { return isa<BoolType>(unwrap(type)); } |
| 52 | + |
| 53 | +MlirType smtTypeGetBool(MlirContext ctx) { |
| 54 | + return wrap(BoolType::get(unwrap(ctx))); |
| 55 | +} |
| 56 | + |
| 57 | +bool smtTypeIsAInt(MlirType type) { return isa<IntType>(unwrap(type)); } |
| 58 | + |
| 59 | +MlirType smtTypeGetInt(MlirContext ctx) { |
| 60 | + return wrap(IntType::get(unwrap(ctx))); |
| 61 | +} |
| 62 | + |
| 63 | +bool smtTypeIsASMTFunc(MlirType type) { return isa<SMTFuncType>(unwrap(type)); } |
| 64 | + |
| 65 | +MlirType smtTypeGetSMTFunc(MlirContext ctx, size_t numberOfDomainTypes, |
| 66 | + const MlirType *domainTypes, MlirType rangeType) { |
| 67 | + SmallVector<Type> domainTypesVec; |
| 68 | + domainTypesVec.reserve(numberOfDomainTypes); |
| 69 | + |
| 70 | + for (size_t i = 0; i < numberOfDomainTypes; i++) |
| 71 | + domainTypesVec.push_back(unwrap(domainTypes[i])); |
| 72 | + |
| 73 | + return wrap(SMTFuncType::get(unwrap(ctx), domainTypesVec, unwrap(rangeType))); |
| 74 | +} |
| 75 | + |
| 76 | +bool smtTypeIsASort(MlirType type) { return isa<SortType>(unwrap(type)); } |
| 77 | + |
| 78 | +MlirType smtTypeGetSort(MlirContext ctx, MlirIdentifier identifier, |
| 79 | + size_t numberOfSortParams, const MlirType *sortParams) { |
| 80 | + SmallVector<Type> sortParamsVec; |
| 81 | + sortParamsVec.reserve(numberOfSortParams); |
| 82 | + |
| 83 | + for (size_t i = 0; i < numberOfSortParams; i++) |
| 84 | + sortParamsVec.push_back(unwrap(sortParams[i])); |
| 85 | + |
| 86 | + return wrap(SortType::get(unwrap(ctx), unwrap(identifier), sortParamsVec)); |
| 87 | +} |
| 88 | + |
| 89 | +//===----------------------------------------------------------------------===// |
| 90 | +// Attribute API. |
| 91 | +//===----------------------------------------------------------------------===// |
| 92 | + |
| 93 | +bool smtAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str) { |
| 94 | + return symbolizeBVCmpPredicate(unwrap(str)).has_value(); |
| 95 | +} |
| 96 | + |
| 97 | +bool smtAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str) { |
| 98 | + return symbolizeIntPredicate(unwrap(str)).has_value(); |
| 99 | +} |
| 100 | + |
| 101 | +bool smtAttrIsASMTAttribute(MlirAttribute attr) { |
| 102 | + return isa<BitVectorAttr, BVCmpPredicateAttr, IntPredicateAttr>(unwrap(attr)); |
| 103 | +} |
| 104 | + |
| 105 | +MlirAttribute smtAttrGetBitVector(MlirContext ctx, uint64_t value, |
| 106 | + unsigned width) { |
| 107 | + return wrap(BitVectorAttr::get(unwrap(ctx), value, width)); |
| 108 | +} |
| 109 | + |
| 110 | +MlirAttribute smtAttrGetBVCmpPredicate(MlirContext ctx, MlirStringRef str) { |
| 111 | + auto predicate = symbolizeBVCmpPredicate(unwrap(str)); |
| 112 | + assert(predicate.has_value() && "invalid predicate"); |
| 113 | + |
| 114 | + return wrap(BVCmpPredicateAttr::get(unwrap(ctx), predicate.value())); |
| 115 | +} |
| 116 | + |
| 117 | +MlirAttribute smtAttrGetIntPredicate(MlirContext ctx, MlirStringRef str) { |
| 118 | + auto predicate = symbolizeIntPredicate(unwrap(str)); |
| 119 | + assert(predicate.has_value() && "invalid predicate"); |
| 120 | + |
| 121 | + return wrap(IntPredicateAttr::get(unwrap(ctx), predicate.value())); |
| 122 | +} |
0 commit comments