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
57 return wrap(BitVectorType::getTypeID());
58}
59
60bool mlirSMTTypeIsABool(MlirType type) { return isa<BoolType>(unwrap(type)); }
61
62MlirType mlirSMTTypeGetBool(MlirContext ctx) {
63 return wrap(BoolType::get(unwrap(ctx)));
64}
65
66MlirStringRef mlirSMTBoolTypeGetName(void) { return wrap(BoolType::name); }
67
68MlirTypeID mlirSMTBoolTypeGetTypeID(void) {
69 return wrap(BoolType::getTypeID());
70}
71
72bool mlirSMTTypeIsAInt(MlirType type) { return isa<IntType>(unwrap(type)); }
73
74MlirType mlirSMTTypeGetInt(MlirContext ctx) {
75 return wrap(IntType::get(unwrap(ctx)));
76}
77
78MlirStringRef mlirSMTIntTypeGetName(void) { return wrap(IntType::name); }
79
80MlirTypeID mlirSMTIntTypeGetTypeID(void) { return wrap(IntType::getTypeID()); }
81
82bool mlirSMTTypeIsASMTFunc(MlirType type) {
83 return isa<SMTFuncType>(unwrap(type));
84}
85
86MlirType mlirSMTTypeGetSMTFunc(MlirContext ctx, size_t numberOfDomainTypes,
87 const MlirType *domainTypes,
88 MlirType rangeType) {
89 SmallVector<Type> domainTypesVec;
90 domainTypesVec.reserve(numberOfDomainTypes);
91
92 for (size_t i = 0; i < numberOfDomainTypes; i++)
93 domainTypesVec.push_back(unwrap(domainTypes[i]));
94
95 return wrap(SMTFuncType::get(unwrap(ctx), domainTypesVec, unwrap(rangeType)));
96}
97
98bool mlirSMTTypeIsASort(MlirType type) { return isa<SortType>(unwrap(type)); }
99
100MlirType mlirSMTTypeGetSort(MlirContext ctx, MlirIdentifier identifier,
101 size_t numberOfSortParams,
102 const MlirType *sortParams) {
103 SmallVector<Type> sortParamsVec;
104 sortParamsVec.reserve(numberOfSortParams);
105
106 for (size_t i = 0; i < numberOfSortParams; i++)
107 sortParamsVec.push_back(unwrap(sortParams[i]));
108
109 return wrap(SortType::get(unwrap(ctx), unwrap(identifier), sortParamsVec));
110}
111
112//===----------------------------------------------------------------------===//
113// Attribute API.
114//===----------------------------------------------------------------------===//
115
117 return symbolizeBVCmpPredicate(unwrap(str)).has_value();
118}
119
120bool mlirSMTAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str) {
121 return symbolizeIntPredicate(unwrap(str)).has_value();
122}
123
124bool mlirSMTAttrIsASMTAttribute(MlirAttribute attr) {
125 return isa<BitVectorAttr, BVCmpPredicateAttr, IntPredicateAttr>(unwrap(attr));
126}
127
128MlirAttribute mlirSMTAttrGetBitVector(MlirContext ctx, uint64_t value,
129 unsigned width) {
130 return wrap(BitVectorAttr::get(unwrap(ctx), value, width));
131}
132
133MlirAttribute mlirSMTAttrGetBVCmpPredicate(MlirContext ctx, MlirStringRef str) {
134 auto predicate = symbolizeBVCmpPredicate(unwrap(str));
135 assert(predicate.has_value() && "invalid predicate");
136
137 return wrap(BVCmpPredicateAttr::get(unwrap(ctx), predicate.value()));
138}
139
140MlirAttribute mlirSMTAttrGetIntPredicate(MlirContext ctx, MlirStringRef str) {
141 auto predicate = symbolizeIntPredicate(unwrap(str));
142 assert(predicate.has_value() && "invalid predicate");
143
144 return wrap(IntPredicateAttr::get(unwrap(ctx), predicate.value()));
145}
#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:140
MlirStringRef mlirSMTIntTypeGetName(void)
Definition SMT.cpp:78
bool mlirSMTTypeIsASMTFunc(MlirType type)
Checks if the given type is a smt::FuncType.
Definition SMT.cpp:82
MlirAttribute mlirSMTAttrGetBitVector(MlirContext ctx, uint64_t value, unsigned width)
Creates a smt::BitVectorAttr with the given value and width.
Definition SMT.cpp:128
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:60
bool mlirSMTAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::BVCmpPredicate.
Definition SMT.cpp:116
MlirType mlirSMTTypeGetInt(MlirContext ctx)
Creates a smt::IntType.
Definition SMT.cpp:74
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:133
bool mlirSMTTypeIsASort(MlirType type)
Checks if the given type is a smt::SortType.
Definition SMT.cpp:98
MlirStringRef mlirSMTBoolTypeGetName(void)
Definition SMT.cpp:66
bool mlirSMTAttrIsASMTAttribute(MlirAttribute attr)
Checks if the given attribute is a smt::SMTAttribute.
Definition SMT.cpp:124
MlirTypeID mlirSMTIntTypeGetTypeID(void)
Definition SMT.cpp:80
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
MlirTypeID mlirSMTBitVectorTypeGetTypeID(void)
Definition SMT.cpp:56
MlirTypeID mlirSMTBoolTypeGetTypeID(void)
Definition SMT.cpp:68
MlirType mlirSMTTypeGetBool(MlirContext ctx)
Creates a smt::BoolType.
Definition SMT.cpp:62
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:100
bool mlirSMTTypeIsAInt(MlirType type)
Checks if the given type is a smt::IntType.
Definition SMT.cpp:72
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:86
bool mlirSMTAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::IntPredicate.
Definition SMT.cpp:120
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:78