22using 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());
133 "name", [](
const StructType &type) -> std::optional<std::string> {
138 return StringRef(stringRef.
data, stringRef.
length).str();
141 c.def_prop_ro(
"body", [](
const StructType &type) -> nb::object {
154 c.def_prop_ro(
"packed", [](
const StructType &type) {
158 c.def_prop_ro(
"opaque", [](
const StructType &type) {
179 [](std::optional<unsigned> addressSpace,
183 context.
get()->get(),
184 addressSpace.has_value() ? *addressSpace : 0);
186 throw nb::value_error(scope.
takeMessage().c_str());
190 "address_space"_a = nb::none(), nb::kw_only(),
191 "context"_a = nb::none());
192 c.def_prop_ro(
"address_space", [](
const PointerType &type) {
203 "translate_module_to_llvmir",
207 "module"_a, nb::rv_policy::take_ownership);
215 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
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.
nanobind::class_< StructType, PyType > ClassTy
static void bind(nanobind::module_ &m)
MlirTypeID(*)() GetTypeIDFunctionTy
bool(*)(MlirType) IsAFunctionTy
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 MlirStringRef mlirLLVMStructTypeGetName(void)
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 MlirTypeID mlirLLVMPointerTypeGetTypeID(void)
MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMStructTypeGetTypeID(void)
MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position)
Returns the positions-th field of the struct.
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMPointerTypeGetName(void)
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.
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 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