Skip to content

Commit 46edbce

Browse files
authored
[MLIR][LLVM] Change CAPI pointer factory to create opaque pointers (#70572)
This commit changes the LLVM dialect's CAPI pointer getters to drop support for typed pointers. Typed pointers are deprecated and should no longer be generated.
1 parent 3e96070 commit 46edbce

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

mlir/include/mlir-c/Dialect/LLVM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" {
1919
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(LLVM, llvm);
2020

2121
/// Creates an llvm.ptr type.
22-
MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirType pointee,
22+
MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx,
2323
unsigned addressSpace);
2424

2525
/// Creates an llmv.void type.

mlir/lib/CAPI/Dialect/LLVM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ using namespace mlir::LLVM;
1616

1717
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM, llvm, LLVMDialect)
1818

19-
MlirType mlirLLVMPointerTypeGet(MlirType pointee, unsigned addressSpace) {
20-
return wrap(LLVMPointerType::get(unwrap(pointee), addressSpace));
19+
MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace) {
20+
return wrap(LLVMPointerType::get(unwrap(ctx), addressSpace));
2121
}
2222

2323
MlirType mlirLLVMVoidTypeGet(MlirContext ctx) {

mlir/test/CAPI/llvm.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// RUN: mlir-capi-llvm-test 2>&1 | FileCheck %s
1111

1212
#include "mlir-c/Dialect/LLVM.h"
13-
#include "mlir-c/IR.h"
1413
#include "mlir-c/BuiltinTypes.h"
14+
#include "mlir-c/IR.h"
1515

1616
#include <assert.h>
1717
#include <math.h>
@@ -26,17 +26,20 @@ static void testTypeCreation(MlirContext ctx) {
2626
MlirType i32 = mlirIntegerTypeGet(ctx, 32);
2727
MlirType i64 = mlirIntegerTypeGet(ctx, 64);
2828

29-
const char *i32p_text = "!llvm.ptr<i32>";
30-
MlirType i32p = mlirLLVMPointerTypeGet(i32, 0);
31-
MlirType i32p_ref = mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32p_text));
32-
// CHECK: !llvm.ptr<i32>: 1
33-
fprintf(stderr, "%s: %d\n", i32p_text, mlirTypeEqual(i32p, i32p_ref));
29+
const char *ptr_text = "!llvm.ptr";
30+
MlirType ptr = mlirLLVMPointerTypeGet(ctx, 0);
31+
MlirType ptr_ref =
32+
mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(ptr_text));
33+
// CHECK: !llvm.ptr: 1
34+
fprintf(stderr, "%s: %d\n", ptr_text, mlirTypeEqual(ptr, ptr_ref));
3435

35-
const char *i32p4_text = "!llvm.ptr<i32, 4>";
36-
MlirType i32p4 = mlirLLVMPointerTypeGet(i32, 4);
37-
MlirType i32p4_ref = mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32p4_text));
38-
// CHECK: !llvm.ptr<i32, 4>: 1
39-
fprintf(stderr, "%s: %d\n", i32p4_text, mlirTypeEqual(i32p4, i32p4_ref));
36+
const char *ptr_addr_text = "!llvm.ptr<42>";
37+
MlirType ptr_addr = mlirLLVMPointerTypeGet(ctx, 42);
38+
MlirType ptr_addr_ref =
39+
mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(ptr_addr_text));
40+
// CHECK: !llvm.ptr<42>: 1
41+
fprintf(stderr, "%s: %d\n", ptr_addr_text,
42+
mlirTypeEqual(ptr_addr, ptr_addr_ref));
4043

4144
const char *voidt_text = "!llvm.void";
4245
MlirType voidt = mlirLLVMVoidTypeGet(ctx);

0 commit comments

Comments
 (0)