22#include <mlir-c/BuiltinAttributes.h>
23#include <mlir-c/Support.h>
25#include <mlir/CAPI/AffineMap.h>
26#include <mlir/CAPI/Registration.h>
27#include <mlir/CAPI/Support.h>
28#include <mlir/CAPI/Wrap.h>
29#include <mlir/IR/BuiltinAttributes.h>
30#include <mlir/IR/SymbolTable.h>
32#include <llvm/ADT/STLExtras.h>
42MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Struct, llzk__component,
StructDialect)
55 llvm::cast<SymbolRefAttr>(unwrap(name)), llvm::cast<ArrayAttr>(unwrap(params))
61 MlirAttribute name, intptr_t numParams, MlirAttribute
const *params
63 SmallVector<Attribute> paramsSto;
66 llvm::cast<SymbolRefAttr>(unwrap(name)), unwrapList(numParams, params, paramsSto)
74 auto *rootOp = unwrap(root);
75 SymbolTableCollection stc;
76 mlir::FailureOr<llzk::SymbolLookupResult<StructDefOp>> lookup =
77 structType.getDefinition(stc, rootOp);
79 if (succeeded(lookup)) {
97 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getBody());
101 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType());
105 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType(llvm::cast<ArrayAttr>(unwrap(attr))));
109 for (
auto [offset, member] :
110 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getMemberDefs())) {
111 dst[offset] = wrap(member);
120 MlirOperation op, intptr_t *strSize,
char *(*alloc_string)(
size_t)
122 auto header = llvm::cast<StructDefOp>(unwrap(op)).getHeaderString();
124 char *dst = alloc_string(*strSize);
125 dst[header.size()] = 0;
126 memcpy(dst, header.data(), header.size());
131 for (
auto [offset, attr] :
132 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getTemplateParamOpNames())) {
133 dst[offset] = wrap(attr);
139 llvm::cast<StructDefOp>(unwrap(op)).getTemplateParamOpNames().size()
144 for (
auto [offset, attr] :
145 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getTemplateExprOpNames())) {
146 dst[offset] = wrap(attr);
152 llvm::cast<StructDefOp>(unwrap(op)).getTemplateExprOpNames().size()
165 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName)
172 MlirIdentifier memberName, MlirAffineMap map,
MlirValueRange mapOperands
174 SmallVector<Value> mapOperandsSto;
175 auto mapAttr = AffineMapAttr::get(unwrap(map));
178 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName), mapAttr,
179 unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto),
180 mapAttr.getAffineMap().getNumDims()
187 MlirIdentifier memberName, MlirStringRef symbol
191 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
192 FlatSymbolRefAttr::get(unwrap(builder)->getStringAttr(unwrap(symbol)))
199 MlirIdentifier memberName, int64_t distance
203 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
204 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.