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>
36class BuildShortTypeString {
37 static constexpr char PLACEHOLDER =
'\x1A';
40 llvm::raw_string_ostream ss;
42 BuildShortTypeString() : ret(), ss(ret) {}
43 BuildShortTypeString &append(mlir::Type);
44 BuildShortTypeString &append(mlir::ArrayRef<mlir::Attribute>);
45 BuildShortTypeString &append(mlir::Attribute);
47 void appendSymRef(mlir::SymbolRefAttr);
48 void appendSymName(mlir::StringRef);
52 static inline std::string
from(mlir::Type type) {
53 return BuildShortTypeString().append(type).ret;
58 static inline std::string
from(mlir::ArrayRef<mlir::Attribute> attrs) {
59 return BuildShortTypeString().append(attrs).ret;
69 static std::string
from(
const std::string &base, mlir::ArrayRef<mlir::Attribute> attrs);
86 mlir::Type type, mlir::SymbolTableCollection &symbolTable, mlir::Operation *op
109 return emitError() <<
"expected a valid LLZK type but found " << type;
111 return mlir::success();
125static inline mlir::raw_ostream &
operator<<(mlir::raw_ostream &os,
const Side &val) {
157template <>
struct DenseMapInfo<
llzk::Side> {
162 using UT = std::underlying_type_t<T>;
163 return llvm::DenseMapInfo<UT>::getHashValue(
static_cast<UT
>(val));
165 static bool isEqual(
const T &lhs,
const T &rhs) {
return lhs == rhs; }
181using UnificationMap = mlir::DenseMap<std::pair<mlir::SymbolRefAttr, Side>, mlir::Attribute>;
186 const mlir::ArrayRef<mlir::Attribute> &lhsParams,
187 const mlir::ArrayRef<mlir::Attribute> &rhsParams,
UnificationMap *unifications =
nullptr
193 const mlir::ArrayAttr &lhsParams,
const mlir::ArrayAttr &rhsParams,
201 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
208 mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
UnificationMap *unifications = nullptr
214 mlir::Type lhs, mlir::Type rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
220template <
typename Iter1,
typename Iter2>
222 Iter1 lhs, Iter2 rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
225 return (lhs.size() == rhs.size()) &&
226 std::equal(lhs.begin(), lhs.end(), rhs.begin(), [&](mlir::Type a, mlir::Type b) {
227 return typesUnify(a, b, rhsReversePrefix, unifications);
231template <
typename Iter1,
typename Iter2>
233 Iter1 lhs, Iter2 rhs, mlir::ArrayRef<llvm::StringRef> rhsReversePrefix = {},
236 return lhs.size() == 1 && rhs.size() == 1 &&
237 typesUnify(lhs.front(), rhs.front(), rhsReversePrefix, unifications);
247 mlir::Type oldTy, mlir::Type newTy,
248 llvm::function_ref<
bool(mlir::Type oldTy, mlir::Type newTy)> knownOldToNew =
nullptr
251template <
typename TypeClass>
inline TypeClass
getIfSingleton(mlir::TypeRange types) {
252 return (types.size() == 1) ? llvm::dyn_cast<TypeClass>(types.front()) :
nullptr;
255template <
typename TypeClass>
inline TypeClass
getAtIndex(mlir::TypeRange types,
size_t index) {
256 return (types.size() > index) ? llvm::dyn_cast<TypeClass>(types[index]) :
nullptr;
283 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)
mlir::raw_ostream & operator<<(mlir::raw_ostream &os, const ConstrainRef &rhs)
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)
llvm::function_ref< mlir::InFlightDiagnostic()> EmitErrorFn
TypeClass getIfSingleton(mlir::TypeRange types)
bool isValidGlobalType(Type type)
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)
SmallVector< Attribute > forceIntAttrTypes(ArrayRef< Attribute > attrList)
LogicalResult verifyArrayType(EmitErrorFn emitError, Type elementType, ArrayRef< Attribute > dimensionSizes)
bool isValidColumnType(Type type, SymbolTableCollection &symbolTable, Operation *op)
mlir::DenseMap< std::pair< mlir::SymbolRefAttr, Side >, mlir::Attribute > UnificationMap
Optional result from type 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 isSignalType(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 isMoreConcreteUnification(Type oldTy, Type newTy, llvm::function_ref< bool(Type oldTy, Type newTy)> knownOldToNew)
LogicalResult verifyStructTypeParams(EmitErrorFn emitError, ArrayAttr params)
Attribute forceIntAttrType(Attribute attr)
IntegerAttr forceIntType(IntegerAttr attr)
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)