20 using namespace nanobind::literals;
36 llvmStructType.def_classmethod(
38 [](nb::object cls,
const std::vector<MlirType> &elements,
bool packed,
43 loc, elements.size(), elements.data(), packed);
49 "cls"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
50 "loc"_a.none() = nb::none());
52 llvmStructType.def_classmethod(
54 [](nb::object cls,
const std::string &name, MlirContext context) {
58 "cls"_a,
"name"_a, nb::kw_only(),
"context"_a.none() = nb::none());
60 llvmStructType.def_classmethod(
62 [](nb::object cls,
const std::string &name, MlirContext context) {
66 "cls"_a,
"name"_a,
"context"_a.none() = nb::none());
70 [](MlirType
self,
const std::vector<MlirType> &elements,
bool packed) {
72 self, elements.size(), elements.data(), packed);
74 throw nb::value_error(
75 "Struct body already set to different content.");
78 "elements"_a, nb::kw_only(),
"packed"_a =
false);
80 llvmStructType.def_classmethod(
82 [](nb::object cls,
const std::string &name,
83 const std::vector<MlirType> &elements,
bool packed, MlirContext ctx) {
86 elements.size(), elements.
data(), packed));
88 "cls"_a,
"name"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
89 "context"_a.none() = nb::none());
91 llvmStructType.def_property_readonly(
92 "name", [](MlirType type) -> std::optional<std::string> {
97 return StringRef(stringRef.
data, stringRef.
length).str();
100 llvmStructType.def_property_readonly(
"body", [](MlirType type) -> nb::object {
113 llvmStructType.def_property_readonly(
116 llvmStructType.def_property_readonly(
126 [](nb::object cls, std::optional<unsigned> addressSpace,
127 MlirContext context) {
130 context, addressSpace.has_value() ? *addressSpace : 0);
132 throw nb::value_error(scope.
takeMessage().c_str());
136 "cls"_a,
"address_space"_a.none() = nb::none(), nb::kw_only(),
137 "context"_a.none() = nb::none())
138 .def_property_readonly(
"address_space", [](MlirType type) {
144 m.doc() =
"MLIR LLVM Dialect";
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 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.