Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/include/mlir-c/Dialect/LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(LLVM, llvm);
MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx,
unsigned addressSpace);

MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMPointerTypeGetTypeID(void);

/// Returns `true` if the type is an LLVM dialect pointer type.
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMPointerType(MlirType type);

Expand Down Expand Up @@ -58,6 +60,8 @@ MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type);
/// Returns `true` if the type is an LLVM dialect struct type.
MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMStructType(MlirType type);

MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMStructTypeGetTypeID(void);

/// Returns `true` if the type is a literal (unnamed) LLVM struct type.
MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsLiteral(MlirType type);

Expand Down
7 changes: 4 additions & 3 deletions mlir/lib/Bindings/Python/DialectLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ static void populateDialectLLVMSubmodule(nanobind::module_ &m) {
// StructType
//===--------------------------------------------------------------------===//

auto llvmStructType =
mlir_type_subclass(m, "StructType", mlirTypeIsALLVMStructType);
auto llvmStructType = mlir_type_subclass(
m, "StructType", mlirTypeIsALLVMStructType, mlirLLVMStructTypeGetTypeID);

llvmStructType
.def_classmethod(
Expand Down Expand Up @@ -137,7 +137,8 @@ static void populateDialectLLVMSubmodule(nanobind::module_ &m) {
// PointerType
//===--------------------------------------------------------------------===//

mlir_type_subclass(m, "PointerType", mlirTypeIsALLVMPointerType)
mlir_type_subclass(m, "PointerType", mlirTypeIsALLVMPointerType,
mlirLLVMPointerTypeGetTypeID)
.def_classmethod(
"get",
[](const nb::object &cls, std::optional<unsigned> addressSpace,
Expand Down
8 changes: 8 additions & 0 deletions mlir/lib/CAPI/Dialect/LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace) {
return wrap(LLVMPointerType::get(unwrap(ctx), addressSpace));
}

MlirTypeID mlirLLVMPointerTypeGetTypeID() {
return wrap(LLVM::LLVMPointerType::getTypeID());
}

bool mlirTypeIsALLVMPointerType(MlirType type) {
return isa<LLVM::LLVMPointerType>(unwrap(type));
}
Expand Down Expand Up @@ -73,6 +77,10 @@ bool mlirTypeIsALLVMStructType(MlirType type) {
return isa<LLVM::LLVMStructType>(unwrap(type));
}

MlirTypeID mlirLLVMStructTypeGetTypeID() {
return wrap(LLVM::LLVMStructType::getTypeID());
}

bool mlirLLVMStructTypeIsLiteral(MlirType type) {
return !cast<LLVM::LLVMStructType>(unwrap(type)).isIdentified();
}
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/python/dialects/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def testStructType():
assert opaque.opaque
# CHECK: !llvm.struct<"opaque", opaque>

typ = Type.parse('!llvm.struct<"zoo", (i32, i64)>')
assert isinstance(typ, llvm.StructType)


# CHECK-LABEL: testSmoke
@constructAndPrintInModule
Expand All @@ -120,6 +123,9 @@ def testPointerType():
# CHECK: !llvm.ptr<1>
print(ptr_with_addr)

typ = Type.parse("!llvm.ptr<1>")
assert isinstance(typ, llvm.PointerType)


# CHECK-LABEL: testConstant
@constructAndPrintInModule
Expand Down