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)
49 MlirLocation location, MlirStringRef name, MlirType funcType, intptr_t numAttrs,
50 MlirNamedAttribute const *attrs, intptr_t numArgAttrs, MlirAttribute const *argAttrs
52 SmallVector<NamedAttribute> attrsSto;
53 SmallVector<Attribute> argAttrsSto;
54 SmallVector<DictionaryAttr> unwrappedArgAttrs =
55 llvm::map_to_vector(unwrapList(numArgAttrs, argAttrs, argAttrsSto), [](
auto attr) {
56 return llvm::cast<DictionaryAttr>(attr);
60 unwrap(location), unwrap(name), llvm::cast<FunctionType>(unwrap(funcType)),
61 unwrapList(numAttrs, attrs, attrsSto), unwrappedArgAttrs
67 return llvm::cast<FuncDefOp>(unwrap(op)).hasArgName(index);
71 std::optional<StringAttr> argNameAttr = llvm::cast<FuncDefOp>(unwrap(op)).getArgNameAttr(index);
72 return wrap(argNameAttr ? Attribute(*argNameAttr) : Attribute());
76 llvm::cast<FuncDefOp>(unwrap(op)).setArgNameAttr(index, llvm::cast<StringAttr>(unwrap(attr)));
80 llvm::cast<FuncDefOp>(unwrap(op)).setArgName(index, unwrap(name));
87static auto unwrapCallee(MlirOperation op) {
return llvm::cast<FuncDefOp>(unwrap(op)); }
89static auto unwrapDims(MlirAttribute attr) {
return llvm::cast<DenseI32ArrayAttr>(unwrap(attr)); }
91static auto unwrapName(MlirAttribute attr) {
return llvm::cast<SymbolRefAttr>(unwrap(attr)); }
94 Function,
CallOp, intptr_t numResults, MlirType
const *results, MlirAttribute name,
95 intptr_t numOperands, MlirValue
const *operands
97 SmallVector<Type> resultsSto;
98 SmallVector<Value> operandsSto;
101 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
102 unwrapList(numOperands, operands, operandsSto)
108 Function,
CallOp, ToCallee, MlirOperation callee, intptr_t numOperands,
109 MlirValue
const *operands
111 SmallVector<Value> operandsSto;
114 builder, location, unwrapCallee(callee), unwrapList(numOperands, operands, operandsSto)
120 Function,
CallOp, WithMapOperands, intptr_t numResults, MlirType
const *results,
122 MlirValue
const *argOperands
124 SmallVector<Type> resultsSto;
125 SmallVector<Value> argOperandsSto;
131 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
132 *mapOperandsHelper, unwrapDims(numDimsPerMap),
133 unwrapList(numArgOperands, argOperands, argOperandsSto)
139 Function,
CallOp, ToCalleeWithMapOperands, MlirOperation callee,
142 SmallVector<Value> argOperandsSto;
148 builder, location, unwrapCallee(callee), *mapOperandsHelper, unwrapDims(numDimsPerMap),
149 unwrapList(numArgOperands, argOperands, argOperandsSto)
155 Function,
CallOp, WithTemplateParams, intptr_t numResults, MlirType
const *results,
156 MlirAttribute name, intptr_t numTemplateParams, MlirAttribute
const *templateParams,
157 intptr_t numArgOperands, MlirValue
const *argOperands
159 SmallVector<Type> resultsSto;
160 SmallVector<Value> argOperandsSto;
161 SmallVector<Attribute> templateParamsSto;
164 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
165 unwrapList(numArgOperands, argOperands, argOperandsSto),
166 unwrapList(numTemplateParams, templateParams, templateParamsSto)
172 Function,
CallOp, ToCalleeWithTemplateParams, MlirOperation callee, intptr_t numTemplateParams,
173 MlirAttribute
const *templateParams, intptr_t numArgOperands, MlirValue
const *argOperands
175 SmallVector<Value> argOperandsSto;
176 SmallVector<Attribute> templateParamsSto;
179 builder, location, unwrapCallee(callee),
180 unwrapList(numArgOperands, argOperands, argOperandsSto),
181 unwrapList(numTemplateParams, templateParams, templateParamsSto)
void llzkFunction_FuncDefOpSetArgNameAttr(MlirOperation op, unsigned index, MlirAttribute attr)
Sets the function.arg_name attribute for the argument at the given index.
bool llzkFunction_FuncDefOpHasArgNameAttr(MlirOperation op, unsigned index)
Returns true iff the argument at the given index has a function.arg_name attribute.
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...
MlirOperation llzkFunction_FuncDefOpCreateWithAttrsAndArgAttrs(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.
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.
static FuncDefOp create(::mlir::Location location, ::llvm::StringRef name, ::mlir::FunctionType type, ::llvm::ArrayRef<::mlir::NamedAttribute > attrs={})
#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