1//===- ACCToLLVM.cpp - Convert OpenACC to LLVM dialect ----------*- 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#include "mlir/Conversion/OpenACCToLLVM/ACCToLLVM.h"
10
11#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
12#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
13#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
14#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
15#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
16#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
17#include "mlir/Dialect/OpenACC/Analysis/OpenACCSupport.h"
18#include "mlir/Dialect/OpenACC/Extensions/AllExtensions.h"
19#include "mlir/Pass/Pass.h"
20
21namespace mlir {
22#define GEN_PASS_DEF_CONVERTACCTOLLVMPASS
23#include "mlir/Conversion/Passes.h.inc"
24} // namespace mlir
25
26using namespace mlir;
27
28namespace {
29struct ConvertACCToLLVMPass
30 : public impl::ConvertACCToLLVMPassBase<ConvertACCToLLVMPass> {
31 using Base::Base;
32
33 void getDependentDialects(DialectRegistry &registry) const override {
34 Base::getDependentDialects(registry);
35 acc::registerAllExtensions(registry);
36 }
37
38 void runOnOperation() override;
39};
40} // namespace
41
42void ConvertACCToLLVMPass::runOnOperation() {
43 ModuleOp module = getOperation();
44
45 SymbolTable symbolTable(module);
46 LLVMTypeConverter converter(&getContext());
47 RewritePatternSet patterns(&getContext());
48 arith::populateArithToLLVMConversionPatterns(converter, patterns);
49 cf::populateControlFlowToLLVMConversionPatterns(converter, patterns);
50 populateFuncToLLVMConversionPatterns(converter, patterns);
51 populateFinalizeMemRefToLLVMConversionPatterns(converter, patterns);
52
53 acc::ACCRuntimeCallConfig runtimeConfig;
54
55 populateACCExecutableDirectivePatterns(
56 converter, patterns, globalSymbolRegion&: module.getBodyRegion(), symbolTable, config: runtimeConfig);
57
58 acc::OpenACCSupport &accSupport = getAnalysis<acc::OpenACCSupport>();
59 populateACCDataDirectivePatterns(converter, patterns, accSupport,
60 globalSymbolRegion&: module.getBodyRegion(), symbolTable,
61 config: runtimeConfig);
62 populateACCHostDataPatterns(converter, patterns, globalSymbolRegion&: module.getBodyRegion(),
63 symbolTable, config: runtimeConfig);
64 populateACCKernelLaunchPatterns(converter, patterns, accSupport,
65 globalSymbolRegion&: module.getBodyRegion(), symbolTable,
66 config: runtimeConfig);
67 populateACCAtomicPatterns(converter, patterns, accSupport);
68 populateACCDataClauseOpPatterns(converter, patterns, accSupport,
69 globalSymbolRegion&: module.getBodyRegion(), symbolTable,
70 config: runtimeConfig);
71
72 LLVMConversionTarget target(getContext());
73 configureACCExecutableDirectiveConversionLegality(target);
74 configureACCDataDirectiveConversionLegality(target);
75 configureACCHostDataConversionLegality(target);
76 configureACCKernelLaunchConversionLegality(target);
77 configureACCAtomicConversionLegality(target);
78 if (failed(Result: applyPartialConversion(op: module, target, patterns: std::move(patterns))))
79 signalPassFailure();
80}
81