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 {
41 llvm::raw_string_ostream ss;
43 BuildShortTypeString() : ret(), ss(ret) {}
44 BuildShortTypeString &append(mlir::Type);
45 BuildShortTypeString &append(mlir::ArrayRef<mlir::Attribute>);
46 BuildShortTypeString &append(mlir::Attribute);
48 void appendSymRef(mlir::SymbolRefAttr);
49 void appendSymName(mlir::StringRef);
53 static inline std::string
from(mlir::Type type) {
54 return BuildShortTypeString().append(type).ret;
58 static inline std::string
from(mlir::Attribute attr) {
59 return BuildShortTypeString().append(attr).ret;
64 static inline std::string
from(mlir::ArrayRef<mlir::Attribute> attrs) {
65 return BuildShortTypeString().append(attrs).ret;
83 mlir::Type type, mlir::SymbolTableCollection &symbolTable, mlir::Operation *op
139 return emitError() <<
"expected a valid LLZK type but found " << type;
141 return mlir::success();
149static inline mlir::raw_ostream &
operator<<(mlir::raw_ostream &os,
const Side &val) {
181template <>
struct DenseMapInfo<
llzk::Side> {
186 using UT = std::underlying_type_t<T>;
187 return llvm::DenseMapInfo<UT>::getHashValue(
static_cast<UT
>(val));
189 static bool isEqual(
const T &lhs,
const T &rhs) {
return lhs == rhs; }
217using UnificationMap = mlir::DenseMap<std::pair<mlir::SymbolRefAttr, Side>, mlir::Attribute>;
222 const mlir::ArrayRef<mlir::Attribute> &lhsParams,
223 const mlir::ArrayRef<mlir::Attribute> &rhsParams,
UnificationMap *unifications =
nullptr
229 const mlir::ArrayAttr &lhsParams,
const mlir::ArrayAttr &rhsParams,
237 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
244 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
257 mlir::FunctionType lhs, mlir::FunctionType rhs,
258 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
264 mlir::Type lhs, mlir::Type rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
270template <
typename Iter1,
typename Iter2>
272 Iter1 lhs, Iter2 rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
275 return (lhs.size() == rhs.size()) &&
276 std::equal(lhs.begin(), lhs.end(), rhs.begin(), [&](mlir::Type a, mlir::Type b) {
277 return typesUnify(a, b, rhsReversePrefix, unifications);
281template <
typename Iter1,
typename Iter2>
283 Iter1 lhs, Iter2 rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
286 return lhs.size() == 1 && rhs.size() == 1 &&
287 typesUnify(lhs.front(), rhs.front(), rhsReversePrefix, unifications);
298 mlir::Type oldTy, mlir::Type newTy,
299 llvm::function_ref<
bool(mlir::Type oldTy, mlir::Type newTy)> knownOldToNew =
nullptr
302template <
typename TypeClass>
inline TypeClass
getIfSingleton(mlir::TypeRange types) {
303 return (types.size() == 1) ? llvm::dyn_cast<TypeClass>(types.front()) :
nullptr;
306template <
typename TypeClass>
inline TypeClass
getAtIndex(mlir::TypeRange types,
size_t index) {
307 return (types.size() > index) ? llvm::dyn_cast<TypeClass>(types[index]) :
nullptr;
317mlir::FailureOr<llvm::SmallVector<mlir::Attribute>>
335 EmitErrorFn emitError, mlir::Type elementType, mlir::ArrayRef<mlir::Attribute> dimensionSizes
static std::string from(mlir::Attribute attr)
Return a brief string representation of one LLZK type parameter attribute.
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(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)
AttrConcreteness
Concreteness classification for an argument to a parameterized struct type.
FailureOr< IntegerAttr > forceIntType(IntegerAttr attr, EmitErrorFn emitError)
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)
AttrConcreteness classifyAttrConcreteness(Attribute attr, bool allowStructParams)
Interval operator<<(const Interval &lhs, const Interval &rhs)
bool podTypesUnify(PodType lhs, PodType rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
ArrayType flattenArrayElementType(ArrayType outerArrTy, Type elementType)
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 isTypeVarFreeType(Type type)
bool typesUnify(Type lhs, Type rhs, ArrayRef< StringRef > rhsReversePrefix, UnificationMap *unifications)
bool typeParamsUnify(const ArrayRef< Attribute > &lhsParams, const ArrayRef< Attribute > &rhsParams, UnificationMap *unifications)
bool isConcreteStructParamAttr(mlir::Attribute attr, bool allowStructParams=true)
Return true if attr is a concrete argument for a parameterized struct type.
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)