Skip to content

Commit 9b88d38

Browse files
authored
[mlir][ptr] Add conversion to LLVM for all existing ptr ops (#156053)
This patch adds conversion to LLVM for all existing pointer ops. This is a stop gap measure to allow users to use the `ptr` dialect now. In the future some of these conversions will be removed, and added as translations, for example `ptradd`. Example: ```mlir func.func @test_memref_ptradd_indexing(%arg0: memref<10x?x30xf32, #ptr.generic_space>, %arg1: index) -> !ptr.ptr<#ptr.generic_space> { %0 = ptr.to_ptr %arg0 : memref<10x?x30xf32, #ptr.generic_space> -> <#ptr.generic_space> %1 = ptr.type_offset f32 : index %2 = arith.muli %1, %arg1 : index %3 = ptr.ptr_add %0, %2 : <#ptr.generic_space>, index return %3 : !ptr.ptr<#ptr.generic_space> } // mlir-opt --convert-to-llvm --canonicalize --cse llvm.func @test_memref_ptradd_indexing(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: i64, %arg8: i64, %arg9: i64) -> !llvm.ptr { %0 = llvm.mlir.zero : !llvm.ptr %1 = llvm.getelementptr %0[1] : (!llvm.ptr) -> !llvm.ptr, f32 %2 = llvm.ptrtoint %1 : !llvm.ptr to i64 %3 = llvm.mul %2, %arg9 : i64 %4 = llvm.getelementptr %arg1[%3] : (!llvm.ptr, i64) -> !llvm.ptr, i8 llvm.return %4 : !llvm.ptr } ```
1 parent f98e552 commit 9b88d38

File tree

6 files changed

+805
-0
lines changed

6 files changed

+805
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//===- PtrToLLVM.h - Ptr to LLVM dialect conversion -------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef MLIR_CONVERSION_PTRTOLLVM_PTRTOLLVM_H
10+
#define MLIR_CONVERSION_PTRTOLLVM_PTRTOLLVM_H
11+
12+
#include <memory>
13+
14+
namespace mlir {
15+
class DialectRegistry;
16+
class LLVMTypeConverter;
17+
class RewritePatternSet;
18+
namespace ptr {
19+
/// Populate the convert to LLVM patterns for the `ptr` dialect.
20+
void populatePtrToLLVMConversionPatterns(LLVMTypeConverter &converter,
21+
RewritePatternSet &patterns);
22+
/// Register the convert to LLVM interface for the `ptr` dialect.
23+
void registerConvertPtrToLLVMInterface(DialectRegistry &registry);
24+
} // namespace ptr
25+
} // namespace mlir
26+
27+
#endif // MLIR_CONVERSION_PTRTOLLVM_PTRTOLLVM_H

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_subdirectory(NVVMToLLVM)
5050
add_subdirectory(OpenACCToSCF)
5151
add_subdirectory(OpenMPToLLVM)
5252
add_subdirectory(PDLToPDLInterp)
53+
add_subdirectory(PtrToLLVM)
5354
add_subdirectory(ReconcileUnrealizedCasts)
5455
add_subdirectory(SCFToControlFlow)
5556
add_subdirectory(SCFToEmitC)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
add_mlir_conversion_library(MLIRPtrToLLVM
2+
PtrToLLVM.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/PtrToLLVM
6+
7+
DEPENDS
8+
MLIRConversionPassIncGen
9+
10+
LINK_COMPONENTS
11+
Core
12+
13+
LINK_LIBS PUBLIC
14+
MLIRPtrDialect
15+
MLIRLLVMCommonConversion
16+
MLIRLLVMDialect
17+
)

0 commit comments

Comments
 (0)