From 29fbe600091d89134cd998d02b0e9d7a4a6115b3 Mon Sep 17 00:00:00 2001 From: Michele Scuttari Date: Tue, 2 Aug 2022 18:21:05 +0000 Subject: [PATCH] [MLIR] Rename the generic LLVM allocation and deallocation functions The generic allocation and deallocation instructions, which are optionally used during the MemRef -> LLVM conversion, should have a name that is specifically bound to their origin, that is the conversion pass itself. Reviewed By: silvas Differential Revision: https://reviews.llvm.org/D130588 --- mlir/docs/TargetLLVMIR.md | 7 ++++--- mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp | 7 ++++--- mlir/test/Conversion/MemRefToLLVM/generic-functions.mlir | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/mlir/docs/TargetLLVMIR.md b/mlir/docs/TargetLLVMIR.md index c86ed7a..bf639b8 100644 --- a/mlir/docs/TargetLLVMIR.md +++ b/mlir/docs/TargetLLVMIR.md @@ -560,9 +560,10 @@ into calls to `malloc` (`aligned_alloc` if aligned allocations are requested) and `free`. However, it is possible to convert them to more generic functions which can be implemented by a runtime library, thus allowing custom allocation strategies or runtime profiling. When the conversion pass is instructed to -perform such operation, the names of the calles are `_mlir_alloc`, -`_mlir_aligned_alloc` and `_mlir_free`. Their signatures are the same of -`malloc`, `aligned_alloc` and `free`. +perform such operation, the names of the calles are +`_mlir_memref_to_llvm_alloc`, `_mlir_memref_to_llvm_aligned_alloc` and +`_mlir_memref_to_llvm_free`. Their signatures are the same of `malloc`, +`aligned_alloc` and `free`. ### C-compatible wrapper emission diff --git a/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp b/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp index 1a336fe..65e26aa 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/FunctionCallUtils.cpp @@ -35,9 +35,10 @@ static constexpr llvm::StringRef kPrintNewline = "printNewline"; static constexpr llvm::StringRef kMalloc = "malloc"; static constexpr llvm::StringRef kAlignedAlloc = "aligned_alloc"; static constexpr llvm::StringRef kFree = "free"; -static constexpr llvm::StringRef kGenericAlloc = "_mlir_alloc"; -static constexpr llvm::StringRef kGenericAlignedAlloc = "_mlir_aligned_alloc"; -static constexpr llvm::StringRef kGenericFree = "_mlir_free"; +static constexpr llvm::StringRef kGenericAlloc = "_mlir_memref_to_llvm_alloc"; +static constexpr llvm::StringRef kGenericAlignedAlloc = + "_mlir_memref_to_llvm_aligned_alloc"; +static constexpr llvm::StringRef kGenericFree = "_mlir_memref_to_llvm_free"; static constexpr llvm::StringRef kMemRefCopy = "memrefCopy"; /// Generic print function lookupOrCreate helper. diff --git a/mlir/test/Conversion/MemRefToLLVM/generic-functions.mlir b/mlir/test/Conversion/MemRefToLLVM/generic-functions.mlir index 624ae76..3d98dbc 100644 --- a/mlir/test/Conversion/MemRefToLLVM/generic-functions.mlir +++ b/mlir/test/Conversion/MemRefToLLVM/generic-functions.mlir @@ -6,8 +6,8 @@ // CHECK-LABEL: func @alloc() func.func @zero_d_alloc() -> memref { -// CHECK-NOTALIGNED: llvm.call @_mlir_alloc(%{{.*}}) : (i64) -> !llvm.ptr -// CHECK-ALIGNED: llvm.call @_mlir_aligned_alloc(%{{.*}}, %{{.*}}) : (i64, i64) -> !llvm.ptr +// CHECK-NOTALIGNED: llvm.call @_mlir_memref_to_llvm_alloc(%{{.*}}) : (i64) -> !llvm.ptr +// CHECK-ALIGNED: llvm.call @_mlir_memref_to_llvm_aligned_alloc(%{{.*}}, %{{.*}}) : (i64, i64) -> !llvm.ptr %0 = memref.alloc() : memref return %0 : memref } @@ -16,8 +16,8 @@ func.func @zero_d_alloc() -> memref { // CHECK-LABEL: func @dealloc() func.func @dealloc(%arg0: memref) { -// CHECK-NOTALIGNED: llvm.call @_mlir_free(%{{.*}}) : (!llvm.ptr) -> () -// CHECK-ALIGNED: llvm.call @_mlir_free(%{{.*}}) : (!llvm.ptr) -> () +// CHECK-NOTALIGNED: llvm.call @_mlir_memref_to_llvm_free(%{{.*}}) : (!llvm.ptr) -> () +// CHECK-ALIGNED: llvm.call @_mlir_memref_to_llvm_free(%{{.*}}) : (!llvm.ptr) -> () memref.dealloc %arg0 : memref return } -- 2.7.4