[Mlir-commits] [mlir] 46edbce - [MLIR][LLVM] Change CAPI pointer factory to create opaque pointers (#70572)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Oct 30 04:50:41 PDT 2023


Author: Christian Ulmann
Date: 2023-10-30T12:50:37+01:00
New Revision: 46edbce454a58e35b6f026092fe4dadcf5fccb2e

URL: https://github.com/llvm/llvm-project/commit/46edbce454a58e35b6f026092fe4dadcf5fccb2e
DIFF: https://github.com/llvm/llvm-project/commit/46edbce454a58e35b6f026092fe4dadcf5fccb2e.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/include/mlir-c/Dialect/LLVM.h
    mlir/lib/CAPI/Dialect/LLVM.cpp
    mlir/test/CAPI/llvm.c

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index ba98c33fdfd6bc6..72701a82225436e 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -19,7 +19,7 @@ extern "C" {
 MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(LLVM, llvm);
 
 /// Creates an llvm.ptr type.
-MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirType pointee,
+MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx,
                                                    unsigned addressSpace);
 
 /// Creates an llmv.void type.

diff  --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index d023bf5d68ce5a5..b4405f7aac8ab29 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -16,8 +16,8 @@ using namespace mlir::LLVM;
 
 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM, llvm, LLVMDialect)
 
-MlirType mlirLLVMPointerTypeGet(MlirType pointee, unsigned addressSpace) {
-  return wrap(LLVMPointerType::get(unwrap(pointee), addressSpace));
+MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace) {
+  return wrap(LLVMPointerType::get(unwrap(ctx), addressSpace));
 }
 
 MlirType mlirLLVMVoidTypeGet(MlirContext ctx) {

diff  --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index 82e1660c15a4825..aaec7b113f0a976 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -10,8 +10,8 @@
 // RUN: mlir-capi-llvm-test 2>&1 | FileCheck %s
 
 #include "mlir-c/Dialect/LLVM.h"
-#include "mlir-c/IR.h"
 #include "mlir-c/BuiltinTypes.h"
+#include "mlir-c/IR.h"
 
 #include <assert.h>
 #include <math.h>
@@ -26,17 +26,20 @@ static void testTypeCreation(MlirContext ctx) {
   MlirType i32 = mlirIntegerTypeGet(ctx, 32);
   MlirType i64 = mlirIntegerTypeGet(ctx, 64);
 
-  const char *i32p_text = "!llvm.ptr<i32>";
-  MlirType i32p = mlirLLVMPointerTypeGet(i32, 0);
-  MlirType i32p_ref = mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32p_text));
-  // CHECK: !llvm.ptr<i32>: 1
-  fprintf(stderr, "%s: %d\n", i32p_text, mlirTypeEqual(i32p, i32p_ref));
+  const char *ptr_text = "!llvm.ptr";
+  MlirType ptr = mlirLLVMPointerTypeGet(ctx, 0);
+  MlirType ptr_ref =
+      mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(ptr_text));
+  // CHECK: !llvm.ptr: 1
+  fprintf(stderr, "%s: %d\n", ptr_text, mlirTypeEqual(ptr, ptr_ref));
 
-  const char *i32p4_text = "!llvm.ptr<i32, 4>";
-  MlirType i32p4 = mlirLLVMPointerTypeGet(i32, 4);
-  MlirType i32p4_ref = mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(i32p4_text));
-  // CHECK: !llvm.ptr<i32, 4>: 1
-  fprintf(stderr, "%s: %d\n", i32p4_text, mlirTypeEqual(i32p4, i32p4_ref));
+  const char *ptr_addr_text = "!llvm.ptr<42>";
+  MlirType ptr_addr = mlirLLVMPointerTypeGet(ctx, 42);
+  MlirType ptr_addr_ref =
+      mlirTypeParseGet(ctx, mlirStringRefCreateFromCString(ptr_addr_text));
+  // CHECK: !llvm.ptr<42>: 1
+  fprintf(stderr, "%s: %d\n", ptr_addr_text,
+          mlirTypeEqual(ptr_addr, ptr_addr_ref));
 
   const char *voidt_text = "!llvm.void";
   MlirType voidt = mlirLLVMVoidTypeGet(ctx);


        


More information about the Mlir-commits mailing list