14#include <mlir/IR/OpImplementation.h>
15#include <mlir/IR/Operation.h>
16#include <mlir/IR/SymbolTable.h>
18#include <llvm/ADT/ArrayRef.h>
19#include <llvm/ADT/DenseMap.h>
20#include <llvm/ADT/StringRef.h>
39class BuildShortTypeString {
40 static constexpr char PLACEHOLDER =
'\x1A';
43 llvm::raw_string_ostream ss;
45 BuildShortTypeString() : ret(), ss(ret) {}
46 BuildShortTypeString &append(mlir::Type);
47 BuildShortTypeString &append(mlir::ArrayRef<mlir::Attribute>);
48 BuildShortTypeString &append(mlir::Attribute);
50 void appendSymRef(mlir::SymbolRefAttr);
51 void appendSymName(mlir::StringRef);
55 static inline std::string
from(mlir::Type type) {
56 return BuildShortTypeString().append(type).ret;
61 static inline std::string
from(mlir::ArrayRef<mlir::Attribute> attrs) {
62 return BuildShortTypeString().append(attrs).ret;
72 static std::string
from(
const std::string &base, mlir::ArrayRef<mlir::Attribute> attrs);
89 mlir::Type type, mlir::SymbolTableCollection &symbolTable, mlir::Operation *op
116 return emitError() <<
"expected a valid LLZK type but found " << type;
118 return mlir::success();
126static inline mlir::raw_ostream &
operator<<(mlir::raw_ostream &os,
const Side &val) {
158template <>
struct DenseMapInfo<
llzk::Side> {
163 using UT = std::underlying_type_t<T>;
164 return llvm::DenseMapInfo<UT>::getHashValue(
static_cast<UT
>(val));
166 static bool isEqual(
const T &lhs,
const T &rhs) {
return lhs == rhs; }
172bool isDynamic(mlir::IntegerAttr intAttr);
186using UnificationMap = mlir::DenseMap<std::pair<mlir::SymbolRefAttr, Side>, mlir::Attribute>;
191 const mlir::ArrayRef<mlir::Attribute> &lhsParams,
192 const mlir::ArrayRef<mlir::Attribute> &rhsParams,
UnificationMap *unifications =
nullptr
198 const mlir::ArrayAttr &lhsParams,
const mlir::ArrayAttr &rhsParams,
206 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
213 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
226 mlir::FunctionType lhs, mlir::FunctionType rhs,
227 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
233 mlir::Type lhs, mlir::Type rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
239template <
typename Iter1,
typename Iter2>
241 Iter1 lhs, Iter2 rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
244 return (lhs.size() == rhs.size()) &&
245 std::equal(lhs.begin(), lhs.end(), rhs.begin(), [&](mlir::Type a, mlir::Type b) {
246 return typesUnify(a, b, rhsReversePrefix, unifications);
250template <
typename Iter1,
typename Iter2>
252 Iter1 lhs, Iter2 rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
255 return lhs.size() == 1 && rhs.size() == 1 &&
256 typesUnify(lhs.front(), rhs.front(), rhsReversePrefix, unifications);
266 mlir::Type oldTy, mlir::Type newTy,
267 llvm::function_ref<
bool(mlir::Type oldTy, mlir::Type newTy)> knownOldToNew =
nullptr
270template <
typename TypeClass>
inline TypeClass
getIfSingleton(mlir::TypeRange types) {
271 return (types.size() == 1) ? llvm::dyn_cast<TypeClass>(types.front()) :
nullptr;
274template <
typename TypeClass>
inline TypeClass
getAtIndex(mlir::TypeRange types,
size_t index) {
275 return (types.size() > index) ? llvm::dyn_cast<TypeClass>(types[index]) :
nullptr;
285mlir::FailureOr<llvm::SmallVector<mlir::Attribute>>
303 EmitErrorFn emitError, mlir::Type elementType, mlir::ArrayRef<mlir::Attribute> dimensionSizes
static std::string from(mlir::ArrayRef< mlir::Attribute > attrs)
Return a brief string representation of the attribute list from a parameterized type.
static std::string from(const std::string &base, mlir::ArrayRef< mlir::Attribute > attrs)
Take an existing name prefix/base that contains N>=0 PLACEHOLDER character(s) and the Attribute list ...
static std::string from(mlir::Type type)
Return a brief string representation of the given LLZK type.
LogicalResult verifyAffineMapAttrType(EmitErrorFn emitError, Attribute in)
void assertValidAttrForParamOfType(Attribute attr)
LogicalResult verifySubArrayType(EmitErrorFn emitError, ArrayType arrayType, ArrayType subArrayType)
Determine if the subArrayType is a valid subarray of arrayType.
FailureOr< Attribute > forceIntAttrType(Attribute attr, EmitErrorFn emitError)
uint64_t computeEmitEqCardinality(Type type)
bool isValidArrayType(Type type)
LogicalResult verifyIntAttrType(EmitErrorFn emitError, Attribute in)
bool typeListsUnify(Iter1 lhs, Iter2 rhs, mlir::ArrayRef< llvm::StringRef > rhsReversePrefix={}, UnificationMap *unifications=nullptr)
Return true iff the two lists of Type instances are equivalent or could be equivalent after full inst...
bool isConcreteType(Type type, bool allowStructParams)
bool isValidArrayElemType(Type type)
TypeClass getIfSingleton(mlir::TypeRange types)
bool isValidGlobalType(Type type)
FailureOr< IntegerAttr > forceIntType(IntegerAttr attr, EmitErrorFn emitError)
Convert an IntegerAttr with a type other than IndexType to use IndexType.
bool singletonTypeListsUnify(Iter1 lhs, Iter2 rhs, mlir::ArrayRef< llvm::StringRef > rhsReversePrefix={}, UnificationMap *unifications=nullptr)
bool structTypesUnify(StructType lhs, StructType rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
LogicalResult verifyArrayType(EmitErrorFn emitError, Type elementType, ArrayRef< Attribute > dimensionSizes)
bool isFeltOrSimpleFeltAggregate(Type ty)
LogicalResult verifySubArrayOrElementType(EmitErrorFn emitError, ArrayType arrayType, Type subArrayOrElemType)
bool isValidColumnType(Type type, SymbolTableCollection &symbolTable, Operation *op)
bool isValidMainSignalType(Type pType)
mlir::DenseMap< std::pair< mlir::SymbolRefAttr, Side >, mlir::Attribute > UnificationMap
Optional result from type unifications.
llvm::function_ref< InFlightDiagnosticWrapper()> EmitErrorFn
Callback to produce an error diagnostic.
FailureOr< SmallVector< Attribute > > forceIntAttrTypes(ArrayRef< Attribute > attrList, EmitErrorFn emitError)
Interval operator<<(const Interval &lhs, const Interval &rhs)
bool podTypesUnify(PodType lhs, PodType rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
bool isValidEmitEqType(Type type)
TypeClass getAtIndex(mlir::TypeRange types, size_t index)
bool isValidType(Type type)
bool arrayTypesUnify(ArrayType lhs, ArrayType rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
bool isDynamic(IntegerAttr intAttr)
bool typesUnify(Type lhs, Type rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
bool typeParamsUnify(const ArrayRef< Attribute > &lhsParams, const ArrayRef< Attribute > &rhsParams, UnificationMap *unifications)
bool isMoreConcreteUnification(Type oldTy, Type newTy, llvm::function_ref< bool(Type oldTy, Type newTy)> knownOldToNew)
bool functionTypesUnify(FunctionType lhs, FunctionType rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
LogicalResult verifyStructTypeParams(EmitErrorFn emitError, ArrayAttr params)
bool hasAffineMapAttr(Type type)
mlir::LogicalResult checkValidType(EmitErrorFn emitError, mlir::Type type)
bool isValidConstReadType(Type type)
LogicalResult verifyArrayDimSizes(EmitErrorFn emitError, ArrayRef< Attribute > dimensionSizes)
static bool isEqual(const T &lhs, const T &rhs)
static T getTombstoneKey()
static unsigned getHashValue(const T &val)