20#include <mlir-c/Pass.h>
22#include <mlir/CAPI/IR.h>
23#include <mlir/CAPI/Pass.h>
24#include <mlir/CAPI/Registration.h>
25#include <mlir/CAPI/Wrap.h>
26#include <mlir/IR/Attributes.h>
27#include <mlir/IR/BuiltinAttributes.h>
29#include <llvm/ADT/SmallVectorExtras.h>
39MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Function, llzk__function,
FunctionDialect)
48 MlirLocation location, MlirStringRef name, MlirType funcType, intptr_t numAttrs,
49 MlirNamedAttribute const *attrs, intptr_t numArgAttrs, 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);
59 unwrap(location), unwrap(name), llvm::cast<FunctionType>(unwrap(funcType)),
60 unwrapList(numAttrs, attrs, attrsSto), unwrappedArgAttrs
69static auto unwrapCallee(MlirOperation op) {
return llvm::cast<FuncDefOp>(unwrap(op)); }
71static auto unwrapDims(MlirAttribute attr) {
return llvm::cast<DenseI32ArrayAttr>(unwrap(attr)); }
73static auto unwrapName(MlirAttribute attr) {
return llvm::cast<SymbolRefAttr>(unwrap(attr)); }
76 Function,
CallOp, intptr_t numResults, MlirType
const *results, MlirAttribute name,
77 intptr_t numOperands, MlirValue
const *operands
79 SmallVector<Type> resultsSto;
80 SmallVector<Value> operandsSto;
83 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
84 unwrapList(numOperands, operands, operandsSto)
90 Function,
CallOp, ToCallee, MlirOperation callee, intptr_t numOperands,
91 MlirValue
const *operands
93 SmallVector<Value> operandsSto;
96 builder, location, unwrapCallee(callee), unwrapList(numOperands, operands, operandsSto)
102 Function,
CallOp, WithMapOperands, intptr_t numResults, MlirType
const *results,
104 MlirValue
const *argOperands
106 SmallVector<Type> resultsSto;
107 SmallVector<Value> argOperandsSto;
113 builder, location, unwrapList(numResults, results, resultsSto), unwrapName(name),
114 *mapOperandsHelper, unwrapDims(numDimsPerMap),
115 unwrapList(numArgOperands, argOperands, argOperandsSto)
121 Function,
CallOp, ToCalleeWithMapOperands, MlirOperation callee,
124 SmallVector<Value> argOperandsSto;
130 builder, location, unwrapCallee(callee), *mapOperandsHelper, unwrapDims(numDimsPerMap),
131 unwrapList(numArgOperands, argOperands, argOperandsSto)
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.
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