20 using namespace nanobind::literals;
39 [](
const nb::object &cls,
const std::vector<MlirType> &elements,
40 bool packed, MlirLocation loc) {
44 loc, elements.size(), elements.data(), packed);
50 "cls"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
53 "get_literal_unchecked",
54 [](
const nb::object &cls,
const std::vector<MlirType> &elements,
55 bool packed, MlirContext context) {
59 context, elements.size(), elements.data(), packed);
65 "cls"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
66 "context"_a = nb::none());
68 llvmStructType.def_classmethod(
70 [](
const nb::object &cls,
const std::string &name, MlirContext context) {
74 "cls"_a,
"name"_a, nb::kw_only(),
"context"_a = nb::none());
76 llvmStructType.def_classmethod(
78 [](
const nb::object &cls,
const std::string &name, MlirContext context) {
82 "cls"_a,
"name"_a,
"context"_a = nb::none());
86 [](MlirType
self,
const std::vector<MlirType> &elements,
bool packed) {
88 self, elements.size(), elements.data(), packed);
90 throw nb::value_error(
91 "Struct body already set to different content.");
94 "elements"_a, nb::kw_only(),
"packed"_a =
false);
96 llvmStructType.def_classmethod(
98 [](
const nb::object &cls,
const std::string &name,
99 const std::vector<MlirType> &elements,
bool packed, MlirContext ctx) {
102 elements.size(), elements.
data(), packed));
104 "cls"_a,
"name"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
105 "context"_a = nb::none());
107 llvmStructType.def_property_readonly(
108 "name", [](MlirType type) -> std::optional<std::string> {
113 return StringRef(stringRef.
data, stringRef.
length).str();
116 llvmStructType.def_property_readonly(
"body", [](MlirType type) -> nb::object {
129 llvmStructType.def_property_readonly(
132 llvmStructType.def_property_readonly(
142 [](
const nb::object &cls, std::optional<unsigned> addressSpace,
143 MlirContext context) {
146 context, addressSpace.has_value() ? *addressSpace : 0);
148 throw nb::value_error(scope.
takeMessage().c_str());
152 "cls"_a,
"address_space"_a = nb::none(), nb::kw_only(),
153 "context"_a = nb::none())
154 .def_property_readonly(
"address_space", [](MlirType type) {
160 m.doc() =
"MLIR LLVM Dialect";
static void populateDialectLLVMSubmodule(const nanobind::module_ &m)
NB_MODULE(_mlirDialectsLLVM, m)
RAII scope intercepting all diagnostics into a string.
std::string takeMessage()
Creates a custom subclass of mlir.ir.Type, implementing a casting constructor and type checking metho...
pure_subclass & def_classmethod(const char *name, Func &&f, const Extra &...extra)
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 MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace)
Creates an llvm.ptr type.
MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsLiteral(MlirType type)
Returns true if the type is a literal (unnamed) LLVM struct type.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type)
Returns the identifier of the identified struct.
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 MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position)
Returns the positions-th field of the struct.
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name)
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 bool mlirTypeIsALLVMStructType(MlirType type)
Returns true if the type is an LLVM dialect struct type.
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 unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType)
Returns address space of llvm.ptr.
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.
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.