diff options
author | Michael Kruse <llvm-project@meinersbur.de> | 2025-07-11 12:54:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-11 12:54:25 +0200 |
commit | 96bc07d49221dc40eb751e0759be2ccbb8a64f00 (patch) | |
tree | 2bb124a3bc6a019c14dd6b7249374735911baf01 /mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp | |
parent | a61ea9fd9b9c100ce4fce9212dc85230257fd5c8 (diff) | |
download | llvm-96bc07d49221dc40eb751e0759be2ccbb8a64f00.zip llvm-96bc07d49221dc40eb751e0759be2ccbb8a64f00.tar.gz llvm-96bc07d49221dc40eb751e0759be2ccbb8a64f00.tar.bz2 |
[MLIR][OpenMP] Add canonical loop LLVM-IR lowering (#147069)
Support for translating the operations introduced in #144785 to LLVM-IR.
In order to keep the lowering simple,
`OpenMPIRBuider::unrollLoopHeuristic` is applied when encountering the
`omp.unroll_heuristic` op. As a result, the operation that unrolling is
applied to (`omp.canonical_loop`) must have been emitted before even
though logically there is no such requirement.
Eventually, all transformations on a loop must be applied directly after
emitting `omp.canonical_loop`, i.e. future transformations must be
looked-up when encountering `omp.canonical_loop` itself. This is because
many OpenMPIRBuilder methods (e.g. `createParallel`) expect all the
region code to be emitted withing a callback. In the case of
`createParallel`, the region code is getting outlined into a new
function. Therefore, making the operation order a formal requirement
would not make the implementation any easier.
Diffstat (limited to 'mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp')
-rw-r--r-- | mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp index 77a2708..7ac9687 100644 --- a/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp +++ b/mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp @@ -41,6 +41,16 @@ template <typename T> struct OpenMPOpConversion : public ConvertOpToLLVMPattern<T> { using ConvertOpToLLVMPattern<T>::ConvertOpToLLVMPattern; + OpenMPOpConversion(LLVMTypeConverter &typeConverter, + PatternBenefit benefit = 1) + : ConvertOpToLLVMPattern<T>(typeConverter, benefit) { + // Operations using CanonicalLoopInfoType are lowered only by + // mlir::translateModuleToLLVMIR() using the OpenMPIRBuilder. Until then, + // the type and operations using it must be preserved. + typeConverter.addConversion( + [&](::mlir::omp::CanonicalLoopInfoType type) { return type; }); + } + LogicalResult matchAndRewrite(T op, typename T::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override { |