CIRCT 21.0.0git
Loading...
Searching...
No Matches
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
12
13#include "mlir/CAPI/Registration.h"
14
15using namespace circt;
16using namespace smt;
17
18//===----------------------------------------------------------------------===//
19// Dialect API.
20//===----------------------------------------------------------------------===//
21
22MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SMT, smt, circt::smt::SMTDialect)
23
24//===----------------------------------------------------------------------===//
25// Type API.
26//===----------------------------------------------------------------------===//
27
29 return isAnyNonFuncSMTValueType(unwrap(type));
30}
31
32bool smtTypeIsAnySMTValueType(MlirType type) {
33 return isAnySMTValueType(unwrap(type));
34}
35
36bool smtTypeIsAArray(MlirType type) { return isa<ArrayType>(unwrap(type)); }
37
38MlirType smtTypeGetArray(MlirContext ctx, MlirType domainType,
39 MlirType rangeType) {
40 return wrap(
41 ArrayType::get(unwrap(ctx), unwrap(domainType), unwrap(rangeType)));
42}
43
44bool smtTypeIsABitVector(MlirType type) {
45 return isa<BitVectorType>(unwrap(type));
46}
47
48MlirType smtTypeGetBitVector(MlirContext ctx, int32_t width) {
49 return wrap(BitVectorType::get(unwrap(ctx), width));
50}
51
52bool smtTypeIsABool(MlirType type) { return isa<BoolType>(unwrap(type)); }
53
54MlirType smtTypeGetBool(MlirContext ctx) {
55 return wrap(BoolType::get(unwrap(ctx)));
56}
57
58bool smtTypeIsAInt(MlirType type) { return isa<IntType>(unwrap(type)); }
59
60MlirType smtTypeGetInt(MlirContext ctx) {
61 return wrap(IntType::get(unwrap(ctx)));
62}
63
64bool smtTypeIsASMTFunc(MlirType type) { return isa<SMTFuncType>(unwrap(type)); }
65
66MlirType 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
77bool smtTypeIsASort(MlirType type) { return isa<SortType>(unwrap(type)); }
78
79MlirType 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
94bool smtAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str) {
95 return symbolizeBVCmpPredicate(unwrap(str)).has_value();
96}
97
98bool smtAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str) {
99 return symbolizeIntPredicate(unwrap(str)).has_value();
100}
101
102bool smtAttrIsASMTAttribute(MlirAttribute attr) {
103 return isa<BitVectorAttr, BVCmpPredicateAttr, IntPredicateAttr>(unwrap(attr));
104}
105
106MlirAttribute smtAttrGetBitVector(MlirContext ctx, uint64_t value,
107 unsigned width) {
108 return wrap(BitVectorAttr::get(unwrap(ctx), value, width));
109}
110
111MlirAttribute 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
118MlirAttribute 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}
assert(baseType &&"element must be base type")
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:113
bool smtTypeIsABitVector(MlirType type)
Checks if the given type is a smt::BitVectorType.
Definition SMT.cpp:44
bool smtTypeIsASMTFunc(MlirType type)
Checks if the given type is a smt::FuncType.
Definition SMT.cpp:64
MlirType smtTypeGetSort(MlirContext ctx, MlirIdentifier identifier, size_t numberOfSortParams, const MlirType *sortParams)
Creates a smt::SortType with the given identifier and sort parameters.
Definition SMT.cpp:79
bool smtTypeIsABool(MlirType type)
Checks if the given type is a smt::BoolType.
Definition SMT.cpp:52
MlirAttribute smtAttrGetBitVector(MlirContext ctx, uint64_t value, unsigned width)
Creates a smt::BitVectorAttr with the given value and width.
Definition SMT.cpp:106
bool smtTypeIsAnyNonFuncSMTValueType(MlirType type)
Checks if the given type is any non-func SMT value type.
Definition SMT.cpp:28
bool smtTypeIsAInt(MlirType type)
Checks if the given type is a smt::IntType.
Definition SMT.cpp:58
MlirType smtTypeGetBool(MlirContext ctx)
Creates a smt::BoolType.
Definition SMT.cpp:54
MlirType smtTypeGetBitVector(MlirContext ctx, int32_t width)
Creates a smt::BitVectorType with the given width.
Definition SMT.cpp:48
MlirType smtTypeGetSMTFunc(MlirContext ctx, size_t numberOfDomainTypes, const MlirType *domainTypes, MlirType rangeType)
Creates a smt::FuncType with the given domain and range types.
Definition SMT.cpp:66
bool smtAttrIsASMTAttribute(MlirAttribute attr)
Checks if the given attribute is a smt::SMTAttribute.
Definition SMT.cpp:102
MlirAttribute smtAttrGetIntPredicate(MlirContext ctx, MlirStringRef str)
Creates a smt::IntPredicateAttr with the given string.
Definition SMT.cpp:118
bool smtTypeIsAArray(MlirType type)
Checks if the given type is a smt::ArrayType.
Definition SMT.cpp:36
MlirType smtTypeGetInt(MlirContext ctx)
Creates a smt::IntType.
Definition SMT.cpp:60
MlirAttribute smtAttrGetBVCmpPredicate(MlirContext ctx, MlirStringRef str)
Creates a smt::BVCmpPredicateAttr with the given string.
Definition SMT.cpp:111
bool smtAttrCheckBVCmpPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::BVCmpPredicate.
Definition SMT.cpp:94
MlirType smtTypeGetArray(MlirContext ctx, MlirType domainType, MlirType rangeType)
Creates an array type with the given domain and range types.
Definition SMT.cpp:38
bool smtTypeIsAnySMTValueType(MlirType type)
Checks if the given type is any SMT value type.
Definition SMT.cpp:32
bool smtTypeIsASort(MlirType type)
Checks if the given type is a smt::SortType.
Definition SMT.cpp:77
bool smtAttrCheckIntPredicate(MlirContext ctx, MlirStringRef str)
Checks if the given string is a valid smt::IntPredicate.
Definition SMT.cpp:98
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition smt.py:1