23using namespace nanobind::literals;
46 [](
const std::vector<PyType> &elements,
bool packed,
50 std::vector<MlirType> elements_(elements.size());
51 std::copy(elements.begin(), elements.end(), elements_.begin());
54 loc, elements.size(), elements_.data(), packed);
60 "elements"_a, nb::kw_only(),
"packed"_a =
false,
"loc"_a = nb::none(),
61 "context"_a = nb::none());
64 "get_literal_unchecked",
65 [](
const std::vector<PyType> &elements,
bool packed,
69 std::vector<MlirType> elements_(elements.size());
70 std::copy(elements.begin(), elements.end(), elements_.begin());
73 context.
get()->get(), elements.size(), elements_.data(), packed);
79 "elements"_a, nb::kw_only(),
"packed"_a =
false,
80 "context"_a = nb::none());
90 "name"_a, nb::kw_only(),
"context"_a = nb::none());
100 "name"_a,
"context"_a = nb::none());
104 [](
const StructType &self,
const std::vector<PyType> &elements,
106 std::vector<MlirType> elements_(elements.size());
107 std::copy(elements.begin(), elements.end(), elements_.begin());
109 self, elements.size(), elements_.data(), packed);
111 throw nb::value_error(
112 "Struct body already set to different content.");
115 "elements"_a, nb::kw_only(),
"packed"_a =
false);
119 [](
const std::string &
name,
const std::vector<PyType> &elements,
121 std::vector<MlirType> elements_(elements.size());
122 std::copy(elements.begin(), elements.end(), elements_.begin());
125 context.
get()->get(),
127 elements.size(), elements_.data(), packed));
129 "name"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
130 "context"_a = nb::none());
132 c.def_prop_ro(
"name",
133 [](
const StructType &type) -> std::optional<MlirStringRef> {
140 c.def_prop_ro(
"body", [](
const StructType &type) -> nb::object {
153 c.def_prop_ro(
"packed", [](
const StructType &type) {
157 c.def_prop_ro(
"opaque", [](
const StructType &type) {
178 [](
PyType &elementType,
unsigned numElements) {
182 "element_type"_a,
"num_elements"_a);
183 c.def_prop_ro(
"element_type", [](
const ArrayType &type) {
186 c.def_prop_ro(
"num_elements", [](
const ArrayType &type) {
207 [](std::optional<unsigned> addressSpace,
211 context.
get()->get(),
212 addressSpace.has_value() ? *addressSpace : 0);
214 throw nb::value_error(scope.
takeMessage().c_str());
218 "address_space"_a = nb::none(), nb::kw_only(),
219 "context"_a = nb::none());
220 c.def_prop_ro(
"address_space", [](
const PointerType &type) {
241 [](
PyType &resultType,
const std::vector<PyType> &argumentTypes,
243 std::vector<MlirType> argTypes(argumentTypes.size());
244 std::copy(argumentTypes.begin(), argumentTypes.end(),
249 argTypes.data(), isVarArg));
251 "result_type"_a,
"argument_types"_a, nb::kw_only(),
252 "is_var_arg"_a =
false);
253 c.def_prop_ro(
"return_type", [](
const FunctionType &type) {
256 c.def_prop_ro(
"num_inputs", [](
const FunctionType &type) {
267 c.def_prop_ro(
"is_var_arg", [](
const FunctionType &type) {
291 context.
get()->get(),
294 "value"_a, nb::kw_only(),
"context"_a = nb::none());
317 "value"_a, nb::kw_only(),
"context"_a = nb::none());
336 context.
get()->get(),
342 "name"_a, nb::kw_only(),
"context"_a = nb::none());
343 c.def_prop_ro(
"name", [](
const MDFuncAttr &self) {
361 [](
const std::vector<PyAttribute> &operands,
363 std::vector<MlirAttribute> operands_(operands.size());
364 std::copy(operands.begin(), operands.end(), operands_.begin());
370 "operands"_a, nb::kw_only(),
"context"_a = nb::none());
371 c.def_prop_ro(
"num_operands", [](
const MDNodeAttr &self) {
376 if (index < 0 || index >= n)
377 throw nb::index_error(
"MDNodeAttr operand index out of range");
397 "translate_module_to_llvmir",
401 "module"_a, nb::rv_policy::take_ownership);
409 m.doc() =
"MLIR LLVM Dialect";
NB_MODULE(_mlirDialectsLLVM, m)
MLIR_CAPI_EXPORTED char * mlirTranslateModuleToLLVMIRToString(MlirOperation module)
RAII scope intercepting all diagnostics into a string.
std::string takeMessage()
ReferrentTy * get() const
PyMlirContextRef & getContext()
Accesses the context reference.
Used in function arguments when None should resolve to the current context manager set instance.
Used in function arguments when None should resolve to the current context manager set instance.
PyAttribute(PyMlirContextRef contextRef, MlirAttribute attr)
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
nanobind::class_< MDStringAttr, PyAttribute > ClassTy
PyConcreteAttribute()=default
bool(*)(MlirAttribute) IsAFunctionTy
MlirTypeID(*)() GetTypeIDFunctionTy
static const MlirStringRef name
nanobind::class_< StructType, PyType > ClassTy
static void bind(nanobind::module_ &m)
MlirTypeID(*)() GetTypeIDFunctionTy
bool(*)(MlirType) IsAFunctionTy
PyType(PyMlirContextRef contextRef, MlirType type)
MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol)
Creates a flat symbol reference attribute in the given context referencing a symbol identified by the...
MLIR_CAPI_EXPORTED MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr)
Returns the referenced symbol as a string reference.
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedNewGet(MlirContext ctx, MlirStringRef name, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM identified struct type with no body and a name starting with the given prefix.
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name)
Creates an LLVM identified struct type with no body.
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMPointerType(MlirType type)
Returns true if the type is an LLVM dialect pointer type.
MLIR_CAPI_EXPORTED MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Sets the body of the identified struct if it hasn't been set yet.
MLIR_CAPI_EXPORTED unsigned mlirLLVMArrayTypeGetNumElements(MlirType type)
Returns the number of elements in the llvm.array type.
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMArrayType(MlirType type)
Returns true if the type is an LLVM dialect array type.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetName(void)
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMFunctionTypeGetName(void)
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDFuncAttrGetTypeID(void)
Returns the TypeID of MDFuncAttr.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value)
Creates an LLVM MDStringAttr.
MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos)
Returns the pos-th input type.
MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace)
Creates an llvm.ptr type.
MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGetElementType(MlirType type)
Returns the element type of the llvm.array type.
MLIR_CAPI_EXPORTED bool mlirLLVMFunctionTypeIsVarArg(MlirType type)
Returns true if the function type is variadic.
MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsLiteral(MlirType type)
Returns true if the type is a literal (unnamed) LLVM struct type.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMMDStringAttrGetValue(MlirAttribute attr)
Returns the string value of an LLVM MDStringAttr.
MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements)
Creates an llvm.array type.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type)
Returns the identifier of the identified struct.
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMArrayTypeGetTypeID(void)
MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsOpaque(MlirType type)
Returns true is the struct is explicitly opaque (will not have a body) or uninitialized (will eventua...
MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsPacked(MlirType type)
Returns true if the struct is packed.
MLIR_CAPI_EXPORTED intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type)
Returns the number of fields in the struct.
MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDStringAttr.
MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDConstantAttr.
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMPointerTypeGetTypeID(void)
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMStructTypeGetTypeID(void)
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name)
Creates an LLVM MDFuncAttr referencing a function symbol.
MLIR_CAPI_EXPORTED intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type)
Returns the number of input types.
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position)
Returns the positions-th field of the struct.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMArrayTypeGetName(void)
MLIR_CAPI_EXPORTED intptr_t mlirLLVMMDNodeAttrGetNumOperands(MlirAttribute attr)
Returns the number of operands in an LLVM MDNodeAttr.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMPointerTypeGetName(void)
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name)
MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes, MlirType const *argumentTypes, bool isVarArg)
Creates an llvm.func type.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDConstantAttrGet(MlirContext ctx, MlirAttribute valueAttr)
Creates an LLVM MDConstantAttr wrapping an attribute.
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM literal (unnamed) struct type.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDFuncAttrGetName(MlirAttribute attr)
Returns the symbol name of an LLVM MDFuncAttr.
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDConstantAttrGetTypeID(void)
Returns the TypeID of MDConstantAttr.
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDNodeAttrGetTypeID(void)
Returns the TypeID of MDNodeAttr.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDConstantAttrGetValue(MlirAttribute attr)
Returns the attribute value of an LLVM MDConstantAttr.
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMFunctionType(MlirType type)
Returns true if the type is an LLVM dialect function type.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index)
Returns the operand at the given index of an LLVM MDNodeAttr.
MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDNodeAttr.
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMStructType(MlirType type)
Returns true if the type is an LLVM dialect struct type.
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands, MlirAttribute const *operands)
Creates an LLVM MDNodeAttr.
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM literal (unnamed) struct type if possible.
MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDFuncAttr.
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMFunctionTypeGetTypeID(void)
Returns the TypeID of an LLVM function type.
MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type)
Returns the return type of the function type.
MLIR_CAPI_EXPORTED unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType)
Returns address space of llvm.ptr.
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDStringAttrGetTypeID(void)
Returns the TypeID of MDStringAttr.
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
MLIR_CAPI_EXPORTED MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
static bool mlirLogicalResultIsSuccess(MlirLogicalResult res)
Checks if the given logical result represents a success.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
static void populateDialectLLVMSubmodule(nanobind::module_ &m)
Include the generated interface declarations.
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.
const char * data
Pointer to the first symbol.
size_t length
Length of the fragment.
static void bindDerived(ClassTy &c)
static constexpr const char * pyClassName
static constexpr IsAFunctionTy isaFunction
static const MlirStringRef name
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr IsAFunctionTy isaFunction
static const MlirStringRef name
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static void bindDerived(ClassTy &c)
static constexpr const char * pyClassName
static void bindDerived(ClassTy &c)
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr const char * pyClassName
static constexpr IsAFunctionTy isaFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static void bindDerived(ClassTy &c)
static constexpr IsAFunctionTy isaFunction
static constexpr const char * pyClassName
static void bindDerived(ClassTy &c)
static constexpr IsAFunctionTy isaFunction
static constexpr const char * pyClassName
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static void bindDerived(ClassTy &c)
static constexpr const char * pyClassName
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr IsAFunctionTy isaFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr const char * pyClassName
static void bindDerived(ClassTy &c)
static constexpr IsAFunctionTy isaFunction
static const MlirStringRef name
static constexpr IsAFunctionTy isaFunction
static const MlirStringRef name
static constexpr const char * pyClassName
static void bindDerived(ClassTy &c)
static constexpr GetTypeIDFunctionTy getTypeIdFunction