21#include <mlir/CAPI/AffineMap.h>
22#include <mlir/CAPI/Registration.h>
23#include <mlir/CAPI/Support.h>
24#include <mlir/CAPI/Wrap.h>
25#include <mlir/IR/BuiltinAttributes.h>
26#include <mlir/IR/SymbolTable.h>
28#include <mlir-c/Support.h>
30#include <llvm/ADT/STLExtras.h>
36MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Struct, llzk__component,
StructDialect)
49 llvm::cast<SymbolRefAttr>(unwrap(name)), llvm::cast<ArrayAttr>(unwrap(params))
56 SmallVector<Attribute> paramsSto;
59 llvm::cast<SymbolRefAttr>(unwrap(name)), unwrapList(numParams, params, paramsSto)
67 return wrap(llvm::cast<StructType>(unwrap(type)).getNameRef());
71 return wrap(llvm::cast<StructType>(unwrap(type)).getParams());
78 auto *rootOp = unwrap(root);
79 SymbolTableCollection stc;
80 mlir::FailureOr<llzk::SymbolLookupResult<StructDefOp>> lookup =
81 structType.getDefinition(stc, rootOp);
83 if (succeeded(lookup)) {
103 return wrap(&llvm::cast<StructDefOp>(unwrap(op)).getBodyRegion());
107 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getBody());
111 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType());
115 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType(llvm::cast<ArrayAttr>(unwrap(attr))));
119 Builder builder(unwrap(op)->getContext());
121 llvm::cast<StructDefOp>(unwrap(op)).getMemberDef(builder.getStringAttr(unwrap(name)))
126 for (
auto [offset, member] :
127 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getMemberDefs())) {
128 dst[offset] = wrap(member);
133 return static_cast<intptr_t
>(llvm::cast<StructDefOp>(unwrap(op)).getMemberDefs().size());
137 return wrap(llvm::cast<StructDefOp>(unwrap(op)).hasColumns());
141 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getComputeFuncOp());
145 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getConstrainFuncOp());
150 auto header = llvm::cast<StructDefOp>(unwrap(op)).getHeaderString();
151 *strSize =
static_cast<intptr_t
>(header.size()) + 1;
152 char *dst = alloc_string(*strSize);
153 dst[header.size()] = 0;
154 memcpy(dst, header.data(), header.size());
159 Builder builder(unwrap(op)->getContext());
160 return llvm::cast<StructDefOp>(unwrap(op)).hasParamNamed(builder.getStringAttr(unwrap(name)));
164 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getFullyQualifiedName());
168 return llvm::cast<StructDefOp>(unwrap(op)).isMainComponent();
178 return llvm::cast<MemberDefOp>(unwrap(op)).hasPublicAttr();
182 llvm::cast<MemberDefOp>(unwrap(op)).setPublicAttr(value);
194 builder, location, unwrap(memberType), unwrap(
component),
195 unwrap(builder)->getStringAttr(unwrap(name))
204 SmallVector<Value> mapOperandsSto;
205 auto nameAttr = unwrap(builder)->getStringAttr(unwrap(name));
206 auto mapAttr = AffineMapAttr::get(unwrap(map));
209 builder, location, unwrap(memberType), unwrap(
component), nameAttr, mapAttr,
210 unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto),
211 mapAttr.getAffineMap().getNumDims()
218 MlirStringRef name, MlirStringRef symbol
220 auto nameAttr = unwrap(builder)->getStringAttr(unwrap(name));
223 builder, location, unwrap(memberType), unwrap(
component), nameAttr,
224 FlatSymbolRefAttr::get(unwrap(builder)->getStringAttr(unwrap(symbol)))
233 auto nameAttr = unwrap(builder)->getStringAttr(unwrap(name));
236 builder, location, unwrap(memberType), unwrap(
component), nameAttr,
237 unwrap(builder)->getIndexAttr(distance)
const char * llzkStructDefOpGetHeaderString(MlirOperation op, intptr_t *strSize, char *(*alloc_string)(size_t))
Returns the header string of the struct.
MlirAttribute llzkStructDefOpGetFullyQualifiedName(MlirOperation op)
Returns a StringAttr with the fully qualified name of the struct.
MlirType llzkStructDefOpGetTypeWithParams(MlirOperation op, MlirAttribute attr)
Returns the associated StructType to this op using the given const params instead of the parameters d...
bool llzkStructDefOpGetHasParamName(MlirOperation op, MlirStringRef name)
intptr_t llzkStructDefOpGetNumMemberDefs(MlirOperation op)
Returns the number of MemberDefOp operations defined in this struct.
MlirType llzkStructTypeGetWithAttrs(MlirAttribute name, intptr_t numParams, MlirAttribute const *params)
Creates a llzk::component::StructType with an array of parameters.
MlirAttribute llzkStructTypeGetParams(MlirType type)
Returns the parameter of a llzk::component::StructType as an ArrayAttr.
MlirType llzkStructTypeGetWithArrayAttr(MlirAttribute name, MlirAttribute params)
Creates a llzk::component::StructType with an ArrayAttr as parameters.
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...
void llzkMemberDefOpSetPublicAttr(MlirOperation op, bool value)
Sets the public attribute in the given member.
bool llzkStructDefOpGetIsMainComponent(MlirOperation op)
MlirOperation llzkStructDefOpGetMemberDef(MlirOperation op, MlirStringRef name)
Returns the operation that defines the member with the given name, if present.
bool llzkTypeIsAStructType(MlirType type)
MlirOperation llzkStructDefOpGetComputeFuncOp(MlirOperation op)
Returns the FuncDefOp operation that defines the witness computation of the struct.
void llzkStructDefOpGetMemberDefs(MlirOperation op, MlirOperation *dst)
Fills the given array with the MemberDefOp operations inside this struct.
bool llzkOperationIsAMemberDefOp(MlirOperation op)
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...
MlirBlock llzkStructDefOpGetBody(MlirOperation op)
Returns the single body Block within the StructDefOp's Region.
MlirRegion llzkStructDefOpGetBodyRegion(MlirOperation op)
Returns the single body Region of the StructDefOp.
bool llzkMemberDefOpGetHasPublicAttr(MlirOperation op)
MlirAttribute llzkStructTypeGetName(MlirType type)
Returns the fully qualified name of a llzk::component::StructType.
bool llzkOperationIsAStructDefOp(MlirOperation op)
MlirType llzkStructTypeGet(MlirAttribute name)
Creates a llzk::component::StructType.
MlirOperation llzkStructDefOpGetConstrainFuncOp(MlirOperation op)
Returns the FuncDefOp operation that defines the constraints of the struct.
MlirLogicalResult llzkStructDefOpGetHasColumns(MlirOperation op)
Returns true if the struct has members marked as columns.
MlirType llzkStructDefOpGetType(MlirOperation op)
Returns the associated StructType to this op using the const params defined by the op.
This file defines methods symbol lookup across LLZK operations and included files.
static StructType get(::mlir::SymbolRefAttr structName)
#define LLZK_DEFINE_OP_BUILD_METHOD(op,...)
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(op, suffix,...)
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
auto unwrap_cast(auto &from)