20#include <mlir-c/Pass.h>
22#include <mlir/CAPI/AffineExpr.h>
23#include <mlir/CAPI/AffineMap.h>
24#include <mlir/CAPI/Pass.h>
25#include <mlir/CAPI/Registration.h>
26#include <mlir/CAPI/Wrap.h>
27#include <mlir/IR/BuiltinAttributes.h>
28#include <mlir/Support/LLVM.h>
41MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Polymorphic, llzk__polymorphic,
PolymorphicDialect)
48 return wrap(
TypeVarType::get(FlatSymbolRefAttr::get(StringAttr::get(unwrap(ctx), unwrap(name)))));
52 auto attr = unwrap(attrWrapper);
53 if (
auto sym = llvm::dyn_cast<FlatSymbolRefAttr>(attr)) {
56 return wrap(
TypeVarType::get(FlatSymbolRefAttr::get(llvm::cast<StringAttr>(attr))));
65static inline void copyAttrs(SmallVector<Attribute> attrs, MlirAttribute *dst) {
66 for (
auto [n, attr] : llvm::enumerate(attrs)) {
82 copyAttrs(asTemplateOp(op).getConstNames<TemplateParamOp>(), dst);
98 copyAttrs(asTemplateOp(op).getConstNames<TemplateExprOp>(), dst);
102 return asTemplateOp(op).hasConstNamed<
TemplateExprOp>(unwrap(find));
110 SmallVector<Value> mapOperandsSto;
113 builder, location, llvm::cast<AffineMapAttr>(unwrap(map)),
114 ValueRange(unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto))
122 SmallVector<Value> mapOperandsSto;
125 builder, location, unwrap(map),
126 ValueRange(unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto))
134 SmallVector<Value> mapOperandsSto;
137 builder, location, unwrap(expr),
138 ValueRange(unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto))
143static inline ValueRange dimOperands(MlirOperation op) {
147static inline ValueRange symbolOperands(MlirOperation op) {
151static inline void copyValues(ValueRange in, MlirValue *out) {
152 for (
auto [n, value] : llvm::enumerate(in)) {
153 out[n] = wrap(value);
166 copyValues(dimOperands(op), dst);
178 copyValues(symbolOperands(op), dst);
void llzkPoly_ApplyMapOpGetSymbolOperands(MlirOperation op, MlirValue *dst)
Writes into the destination buffer the operands that correspond to symbols in the affine map.
void llzkPoly_TemplateOpGetConstExprNames(MlirOperation op, MlirAttribute *dst)
Writes into the destination buffer the names of all TemplateExprOp children as FlatSymbolRefAttr attr...
intptr_t llzkPoly_TemplateOpNumConstExprOps(MlirOperation op)
Returns the number of TemplateExprOp children in the TemplateOp.
void llzkPoly_TemplateOpGetConstParamNames(MlirOperation op, MlirAttribute *dst)
Writes into the destination buffer the names of all TemplateParamOp children as FlatSymbolRefAttr att...
bool llzkPoly_TemplateOpHasConstExprOps(MlirOperation op)
Returns true if the TemplateOp has any TemplateExprOp children.
bool llzkPoly_TemplateOpHasConstExprNamed(MlirOperation op, MlirStringRef find)
Returns true if the TemplateOp has a TemplateExprOp with the given name.
MlirBlock llzkPoly_TemplateOpGetBody(MlirOperation op)
Returns the single body Block within the TemplateOp's Region.
bool llzkPoly_TemplateOpHasConstParamNamed(MlirOperation op, MlirStringRef find)
Returns true if the TemplateOp has a TemplateParamOp with the given name.
intptr_t llzkPoly_ApplyMapOpGetNumSymbolOperands(MlirOperation op)
Returns the number of operands that correspond to symbols in the affine map.
void llzkPoly_ApplyMapOpGetDimOperands(MlirOperation op, MlirValue *dst)
Writes into the destination buffer the operands that correspond to dimensions in the affine map.
bool llzkPoly_TemplateOpHasConstParamOps(MlirOperation op)
Returns true if the TemplateOp has any TemplateParamOp children.
MlirType llzkPoly_TypeVarTypeGetFromAttr(MlirAttribute attrWrapper)
Creates a llzk::polymorphic::TypeVarType from either a StringAttr or a FlatSymbolRefAttr.
MlirType llzkPoly_TypeVarTypeGetFromStringRef(MlirContext ctx, MlirStringRef name)
Creates a llzk::polymorphic::TypeVarType.
intptr_t llzkPoly_ApplyMapOpGetNumDimOperands(MlirOperation op)
Returns the number of operands that correspond to dimensions in the affine map.
intptr_t llzkPoly_TemplateOpNumConstParamOps(MlirOperation op)
Returns the number of TemplateParamOp children in the TemplateOp.
static TypeVarType get(::mlir::MLIRContext *context, ::mlir::FlatSymbolRefAttr nameRef)
#define LLZK_DEFINE_OP_BUILD_METHOD(dialect, op,...)
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix,...)
void registerTransformationPasses()
constexpr T checkedCast(U u) noexcept
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
auto unwrap_cast(auto &from)
Representation of an mlir::ValueRange
MlirValue const * values
Pointer to the first value in the range.
intptr_t size
Number of values in the range.