19#include <mlir-c/BuiltinAttributes.h>
21#include <mlir-c/Pass.h>
23#include <mlir/CAPI/IR.h>
24#include <mlir/CAPI/Pass.h>
25#include <mlir/CAPI/Registration.h>
26#include <mlir/CAPI/Wrap.h>
27#include <mlir/IR/Attributes.h>
28#include <mlir/IR/BuiltinAttributes.h>
30#include <llvm/ADT/SmallVectorExtras.h>
40MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Function, llzk__function,
FunctionDialect)
47 Function,
FuncDefOp, WithAttrsAndArgAttrs, MlirStringRef name, MlirType funcType,
48 intptr_t numAttrs, MlirNamedAttribute const *attrs, intptr_t numArgAttrs,
49 MlirAttribute const *argAttrs
51 SmallVector<NamedAttribute> attrsSto;
52 SmallVector<Attribute> argAttrsSto;
53 SmallVector<DictionaryAttr> unwrappedArgAttrs =
54 llvm::map_to_vector(unwrapList(numArgAttrs, argAttrs, argAttrsSto), [](
auto attr) {
55 return llvm::cast<DictionaryAttr>(attr);
60 builder, location, unwrap(name), llvm::cast<FunctionType>(unwrap(funcType)),
61 unwrapList(numAttrs, attrs, attrsSto), unwrappedArgAttrs
68 Function,
FuncDefOp, WithAttrs, MlirStringRef name, MlirType funcType, intptr_t numAttrs,
69 MlirNamedAttribute
const *attrs
71 return llzkFunction_FuncDefOpBuildWithAttrsAndArgAttrs(
72 builder, location, name, funcType, numAttrs, attrs, 0, NULL
77 Function,
FuncDefOp, WithArgAttrs, MlirStringRef name, MlirType funcType, intptr_t numArgAttrs,
78 MlirAttribute
const *argAttrs
80 return llzkFunction_FuncDefOpBuildWithAttrsAndArgAttrs(
81 builder, location, name, funcType, 0, NULL, numArgAttrs, argAttrs
86 Function,
FuncDefOp, WithoutAttrs, MlirStringRef name, MlirType funcType
88 return llzkFunction_FuncDefOpBuildWithAttrs(
89 builder, location, name, funcType, 0, NULL
94 std::optional<StringAttr> argNameAttr = llvm::cast<FuncDefOp>(unwrap(op)).getArgNameAttr(index);
95 return wrap(argNameAttr ? Attribute(*argNameAttr) : Attribute());
99 llvm::cast<FuncDefOp>(unwrap(op)).setArgNameAttr(index, llvm::cast<StringAttr>(unwrap(attr)));
103 llvm::cast<FuncDefOp>(unwrap(op)).setArgName(index, unwrap(name));
107 std::optional<StringAttr> resNameAttr = llvm::cast<FuncDefOp>(unwrap(op)).getResNameAttr(index);
108 return wrap(resNameAttr ? Attribute(*resNameAttr) : Attribute());
112 llvm::cast<FuncDefOp>(unwrap(op)).setResNameAttr(index, llvm::cast<StringAttr>(unwrap(attr)));
116 llvm::cast<FuncDefOp>(unwrap(op)).setResName(index, unwrap(name));
123static auto unwrapCallee(MlirOperation op) {
return llvm::cast<FuncDefOp>(unwrap(op)); }
125static auto unwrapDims(MlirAttribute attr) {
return llvm::cast<DenseI32ArrayAttr>(unwrap(attr)); }
127static auto unwrapName(MlirAttribute attr) {
return llvm::cast<SymbolRefAttr>(unwrap(attr)); }
130 Function,
CallOp, intptr_t numResults, MlirType
const *results, MlirAttribute name,
131 intptr_t numOperands, MlirValue
const *operands
133 SmallVector<Type> resultsSto;
134 SmallVector<Value> operandsSto;
138 builder, location, unwrapList(numResults, results, resultsSto),
139 unwrapName(name), unwrapList(numOperands, operands, operandsSto)
146 Function,
CallOp, ToCallee, MlirOperation callee, intptr_t numOperands,
147 MlirValue
const *operands
149 SmallVector<Value> operandsSto;
153 builder, location, unwrapCallee(callee),
154 unwrapList(numOperands, operands, operandsSto)
161 Function,
CallOp, WithMapOperands, intptr_t numResults, MlirType
const *results,
163 MlirValue
const *argOperands
165 SmallVector<Type> resultsSto;
166 SmallVector<Value> argOperandsSto;
173 builder, location, unwrapList(numResults, results, resultsSto),
174 unwrapName(name), *mapOperandsHelper, unwrapDims(numDimsPerMap),
175 unwrapList(numArgOperands, argOperands, argOperandsSto)
182 Function,
CallOp, ToCalleeWithMapOperands, MlirOperation callee,
185 SmallVector<Value> argOperandsSto;
193 builder, location, unwrapCallee(callee), *mapOperandsHelper,
194 unwrapDims(numDimsPerMap), unwrapList(numArgOperands, argOperands, argOperandsSto)
201 Function,
CallOp, WithTemplateParams, intptr_t numResults, MlirType
const *results,
202 MlirAttribute name, intptr_t numTemplateParams, MlirAttribute
const *templateParams,
203 intptr_t numArgOperands, MlirValue
const *argOperands
205 SmallVector<Type> resultsSto;
206 SmallVector<Value> argOperandsSto;
207 SmallVector<Attribute> templateParamsSto;
211 builder, location, unwrapList(numResults, results, resultsSto),
212 unwrapName(name), unwrapList(numArgOperands, argOperands, argOperandsSto),
213 unwrapList(numTemplateParams, templateParams, templateParamsSto)
220 Function,
CallOp, ToCalleeWithTemplateParams, MlirOperation callee, intptr_t numTemplateParams,
221 MlirAttribute
const *templateParams, intptr_t numArgOperands, MlirValue
const *argOperands
223 SmallVector<Value> argOperandsSto;
224 SmallVector<Attribute> templateParamsSto;
228 builder, location, unwrapCallee(callee),
229 unwrapList(numArgOperands, argOperands, argOperandsSto),
230 unwrapList(numTemplateParams, templateParams, templateParamsSto)
MlirOperation mlirOpBuilderInsert(MlirOpBuilder builder, MlirOperation op)
Inserts op at the current insertion point of builder and returns it.
MlirAttribute llzkFunction_FuncDefOpGetResNameAttr(MlirOperation op, unsigned index)
Returns the function.res_name StringAttr for the result at the given index, or null if the result has...
void llzkFunction_FuncDefOpSetResName(MlirOperation op, unsigned index, MlirStringRef name)
Sets the function.res_name attribute for the result at the given index from a string value.
void llzkFunction_FuncDefOpSetArgNameAttr(MlirOperation op, unsigned index, MlirAttribute attr)
Sets the function.arg_name attribute for the argument at the given index.
MlirAttribute llzkFunction_FuncDefOpGetArgNameAttr(MlirOperation op, unsigned index)
Returns the function.arg_name StringAttr for the argument at the given index, or null if the argument...
void llzkFunction_FuncDefOpSetResNameAttr(MlirOperation op, unsigned index, MlirAttribute attr)
Sets the function.res_name attribute for the result at the given index.
void llzkFunction_FuncDefOpSetArgName(MlirOperation op, unsigned index, MlirStringRef name)
Sets the function.arg_name attribute for the argument at the given index from a string value.
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.
#define LLZK_DEFINE_OP_BUILD_METHOD(dialect, op,...)
#define LLZK_DEFINE_SUFFIX_OP_BUILD_METHOD(dialect, op, suffix,...)
mlir::Operation * create(MlirOpBuilder cBuilder, MlirLocation cLocation, Args &&...args)
Creates a new operation using an ODS build method.
Encapsulates the arguments related to affine maps that are common in operation constructors that supp...
MlirValueRange * mapOperands