21 using namespace nanobind::literals;
40 [](
const nb::object &cls,
const std::vector<MlirType> &elements,
41 bool packed, MlirLocation loc) {
45 loc, elements.size(), elements.data(), packed);
51 "cls"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
54 "get_literal_unchecked",
55 [](
const nb::object &cls,
const std::vector<MlirType> &elements,
56 bool packed, MlirContext context) {
60 context, elements.size(), elements.data(), packed);
66 "cls"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
67 "context"_a = nb::none());
69 llvmStructType.def_classmethod(
71 [](
const nb::object &cls,
const std::string &name, MlirContext context) {
75 "cls"_a,
"name"_a, nb::kw_only(),
"context"_a = nb::none());
77 llvmStructType.def_classmethod(
79 [](
const nb::object &cls,
const std::string &name, MlirContext context) {
83 "cls"_a,
"name"_a,
"context"_a = nb::none());
87 [](MlirType
self,
const std::vector<MlirType> &elements,
bool packed) {
89 self, elements.size(), elements.data(), packed);
91 throw nb::value_error(
92 "Struct body already set to different content.");
95 "elements"_a, nb::kw_only(),
"packed"_a =
false);
97 llvmStructType.def_classmethod(
99 [](
const nb::object &cls,
const std::string &name,
100 const std::vector<MlirType> &elements,
bool packed, MlirContext ctx) {
103 elements.size(), elements.
data(), packed));
105 "cls"_a,
"name"_a,
"elements"_a, nb::kw_only(),
"packed"_a =
false,
106 "context"_a = nb::none());
108 llvmStructType.def_property_readonly(
109 "name", [](MlirType type) -> std::optional<std::string> {
114 return StringRef(stringRef.
data, stringRef.
length).str();
117 llvmStructType.def_property_readonly(
"body", [](MlirType type) -> nb::object {
130 llvmStructType.def_property_readonly(
133 llvmStructType.def_property_readonly(
143 [](
const nb::object &cls, std::optional<unsigned> addressSpace,
144 MlirContext context) {
147 context, addressSpace.has_value() ? *addressSpace : 0);
149 throw nb::value_error(scope.
takeMessage().c_str());
153 "cls"_a,
"address_space"_a = nb::none(), nb::kw_only(),
154 "context"_a = nb::none())
155 .def_property_readonly(
"address_space", [](MlirType type) {
160 "translate_module_to_llvmir",
161 [](MlirOperation module) {
167 "module"_a, nb::rv_policy::take_ownership);
171 m.doc() =
"MLIR LLVM Dialect";
static void populateDialectLLVMSubmodule(nanobind::module_ &m)
NB_MODULE(_mlirDialectsLLVM, m)
#define MAKE_MLIR_PYTHON_QUALNAME(local)
MLIR_CAPI_EXPORTED char * mlirTranslateModuleToLLVMIRToString(MlirOperation module)
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(const char *name, Func &&f, const Extra &...extra)
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.