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