Skip to content

Commit cae746d

Browse files
author
Jeff Niu
committed
[mlir][index] Add convert-index-to-llvm pass
This patch adds a lowering pass to convert `index` dialect ops to LLVM. Depends on D135694 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D135697
1 parent 83c3eeb commit cae746d

File tree

7 files changed

+593
-0
lines changed

7 files changed

+593
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===- IndexToLLVM.h - Index 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_INDEXTOLLVM_INDEXTOLLVM_H
10+
#define MLIR_CONVERSION_INDEXTOLLVM_INDEXTOLLVM_H
11+
12+
#include <memory>
13+
14+
namespace mlir {
15+
class LLVMTypeConverter;
16+
class RewritePatternSet;
17+
class Pass;
18+
19+
#define GEN_PASS_DECL_CONVERTINDEXTOLLVMPASS
20+
#include "mlir/Conversion/Passes.h.inc"
21+
22+
namespace index {
23+
void populateIndexToLLVMConversionPatterns(LLVMTypeConverter &converter,
24+
RewritePatternSet &patterns);
25+
} // namespace index
26+
} // namespace mlir
27+
28+
#endif // MLIR_CONVERSION_INDEXTOLLVM_INDEXTOLLVM_H

mlir/include/mlir/Conversion/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h"
3030
#include "mlir/Conversion/GPUToSPIRV/GPUToSPIRVPass.h"
3131
#include "mlir/Conversion/GPUToVulkan/ConvertGPUToVulkanPass.h"
32+
#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
3233
#include "mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h"
3334
#include "mlir/Conversion/LinalgToSPIRV/LinalgToSPIRVPass.h"
3435
#include "mlir/Conversion/LinalgToStandard/LinalgToStandard.h"

mlir/include/mlir/Conversion/Passes.td

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,29 @@ def ConvertVulkanLaunchFuncToVulkanCalls
439439
let dependentDialects = ["LLVM::LLVMDialect"];
440440
}
441441

442+
//===----------------------------------------------------------------------===//
443+
// ConvertIndexToLLVMPass
444+
//===----------------------------------------------------------------------===//
445+
446+
def ConvertIndexToLLVMPass : Pass<"convert-index-to-llvm"> {
447+
let summary = "Lower the `index` dialect to the `llvm` dialect.";
448+
let description = [{
449+
This pass lowers Index dialect operations to LLVM dialect operations.
450+
Operation conversions are 1-to-1 except for the exotic divides: `ceildivs`,
451+
`ceildivu`, and `floordivs`, which expand to series of LLVM operations.
452+
Importantly, the index bitwidth should be correctly set to the target
453+
pointer width via `index-bitwidth`.
454+
}];
455+
456+
let dependentDialects = ["::mlir::LLVM::LLVMDialect"];
457+
458+
let options = [
459+
Option<"indexBitwidth", "index-bitwidth", "unsigned",
460+
/*default=kDeriveIndexBitwidthFromDataLayout*/"0",
461+
"Bitwidth of the index type, 0 to use size of machine word">,
462+
];
463+
}
464+
442465
//===----------------------------------------------------------------------===//
443466
// LinalgToLLVM
444467
//===----------------------------------------------------------------------===//

mlir/lib/Conversion/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_subdirectory(GPUToNVVM)
1717
add_subdirectory(GPUToROCDL)
1818
add_subdirectory(GPUToSPIRV)
1919
add_subdirectory(GPUToVulkan)
20+
add_subdirectory(IndexToLLVM)
2021
add_subdirectory(LinalgToLLVM)
2122
add_subdirectory(LinalgToSPIRV)
2223
add_subdirectory(LinalgToStandard)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
add_mlir_conversion_library(MLIRIndexToLLVM
2+
IndexToLLVM.cpp
3+
4+
ADDITIONAL_HEADER_DIRS
5+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/IndexToLLVM
6+
7+
DEPENDS
8+
MLIRConversionPassIncGen
9+
10+
LINK_COMPONENTS
11+
Core
12+
13+
LINK_LIBS PUBLIC
14+
MLIRIndexDialect
15+
MLIRLLVMCommonConversion
16+
MLIRLLVMDialect
17+
)

0 commit comments

Comments
 (0)