MLIR  21.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 
9 #include "mlir-c/Dialect/SMT.h"
10 #include "mlir/CAPI/Registration.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 
29  return isAnyNonFuncSMTValueType(unwrap(type));
30 }
31 
32 bool mlirSMTTypeIsAnySMTValueType(MlirType type) {
33  return isAnySMTValueType(unwrap(type));
34 }
35 
36 bool mlirSMTTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); }
37 
38 MlirType mlirSMTTypeGetArray(MlirContext ctx, MlirType domainType,
39  MlirType rangeType) {
40  return wrap(
41  ArrayType::get(unwrap(ctx), unwrap(domainType), unwrap(rangeType)));
42 }
43 
44 bool mlirSMTTypeIsABitVector(MlirType type) {
45  return isa<BitVectorType>(unwrap(type));
46 }
47 
48 MlirType mlirSMTTypeGetBitVector(MlirContext ctx, int32_t width) {
49  return wrap(BitVectorType::get(unwrap(ctx), width));
50 }
51 
52 bool mlirSMTTypeIsABool(MlirType type) { return isa<BoolType>(unwrap(type)); }
53 
54 MlirType mlirSMTTypeGetBool(MlirContext ctx) {
55  return wrap(BoolType::get(unwrap(ctx)));
56 }
57 
58 bool mlirSMTTypeIsAInt(MlirType type) { return isa<IntType>(unwrap(type)); }
59 
60 MlirType mlirSMTTypeGetInt(MlirContext ctx) {
61  return wrap(IntType::get(unwrap(ctx)));
62 }
63 
64 bool mlirSMTTypeIsASMTFunc(MlirType type) {
65  return isa<SMTFuncType>(unwrap(type));
66 }
67 
68 MlirType mlirSMTTypeGetSMTFunc(MlirContext ctx, size_t numberOfDomainTypes,
69  const MlirType *domainTypes,
70  MlirType rangeType) {
71  SmallVector<Type> domainTypesVec;
72  domainTypesVec.reserve(numberOfDomainTypes);
73 
74  for (size_t i = 0; i < numberOfDomainTypes; i++)
75  domainTypesVec.push_back(unwrap(domainTypes[i]));
76 
77  return wrap(SMTFuncType::get(unwrap(ctx), domainTypesVec, unwrap(rangeType)));
78 }
79 
80 bool mlirSMTTypeIsASort(MlirType type) { return isa<SortType>(unwrap(type)); }
81 
82 MlirType mlirSMTTypeGetSort(MlirContext ctx, MlirIdentifier identifier,
83  size_t numberOfSortParams,
84  const MlirType *sortParams) {
85  SmallVector<Type> sortParamsVec;
86  sortParamsVec.reserve(numberOfSortParams);
87 
88  for (size_t i = 0; i < numberOfSortParams; i++)
89  sortParamsVec.push_back(unwrap(sortParams[i]));
90 
91  return wrap(SortType::get(unwrap(ctx), unwrap(identifier), sortParamsVec));
92 }
93 
94 //===----------------------------------------------------------------------===//
95 // Attribute API.
96 //===----------------------------------------------------------------------===//
97 
98 bool mlirSMTAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str) {
99  return symbolizeBVCmpPredicate(unwrap(str)).has_value();
100 }
101 
102 bool mlirSMTAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str) {
103  return symbolizeIntPredicate(unwrap(str)).has_value();
104 }
105 
106 bool mlirSMTAttrIsASMTAttribute(MlirAttribute attr) {
107  return isa<BitVectorAttr, BVCmpPredicateAttr, IntPredicateAttr>(unwrap(attr));
108 }
109 
110 MlirAttribute mlirSMTAttrGetBitVector(MlirContext ctx, uint64_t value,
111  unsigned width) {
112  return wrap(BitVectorAttr::get(unwrap(ctx), value, width));
113 }
114 
115 MlirAttribute mlirSMTAttrGetBVCmpPredicate(MlirContext ctx, MlirStringRef str) {
116  auto predicate = symbolizeBVCmpPredicate(unwrap(str));
117  assert(predicate.has_value() && "invalid predicate");
118 
119  return wrap(BVCmpPredicateAttr::get(unwrap(ctx), predicate.value()));
120 }
121 
122 MlirAttribute mlirSMTAttrGetIntPredicate(MlirContext ctx, MlirStringRef str) {
123  auto predicate = symbolizeIntPredicate(unwrap(str));
124  assert(predicate.has_value() && "invalid predicate");
125 
126  return wrap(IntPredicateAttr::get(unwrap(ctx), predicate.value()));
127 }
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
Definition: Registration.h:36
MlirAttribute mlirSMTAttrGetIntPredicate(MlirContext ctx, MlirStringRef str)
Creates a smt::IntPredicateAttr with the given string.
Definition: SMT.cpp:122
bool mlirSMTTypeIsASMTFunc(MlirType type)
Checks if the given type is a smt::FuncType.
Definition: SMT.cpp:64
MlirAttribute mlirSMTAttrGetBitVector(MlirContext ctx, uint64_t value, unsigned width)
Creates a smt::BitVectorAttr with the given value and width.
Definition: SMT.cpp:110
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:52
bool mlirSMTAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::BVCmpPredicate.
Definition: SMT.cpp:98
MlirType mlirSMTTypeGetInt(MlirContext ctx)
Creates a smt::IntType.
Definition: SMT.cpp:60
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:115
bool mlirSMTTypeIsASort(MlirType type)
Checks if the given type is a smt::SortType.
Definition: SMT.cpp:80
bool mlirSMTAttrIsASMTAttribute(MlirAttribute attr)
Checks if the given attribute is a smt::SMTAttribute.
Definition: SMT.cpp:106
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:54
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:82
bool mlirSMTTypeIsAnyNonFuncSMTValueType(MlirType type)
Checks if the given type is any non-func SMT value type.
Definition: SMT.cpp:28
bool mlirSMTTypeIsAInt(MlirType type)
Checks if the given type is a smt::IntType.
Definition: SMT.cpp:58
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:68
bool mlirSMTAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::IntPredicate.
Definition: SMT.cpp:102
bool mlirSMTTypeIsABitVector(MlirType type)
Checks if the given type is a smt::BitVectorType.
Definition: SMT.cpp:44
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73