22#include <mlir-c/Support.h>
24#include <mlir/CAPI/AffineMap.h>
25#include <mlir/CAPI/Registration.h>
26#include <mlir/CAPI/Support.h>
27#include <mlir/CAPI/Wrap.h>
28#include <mlir/IR/BuiltinAttributes.h>
29#include <mlir/IR/SymbolTable.h>
31#include <llvm/ADT/STLExtras.h>
41MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Struct, llzk__component,
StructDialect)
54 llvm::cast<SymbolRefAttr>(unwrap(name)), llvm::cast<ArrayAttr>(unwrap(params))
60 MlirAttribute name, intptr_t numParams, MlirAttribute
const *params
62 SmallVector<Attribute> paramsSto;
65 llvm::cast<SymbolRefAttr>(unwrap(name)), unwrapList(numParams, params, paramsSto)
73 auto *rootOp = unwrap(root);
74 SymbolTableCollection stc;
75 mlir::FailureOr<llzk::SymbolLookupResult<StructDefOp>> lookup =
76 structType.getDefinition(stc, rootOp);
78 if (succeeded(lookup)) {
96 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getBody());
100 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType());
104 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType(llvm::cast<ArrayAttr>(unwrap(attr))));
108 for (
auto [offset, member] :
109 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getMemberDefs())) {
110 dst[offset] = wrap(member);
119 MlirOperation op, intptr_t *strSize,
char *(*alloc_string)(
size_t)
121 auto header = llvm::cast<StructDefOp>(unwrap(op)).getHeaderString();
123 char *dst = alloc_string(*strSize);
124 dst[header.size()] = 0;
125 memcpy(dst, header.data(), header.size());
130 for (
auto [offset, attr] :
131 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getTemplateParamOpNames())) {
132 dst[offset] = wrap(attr);
138 llvm::cast<StructDefOp>(unwrap(op)).getTemplateParamOpNames().size()
143 for (
auto [offset, attr] :
144 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getTemplateExprOpNames())) {
145 dst[offset] = wrap(attr);
151 llvm::cast<StructDefOp>(unwrap(op)).getTemplateExprOpNames().size()
164 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName)
171 MlirIdentifier memberName, MlirAffineMap map,
MlirValueRange mapOperands
173 SmallVector<Value> mapOperandsSto;
174 auto mapAttr = AffineMapAttr::get(unwrap(map));
177 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName), mapAttr,
178 unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto),
179 mapAttr.getAffineMap().getNumDims()
186 MlirIdentifier memberName, MlirStringRef symbol
190 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
191 FlatSymbolRefAttr::get(unwrap(builder)->getStringAttr(unwrap(symbol)))
198 MlirIdentifier memberName, int64_t distance
202 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
203 unwrap(builder)->getIndexAttr(distance)
MlirType llzkStruct_StructTypeGet(MlirAttribute name)
Creates a llzk::component::StructType.
intptr_t llzkStruct_StructDefOpGetNumMemberDefs(MlirOperation op)
Returns the number of MemberDefOp operations defined in this struct.
MlirLogicalResult llzkStructStructTypeGetDefinitionFromModule(MlirType type, MlirModule root, LlzkSymbolLookupResult *result)
Lookups the definition Operation of the given StructType using the given Module as root for the looku...
MlirType llzkStruct_StructTypeGetWithArrayAttr(MlirAttribute name, MlirAttribute params)
Creates a llzk::component::StructType with an ArrayAttr as parameters.
void llzkStruct_StructDefOpGetTemplateExprOpNames(MlirOperation op, MlirAttribute *dst)
If this struct.def is within a poly.template, add names of all poly.expr within the poly....
MlirType llzkStruct_StructTypeGetWithAttrs(MlirAttribute name, intptr_t numParams, MlirAttribute const *params)
Creates a llzk::component::StructType with an array of parameters.
MlirType llzkStruct_StructDefOpGetTypeWithParams(MlirOperation op, MlirAttribute attr)
Returns the associated StructType to this op using the given const params instead of the parameters d...
MlirLogicalResult llzkStructStructTypeGetDefinition(MlirType type, MlirOperation root, LlzkSymbolLookupResult *result)
Lookups the definition Operation of the given StructType using the given Operation as root for the lo...
void llzkStruct_StructDefOpGetMemberDefs(MlirOperation op, MlirOperation *dst)
Fills the given array with the MemberDefOp operations inside this struct.
void llzkStruct_StructDefOpGetTemplateParamOpNames(MlirOperation op, MlirAttribute *dst)
If this struct.def is within a poly.template, add names of all poly.param within the poly....
MlirBlock llzkStruct_StructDefOpGetBody(MlirOperation op)
Returns the single body Block within the StructDefOp's Region.
const char * llzkStruct_StructDefOpGetHeaderString(MlirOperation op, intptr_t *strSize, char *(*alloc_string)(size_t))
Returns the header string of the struct.
MlirType llzkStruct_StructDefOpGetType(MlirOperation op)
Returns the associated StructType to this op using the const params defined by the op.
intptr_t llzkStruct_StructDefOpGetNumTemplateParamOpNames(MlirOperation op)
Returns the number of poly.param operations defined within this template.
intptr_t llzkStruct_StructDefOpGetNumTemplateExprOpNames(MlirOperation op)
Returns the number of poly.expr operations defined within this template.
This file defines methods symbol lookup across LLZK operations and included files.
static StructType get(::mlir::SymbolRefAttr structName)
#define LLZK_DEFINE_OP_BUILD_METHOD(dialect, op,...)
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix,...)
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)
Owned result of an LLZK symbol lookup.
void * ptr
raw pointer to the result
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.