23#include <mlir-c/BuiltinAttributes.h>
24#include <mlir-c/Pass.h>
25#include <mlir-c/Support.h>
27#include <mlir/CAPI/AffineMap.h>
28#include <mlir/CAPI/Pass.h>
29#include <mlir/CAPI/Registration.h>
30#include <mlir/CAPI/Support.h>
31#include <mlir/CAPI/Wrap.h>
32#include <mlir/IR/BuiltinAttributes.h>
33#include <mlir/IR/SymbolTable.h>
35#include <llvm/ADT/STLExtras.h>
48MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Struct, llzk__component,
StructDialect)
61 llvm::cast<SymbolRefAttr>(unwrap(name)), llvm::cast<ArrayAttr>(unwrap(params))
67 MlirAttribute name, intptr_t numParams, MlirAttribute
const *params
69 SmallVector<Attribute> paramsSto;
72 llvm::cast<SymbolRefAttr>(unwrap(name)), unwrapList(numParams, params, paramsSto)
80 auto *rootOp = unwrap(root);
81 SymbolTableCollection stc;
82 mlir::FailureOr<llzk::SymbolLookupResult<StructDefOp>> lookup =
83 structType.getDefinition(stc, rootOp);
85 if (succeeded(lookup)) {
103 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getBody());
107 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType());
111 return wrap(llvm::cast<StructDefOp>(unwrap(op)).getType(llvm::cast<ArrayAttr>(unwrap(attr))));
115 for (
auto [offset, member] :
116 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getMemberDefs())) {
117 dst[offset] = wrap(member);
126 MlirOperation op, intptr_t *strSize,
char *(*alloc_string)(
size_t)
128 auto header = llvm::cast<StructDefOp>(unwrap(op)).getHeaderString();
130 char *dst = alloc_string(*strSize);
131 dst[header.size()] = 0;
132 memcpy(dst, header.data(), header.size());
137 for (
auto [offset, attr] :
138 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getTemplateParamOpNames())) {
139 dst[offset] = wrap(attr);
145 llvm::cast<StructDefOp>(unwrap(op)).getTemplateParamOpNames().size()
150 for (
auto [offset, attr] :
151 llvm::enumerate(llvm::cast<StructDefOp>(unwrap(op)).getTemplateExprOpNames())) {
152 dst[offset] = wrap(attr);
158 llvm::cast<StructDefOp>(unwrap(op)).getTemplateExprOpNames().size()
167 Struct,
MemberDefOp, MlirStringRef name, MlirType type,
bool isSignal,
bool isColumn
171 wrap(
create<MemberDefOp>(builder, location, unwrap(name), unwrap(type), isSignal, isColumn))
176 Struct,
MemberDefOp, WithAttrs, MlirAttribute name, MlirAttribute type,
bool isSignal,
182 builder, location, llvm::cast<StringAttr>(unwrap(name)),
183 llvm::cast<TypeAttr>(unwrap(type)), isSignal, isColumn
190 Struct,
MemberDefOp, WithNamedAttrs, intptr_t numAttrs, MlirNamedAttribute
const *attrs,
191 bool isSignal,
bool isColumn
193 SmallVector<NamedAttribute> attrsSto;
197 builder, location, unwrapList(numAttrs, attrs, attrsSto), isSignal, isColumn
204 return llvm::cast<MemberDefOp>(unwrap(op)).getColumn();
208 llvm::cast<MemberDefOp>(unwrap(op)).setColumn(newValue);
212 return llvm::cast<MemberDefOp>(unwrap(op)).getSignal();
216 llvm::cast<MemberDefOp>(unwrap(op)).setSignal(newValue);
229 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName)
237 MlirIdentifier memberName, MlirAffineMap map,
MlirValueRange mapOperands
239 SmallVector<Value> mapOperandsSto;
240 auto mapAttr = AffineMapAttr::get(unwrap(map));
244 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
245 mapAttr, unwrapList(mapOperands.
size, mapOperands.
values, mapOperandsSto),
246 mapAttr.getAffineMap().getNumDims()
254 MlirIdentifier memberName, MlirStringRef symbol
259 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
260 FlatSymbolRefAttr::get(unwrap(builder)->getStringAttr(unwrap(symbol)))
268 MlirIdentifier memberName, int64_t distance
273 builder, location, unwrap(memberType), unwrap(
component), unwrap(memberName),
274 unwrap(builder)->getIndexAttr(distance)
MlirOperation mlirOpBuilderInsert(MlirOpBuilder builder, MlirOperation op)
Inserts op at the current insertion point of builder and returns it.
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.
void llzkStruct_MemberDefOpSetSignalValue(MlirOperation op, bool newValue)
Adds or removes the unit signal attribute according to newValue.
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.
bool llzkStruct_MemberDefOpGetColumnValue(MlirOperation op)
Returns whether this member supports offset table accesses.
void llzkStruct_MemberDefOpSetColumnValue(MlirOperation op, bool newValue)
Adds or removes the unit column attribute according to newValue.
intptr_t llzkStruct_StructDefOpGetNumTemplateExprOpNames(MlirOperation op)
Returns the number of poly.expr operations defined within this template.
bool llzkStruct_MemberDefOpGetSignalValue(MlirOperation op)
Returns whether this member is stored as a witness signal.
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,...)
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)
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.