18#include <mlir/CAPI/IR.h>
19#include <mlir/CAPI/Pass.h>
20#include <mlir/CAPI/Registration.h>
21#include <mlir/CAPI/Wrap.h>
22#include <mlir/IR/Attributes.h>
23#include <mlir/IR/BuiltinAttributes.h>
26#include <mlir-c/Pass.h>
28#include <llvm/ADT/SmallVectorExtras.h>
34MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Function, llzk__function,
FunctionDialect)
36static NamedAttribute unwrap(MlirNamedAttribute attr) {
37 return NamedAttribute(unwrap(attr.name), unwrap(attr.attribute));
47 MlirLocation location, MlirStringRef name, MlirType funcType, intptr_t numAttrs,
48 MlirNamedAttribute
const *attrs, intptr_t numArgAttrs, MlirAttribute
const *argAttrs
50 SmallVector<NamedAttribute> attrsSto;
51 SmallVector<Attribute> argAttrsSto;
52 SmallVector<DictionaryAttr> unwrappedArgAttrs =
53 llvm::map_to_vector(unwrapList(numArgAttrs, argAttrs, argAttrsSto), [](
auto attr) {
54 return llvm::cast<DictionaryAttr>(attr);
58 unwrap(location), unwrap(name), llvm::cast<FunctionType>(unwrap(funcType)),
59 unwrapList(numAttrs, attrs, attrsSto), unwrappedArgAttrs
139static auto unwrapCallee(MlirOperation op) {
return llvm::cast<FuncDefOp>(unwrap(op)); }
141static auto unwrapDims(MlirAttribute attr) {
return llvm::cast<DenseI32ArrayAttr>(unwrap(attr)); }
143static auto unwrapName(MlirAttribute attr) {
return llvm::cast<SymbolRefAttr>(unwrap(attr)); }
146 CallOp, intptr_t numResults, MlirType
const *results, MlirAttribute name, intptr_t numOperands,
147 MlirValue
const *operands
149 SmallVector<Type> resultsSto;
150 SmallVector<Value> operandsSto;
153 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
154 unwrapList(numOperands, operands, operandsSto)
160 CallOp, ToCallee, MlirOperation callee, intptr_t numOperands, MlirValue
const *operands
162 SmallVector<Value> operandsSto;
165 builder, location, unwrapCallee(callee), unwrapList(numOperands, operands, operandsSto)
171 CallOp, WithMapOperands, intptr_t numResults, MlirType
const *results, MlirAttribute name,
174 SmallVector<Type> resultsSto;
175 SmallVector<Value> argOperandsSto;
181 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
182 *mapOperandsHelper, unwrapDims(numDimsPerMap),
183 unwrapList(numArgOperands, argOperands, argOperandsSto)
190 intptr_t numArgOperands, MlirValue
const *argOperands
192 SmallVector<Value> argOperandsSto;
198 builder, location, unwrapCallee(callee), *mapOperandsHelper, unwrapDims(numDimsPerMap),
199 unwrapList(numArgOperands, argOperands, argOperandsSto)
bool llzkFuncDefOpGetHasAllowWitnessAttr(MlirOperation op)
MlirType llzkFuncDefOpGetSingleResultTypeOfCompute(MlirOperation op)
Assuming the function is the compute function returns its StructType result.
MlirType llzkCallOpGetCalleeType(MlirOperation op)
Returns the FunctionType of the callee.
MlirOperation llzkFuncDefOpCreateWithAttrsAndArgAttrs(MlirLocation location, MlirStringRef name, MlirType funcType, intptr_t numAttrs, MlirNamedAttribute const *attrs, intptr_t numArgAttrs, MlirAttribute const *argAttrs)
Creates a FuncDefOp with the given attributes and argument attributes.
bool llzkFuncDefOpGetNameIsConstrain(MlirOperation op)
bool llzkFuncDefOpGetHasAllowNonNativeFieldOpsAttr(MlirOperation op)
bool llzkCallOpGetCalleeIsStructConstrain(MlirOperation op)
bool llzkFuncDefOpGetIsInStruct(MlirOperation op)
MlirValue llzkFuncDefOpGetSelfValueFromCompute(MlirOperation op)
Return the "self" value (i.e.
bool llzkFuncDefOpGetHasArgIsPub(MlirOperation op, unsigned argNo)
bool llzkFuncDefOpGetIsStructCompute(MlirOperation op)
MlirValue llzkFuncDefOpGetSelfValueFromConstrain(MlirOperation op)
Return the "self" value (i.e.
bool llzkCallOpGetCalleeIsConstrain(MlirOperation op)
MlirValue llzkCallOpGetSelfValueFromCompute(MlirOperation op)
Return the "self" value (i.e.
void llzkFuncDefOpSetAllowConstraintAttr(MlirOperation op, bool value)
Sets the allow_constraint attribute in the FuncDefOp operation.
bool llzkCallOpGetCalleeIsStructCompute(MlirOperation op)
MlirType llzkCallOpGetSingleResultTypeOfCompute(MlirOperation op)
Assuming the callee is the compute function, returns its StructType result.
bool llzkFuncDefOpGetIsStructConstrain(MlirOperation op)
bool llzkOperationIsAFuncDefOp(MlirOperation op)
void llzkFuncDefOpSetAllowNonNativeFieldOpsAttr(MlirOperation op, bool value)
Sets the allow_non_native_field_ops attribute in the FuncDefOp operation.
MlirValue llzkCallOpGetSelfValueFromConstrain(MlirOperation op)
Return the "self" value (i.e.
bool llzkCallOpGetCalleeIsCompute(MlirOperation op)
bool llzkOperationIsACallOp(MlirOperation op)
bool llzkFuncDefOpGetNameIsCompute(MlirOperation op)
bool llzkFuncDefOpGetHasAllowConstraintAttr(MlirOperation op)
MlirAttribute llzkFuncDefOpGetFullyQualifiedName(MlirOperation op)
Returns the fully qualified name of the function.
void llzkFuncDefOpSetAllowWitnessAttr(MlirOperation op, bool value)
Sets the allow_witness attribute in the FuncDefOp operation.
MlirAttribute llzkAffineMapOperandsBuilderGetDimsPerMapAttr(LlzkAffineMapOperandsBuilder builder, MlirContext context)
Returns the number of dimensions per map represented as an attribute.
Helper for unwrapping the C arguments for the map operands.
static FuncDefOp create(::mlir::Location location, ::llvm::StringRef name, ::mlir::FunctionType type, ::llvm::ArrayRef<::mlir::NamedAttribute > attrs={})
#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)
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
MlirValueRange * mapOperands