MLIR 23.0.0git
SMT.cpp
Go to the documentation of this file.
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
14
15using namespace mlir;
16using namespace smt;
17
18//===----------------------------------------------------------------------===//
19// Dialect API.
20//===----------------------------------------------------------------------===//
21
22MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SMT, smt, mlir::smt::SMTDialect)
23
24//===----------------------------------------------------------------------===//
25// Type API.
26//===----------------------------------------------------------------------===//
27
31
32bool mlirSMTTypeIsAnySMTValueType(MlirType type) {
33 return isAnySMTValueType(unwrap(type));
34}
35
36bool mlirSMTTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); }
37
38MlirType mlirSMTTypeGetArray(MlirContext ctx, MlirType domainType,
39 MlirType rangeType) {
40 return wrap(
41 ArrayType::get(unwrap(ctx), unwrap(domainType), unwrap(rangeType)));
42}
43
44bool mlirSMTTypeIsABitVector(MlirType type) {
45 return isa<BitVectorType>(unwrap(type));
46}
47
48MlirType mlirSMTTypeGetBitVector(MlirContext ctx, int32_t width) {
49 return wrap(BitVectorType::get(unwrap(ctx), width));
50}
51
53 return wrap(BitVectorType::name);
54}
55
56bool mlirSMTTypeIsABool(MlirType type) { return isa<BoolType>(unwrap(type)); }
57
58MlirType mlirSMTTypeGetBool(MlirContext ctx) {
59 return wrap(BoolType::get(unwrap(ctx)));
60}
61
62MlirStringRef mlirSMTBoolTypeGetName(void) { return wrap(BoolType::name); }
63
64bool mlirSMTTypeIsAInt(MlirType type) { return isa<IntType>(unwrap(type)); }
65
66MlirType mlirSMTTypeGetInt(MlirContext ctx) {
67 return wrap(IntType::get(unwrap(ctx)));
68}
69
70MlirStringRef mlirSMTIntTypeGetName(void) { return wrap(IntType::name); }
71
72bool mlirSMTTypeIsASMTFunc(MlirType type) {
73 return isa<SMTFuncType>(unwrap(type));
74}
75
76MlirType mlirSMTTypeGetSMTFunc(MlirContext ctx, size_t numberOfDomainTypes,
77 const MlirType *domainTypes,
78 MlirType rangeType) {
79 SmallVector<Type> domainTypesVec;
80 domainTypesVec.reserve(numberOfDomainTypes);
81
82 for (size_t i = 0; i < numberOfDomainTypes; i++)
83 domainTypesVec.push_back(unwrap(domainTypes[i]));
84
85 return wrap(SMTFuncType::get(unwrap(ctx), domainTypesVec, unwrap(rangeType)));
86}
87
88bool mlirSMTTypeIsASort(MlirType type) { return isa<SortType>(unwrap(type)); }
89
90MlirType mlirSMTTypeGetSort(MlirContext ctx, MlirIdentifier identifier,
91 size_t numberOfSortParams,
92 const MlirType *sortParams) {
93 SmallVector<Type> sortParamsVec;
94 sortParamsVec.reserve(numberOfSortParams);
95
96 for (size_t i = 0; i < numberOfSortParams; i++)
97 sortParamsVec.push_back(unwrap(sortParams[i]));
98
99 return wrap(SortType::get(unwrap(ctx), unwrap(identifier), sortParamsVec));
100}
101
102//===----------------------------------------------------------------------===//
103// Attribute API.
104//===----------------------------------------------------------------------===//
105
107 return symbolizeBVCmpPredicate(unwrap(str)).has_value();
108}
109
110bool mlirSMTAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str) {
111 return symbolizeIntPredicate(unwrap(str)).has_value();
112}
113
114bool mlirSMTAttrIsASMTAttribute(MlirAttribute attr) {
115 return isa<BitVectorAttr, BVCmpPredicateAttr, IntPredicateAttr>(unwrap(attr));
116}
117
118MlirAttribute mlirSMTAttrGetBitVector(MlirContext ctx, uint64_t value,
119 unsigned width) {
120 return wrap(BitVectorAttr::get(unwrap(ctx), value, width));
121}
122
123MlirAttribute mlirSMTAttrGetBVCmpPredicate(MlirContext ctx, MlirStringRef str) {
124 auto predicate = symbolizeBVCmpPredicate(unwrap(str));
125 assert(predicate.has_value() && "invalid predicate");
126
127 return wrap(BVCmpPredicateAttr::get(unwrap(ctx), predicate.value()));
128}
129
130MlirAttribute mlirSMTAttrGetIntPredicate(MlirContext ctx, MlirStringRef str) {
131 auto predicate = symbolizeIntPredicate(unwrap(str));
132 assert(predicate.has_value() && "invalid predicate");
133
134 return wrap(IntPredicateAttr::get(unwrap(ctx), predicate.value()));
135}
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
MlirAttribute mlirSMTAttrGetIntPredicate(MlirContext ctx, MlirStringRef str)
Creates a smt::IntPredicateAttr with the given string.
Definition SMT.cpp:130
MlirStringRef mlirSMTIntTypeGetName(void)
Definition SMT.cpp:70
bool mlirSMTTypeIsASMTFunc(MlirType type)
Checks if the given type is a smt::FuncType.
Definition SMT.cpp:72
MlirAttribute mlirSMTAttrGetBitVector(MlirContext ctx, uint64_t value, unsigned width)
Creates a smt::BitVectorAttr with the given value and width.
Definition SMT.cpp:118
MlirType mlirSMTTypeGetArray(MlirContext ctx, MlirType domainType, MlirType rangeType)
Creates an array type with the given domain and range types.
Definition SMT.cpp:38
bool mlirSMTTypeIsABool(MlirType type)
Checks if the given type is a smt::BoolType.
Definition SMT.cpp:56
bool mlirSMTAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::BVCmpPredicate.
Definition SMT.cpp:106
MlirType mlirSMTTypeGetInt(MlirContext ctx)
Creates a smt::IntType.
Definition SMT.cpp:66
MlirType mlirSMTTypeGetBitVector(MlirContext ctx, int32_t width)
Creates a smt::BitVectorType with the given width.
Definition SMT.cpp:48
MlirAttribute mlirSMTAttrGetBVCmpPredicate(MlirContext ctx, MlirStringRef str)
Creates a smt::BVCmpPredicateAttr with the given string.
Definition SMT.cpp:123
bool mlirSMTTypeIsASort(MlirType type)
Checks if the given type is a smt::SortType.
Definition SMT.cpp:88
MlirStringRef mlirSMTBoolTypeGetName(void)
Definition SMT.cpp:62
bool mlirSMTAttrIsASMTAttribute(MlirAttribute attr)
Checks if the given attribute is a smt::SMTAttribute.
Definition SMT.cpp:114
bool mlirSMTTypeIsAnySMTValueType(MlirType type)
Checks if the given type is any SMT value type.
Definition SMT.cpp:32
bool mlirSMTTypeIsAArray(MlirType type)
Checks if the given type is a smt::ArrayType.
Definition SMT.cpp:36
MlirType mlirSMTTypeGetBool(MlirContext ctx)
Creates a smt::BoolType.
Definition SMT.cpp:58
MlirType mlirSMTTypeGetSort(MlirContext ctx, MlirIdentifier identifier, size_t numberOfSortParams, const MlirType *sortParams)
Creates a smt::SortType with the given identifier and sort parameters.
Definition SMT.cpp:90
bool mlirSMTTypeIsAInt(MlirType type)
Checks if the given type is a smt::IntType.
Definition SMT.cpp:64
MlirType mlirSMTTypeGetSMTFunc(MlirContext ctx, size_t numberOfDomainTypes, const MlirType *domainTypes, MlirType rangeType)
Creates a smt::FuncType with the given domain and range types.
Definition SMT.cpp:76
bool mlirSMTAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::IntPredicate.
Definition SMT.cpp:110
MlirStringRef mlirSMTBitVectorTypeGetName(void)
Definition SMT.cpp:52
bool mlirSMTTypeIsABitVector(MlirType type)
Checks if the given type is a smt::BitVectorType.
Definition SMT.cpp:44
MLIR_CAPI_EXPORTED bool mlirSMTTypeIsAnyNonFuncSMTValueType(MlirType type)
Checks if the given type is any non-func SMT value type.
Definition SMT.cpp:28
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
bool isAnySMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type.
Definition SMTTypes.cpp:33
bool isAnyNonFuncSMTValueType(mlir::Type type)
Returns whether the given type is an SMT value type (excluding functions).
Definition SMTTypes.cpp:29
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:75