mirror-llvm-project/mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVM.cpp
Razvan Lupusoru 71e5cb7526
[mlir][acc] Introduce ACCToLLVM and executable directive codegen (#213165)
Adds initial infrastructure for converting the acc dialect to LLVM,
specifically around generating libacctarget runtime calls. The current
libacctarget APIs are not yet finalized, but the draft proposal can be
found at https://github.com/llvm/llvm-project/pull/197894. This PR adds
codegen for acc init, shutdown, set, and wait.
2026-07-31 11:04:46 -07:00

53 lines
1.9 KiB
C++

//===- ACCToLLVM.cpp - Convert OpenACC to LLVM dialect ----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Conversion/OpenACCToLLVM/ACCToLLVM.h"
#include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h"
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Pass/Pass.h"
namespace mlir {
#define GEN_PASS_DEF_CONVERTACCTOLLVMPASS
#include "mlir/Conversion/Passes.h.inc"
} // namespace mlir
using namespace mlir;
namespace {
struct ConvertACCToLLVMPass
: public impl::ConvertACCToLLVMPassBase<ConvertACCToLLVMPass> {
using Base::Base;
void runOnOperation() override;
};
} // namespace
void ConvertACCToLLVMPass::runOnOperation() {
ModuleOp module = getOperation();
LLVMTypeConverter converter(&getContext());
RewritePatternSet patterns(&getContext());
arith::populateArithToLLVMConversionPatterns(converter, patterns);
cf::populateControlFlowToLLVMConversionPatterns(converter, patterns);
populateFuncToLLVMConversionPatterns(converter, patterns);
// The device_type numbering is implementation-defined by the target
// runtime. For now assume the same numbering as the OpenACC dialect.
acc::ACCRuntimeCallConfig runtimeConfig;
acc::populateDialectIdentityDeviceTypeMapping(runtimeConfig);
populateACCExecutableDirectivePatterns(converter, patterns, runtimeConfig);
LLVMConversionTarget target(getContext());
configureACCExecutableDirectiveConversionLegality(target);
if (failed(applyPartialConversion(module, target, std::move(patterns))))
signalPassFailure();
}