[flang-commits] [flang] 677f7cc - [mlir][flang][openacc] Remove obsolete operand legalization passes
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu May 11 10:33:22 PDT 2023
Author: Valentin Clement
Date: 2023-05-11T10:33:00-07:00
New Revision: 677f7cc55a3f21498e17a0c3e29d4cc126c0dc21
URL: https://github.com/llvm/llvm-project/commit/677f7cc55a3f21498e17a0c3e29d4cc126c0dc21
DIFF: https://github.com/llvm/llvm-project/commit/677f7cc55a3f21498e17a0c3e29d4cc126c0dc21.diff
LOG: [mlir][flang][openacc] Remove obsolete operand legalization passes
The information needed for translation is now encoded in the dialect
operations and does not require a dedicated pass to be extracted.
Remove the obsolete passes that were performing operand legalization.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D150248
Added:
Modified:
flang/include/flang/Optimizer/Transforms/Passes.h
flang/include/flang/Optimizer/Transforms/Passes.td
flang/lib/Optimizer/CodeGen/CMakeLists.txt
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/lib/Optimizer/Transforms/CMakeLists.txt
mlir/include/mlir/Conversion/Passes.h
mlir/include/mlir/Conversion/Passes.td
mlir/lib/Conversion/CMakeLists.txt
mlir/lib/Target/LLVMIR/Dialect/OpenACC/CMakeLists.txt
mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
Removed:
flang/lib/Optimizer/Transforms/OpenACC/OpenACCDataOperandConversion.cpp
mlir/include/mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h
mlir/lib/Conversion/OpenACCToLLVM/CMakeLists.txt
mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
################################################################################
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h
index 863e0df1e7373..93f78f0646e00 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -72,7 +72,6 @@ std::unique_ptr<mlir::Pass> createAlgebraicSimplificationPass();
std::unique_ptr<mlir::Pass>
createAlgebraicSimplificationPass(const mlir::GreedyRewriteConfig &config);
std::unique_ptr<mlir::Pass> createPolymorphicOpConversionPass();
-std::unique_ptr<mlir::Pass> createOpenACCDataOperandConversionPass();
// declarative passes
#define GEN_PASS_REGISTRATION
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index e7a7c61b47972..b4cae024248ba 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -286,16 +286,6 @@ def PolymorphicOpConversion : Pass<"fir-polymorphic-op", "::mlir::func::FuncOp">
];
}
-def OpenACCDataOperandConversion : Pass<"fir-openacc-data-operand-conversion", "::mlir::func::FuncOp"> {
- let summary = "Convert the FIR operands in OpenACC ops to LLVM dialect";
- let dependentDialects = ["mlir::LLVM::LLVMDialect"];
- let options = [
- Option<"useOpaquePointers", "use-opaque-pointers", "bool",
- /*default=*/"true", "Generate LLVM IR using opaque pointers "
- "instead of typed pointers">,
- ];
-}
-
def LoopVersioning : Pass<"loop-versioning", "mlir::func::FuncOp"> {
let summary = "Loop Versioning";
let description = [{
diff --git a/flang/lib/Optimizer/CodeGen/CMakeLists.txt b/flang/lib/Optimizer/CodeGen/CMakeLists.txt
index 1d65e1de6df4c..016544ef870a5 100644
--- a/flang/lib/Optimizer/CodeGen/CMakeLists.txt
+++ b/flang/lib/Optimizer/CodeGen/CMakeLists.txt
@@ -23,7 +23,6 @@ add_flang_library(FIRCodeGen
MLIRMathToFuncs
MLIRMathToLLVM
MLIRMathToLibm
- MLIROpenACCToLLVM
MLIROpenMPToLLVM
MLIRBuiltinToLLVMIRTranslation
MLIRLLVMToLLVMIRTranslation
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index c96ce573e9c4d..f3565c04abcb8 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -31,7 +31,6 @@
#include "mlir/Conversion/MathToFuncs/MathToFuncs.h"
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
#include "mlir/Conversion/MathToLibm/MathToLibm.h"
-#include "mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h"
#include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h"
#include "mlir/Conversion/ReconcileUnrealizedCasts/ReconcileUnrealizedCasts.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -3690,7 +3689,6 @@ class FIRToLLVMLowering
XEmboxOpConversion, XReboxOpConversion, ZeroOpConversion>(typeConverter,
options);
mlir::populateFuncToLLVMConversionPatterns(typeConverter, pattern);
- mlir::populateOpenACCToLLVMConversionPatterns(typeConverter, pattern);
mlir::populateOpenMPToLLVMConversionPatterns(typeConverter, pattern);
mlir::arith::populateArithToLLVMConversionPatterns(typeConverter, pattern);
mlir::cf::populateControlFlowToLLVMConversionPatterns(typeConverter,
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index 3f63035a92987..932914e12a231 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -15,7 +15,6 @@ add_flang_library(FIRTransforms
SimplifyIntrinsics.cpp
AddDebugFoundation.cpp
PolymorphicOpConversion.cpp
- OpenACC/OpenACCDataOperandConversion.cpp
LoopVersioning.cpp
DEPENDS
diff --git a/flang/lib/Optimizer/Transforms/OpenACC/OpenACCDataOperandConversion.cpp b/flang/lib/Optimizer/Transforms/OpenACC/OpenACCDataOperandConversion.cpp
deleted file mode 100644
index de28a8f3872cc..0000000000000
--- a/flang/lib/Optimizer/Transforms/OpenACC/OpenACCDataOperandConversion.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-//===- OpenACCDataOperandConversion.cpp - OpenACC data operand conversion -===//
-//
-// 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 "flang/Optimizer/Dialect/FIRDialect.h"
-#include "flang/Optimizer/Transforms/Passes.h"
-#include "mlir/Conversion/LLVMCommon/Pattern.h"
-#include "mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h"
-#include "mlir/Dialect/Func/IR/FuncOps.h"
-#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
-#include "mlir/Dialect/OpenACC/OpenACC.h"
-#include "mlir/IR/Builders.h"
-#include "mlir/IR/BuiltinOps.h"
-#include "mlir/Pass/Pass.h"
-
-namespace fir {
-#define GEN_PASS_DEF_OPENACCDATAOPERANDCONVERSION
-#include "flang/Optimizer/Transforms/Passes.h.inc"
-} // namespace fir
-
-#define DEBUG_TYPE "flang-openacc-conversion"
-#include "flang/Optimizer/CodeGen/TypeConverter.h"
-
-using namespace fir;
-using namespace mlir;
-
-//===----------------------------------------------------------------------===//
-// Conversion patterns
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-template <typename Op>
-class LegalizeDataOpForLLVMTranslation : public ConvertOpToLLVMPattern<Op> {
- using ConvertOpToLLVMPattern<Op>::ConvertOpToLLVMPattern;
-
- LogicalResult
- matchAndRewrite(Op op, typename Op::Adaptor adaptor,
- ConversionPatternRewriter &builder) const override {
- Location loc = op.getLoc();
- fir::LLVMTypeConverter &converter =
- *static_cast<fir::LLVMTypeConverter *>(this->getTypeConverter());
-
- unsigned numDataOperands = op.getNumDataOperands();
-
- // Keep the non data operands without modification.
- auto nonDataOperands = adaptor.getOperands().take_front(
- adaptor.getOperands().size() - numDataOperands);
- SmallVector<Value> convertedOperands;
- convertedOperands.append(nonDataOperands.begin(), nonDataOperands.end());
-
- // Go over the data operand and legalize them for translation.
- for (unsigned idx = 0; idx < numDataOperands; ++idx) {
- Value originalDataOperand = op.getDataOperand(idx);
- if (auto refTy =
- originalDataOperand.getType().dyn_cast<fir::ReferenceType>()) {
- if (refTy.getEleTy().isa<fir::BaseBoxType>())
- return builder.notifyMatchFailure(op, "BaseBoxType not supported");
- mlir::Type convertedType =
- converter.convertType(refTy).cast<mlir::LLVM::LLVMPointerType>();
- mlir::Value castedOperand =
- builder
- .create<mlir::UnrealizedConversionCastOp>(loc, convertedType,
- originalDataOperand)
- .getResult(0);
- convertedOperands.push_back(castedOperand);
- } else {
- // Type not supported.
- return builder.notifyMatchFailure(op, "expecting a reference type");
- }
- }
-
- if constexpr (std::is_same_v<Op, acc::ParallelOp> ||
- std::is_same_v<Op, acc::DataOp>) {
- auto newOp =
- builder.create<Op>(op.getLoc(), TypeRange(), convertedOperands,
- op.getOperation()->getAttrs());
- builder.inlineRegionBefore(op.getRegion(), newOp.getRegion(),
- newOp.getRegion().end());
- if (failed(builder.convertRegionTypes(&newOp.getOperation()->getRegion(0),
- *this->getTypeConverter())))
- return failure();
- builder.eraseOp(op);
- } else {
- builder.replaceOpWithNewOp<Op>(op, TypeRange(), convertedOperands,
- op.getOperation()->getAttrs());
- }
-
- return success();
- }
-};
-} // namespace
-
-namespace {
-struct OpenACCDataOperandConversion
- : public fir::impl::OpenACCDataOperandConversionBase<
- OpenACCDataOperandConversion> {
- using Base::Base;
-
- void runOnOperation() override;
-};
-} // namespace
-
-void OpenACCDataOperandConversion::runOnOperation() {
- auto op = getOperation();
- auto *context = op.getContext();
-
- // Convert to OpenACC operations with LLVM IR dialect
- RewritePatternSet patterns(context);
- LowerToLLVMOptions options(context);
- options.useOpaquePointers = useOpaquePointers;
- fir::LLVMTypeConverter converter(
- op.getOperation()->getParentOfType<mlir::ModuleOp>(), true);
- patterns.add<LegalizeDataOpForLLVMTranslation<acc::ParallelOp>>(converter);
-
- ConversionTarget target(*context);
- target.addLegalDialect<fir::FIROpsDialect>();
- target.addLegalDialect<LLVM::LLVMDialect>();
- target.addLegalOp<mlir::UnrealizedConversionCastOp>();
-
- auto allDataOperandsAreConverted = [](ValueRange operands) {
- for (Value operand : operands) {
- if (!operand.getType().isa<LLVM::LLVMPointerType>())
- return false;
- }
- return true;
- };
-
- target.addDynamicallyLegalOp<acc::ParallelOp>(
- [allDataOperandsAreConverted](acc::ParallelOp op) {
- return allDataOperandsAreConverted(op.getReductionOperands()) &&
- allDataOperandsAreConverted(op.getGangPrivateOperands()) &&
- allDataOperandsAreConverted(op.getGangFirstPrivateOperands());
- });
-
- if (failed(applyPartialConversion(op, target, std::move(patterns))))
- signalPassFailure();
-}
diff --git a/mlir/include/mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h b/mlir/include/mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h
deleted file mode 100644
index 0cbea0c9ef5b6..0000000000000
--- a/mlir/include/mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h
+++ /dev/null
@@ -1,72 +0,0 @@
-//===- ConvertOpenACCToLLVM.h - OpenACC conversion pass entrypoint --------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-#ifndef MLIR_CONVERSION_OPENACCTOLLVM_CONVERTOPENACCTOLLVM_H
-#define MLIR_CONVERSION_OPENACCTOLLVM_CONVERTOPENACCTOLLVM_H
-
-#include "mlir/Conversion/LLVMCommon/StructBuilder.h"
-#include <memory>
-
-namespace mlir {
-class LLVMTypeConverter;
-class Pass;
-class RewritePatternSet;
-
-#define GEN_PASS_DECL_CONVERTOPENACCTOLLVMPASS
-#include "mlir/Conversion/Passes.h.inc"
-
-static constexpr unsigned kPtrBasePosInDataDescriptor = 0;
-static constexpr unsigned kPtrPosInDataDescriptor = 1;
-static constexpr unsigned kSizePosInDataDescriptor = 2;
-
-/// Helper class to produce LLVM dialect operations inserting
-/// elements to a Data descriptor. Wraps a Value pointing to the descriptor.
-/// The Value may be null, in which case none of the operations are valid.
-///
-/// The data descriptor holds information needed to perform data operations
-/// and movements with the runtime.
-/// `BasePointer`: base of the pointer being mapped.
-/// `Pointer`: actual pointer of the data being mapped.
-/// `Size`: size of the data being mapped.
-///
-/// Example:
-///
-/// ```c
-/// struct S {
-/// int x;
-/// int y;
-/// };
-/// ```
-///
-/// Mapping `s.y` will result if the following information in the data
-/// descriptor:
-/// - `BasePointer`: address of `s`
-/// - `Pointer`: address of `s.y`
-/// - `Size`: size of `s.y`
-///
-/// For a scalar variable BasePointer and Pointer will be the same.
-class DataDescriptor : public StructBuilder {
-public:
- /// Construct a helper for the given descriptor value.
- explicit DataDescriptor(Value descriptor);
- /// Builds IR creating an `undef` value of the descriptor type.
- static DataDescriptor undef(OpBuilder &builder, Location loc, Type basePtrTy,
- Type ptrTy);
-
- static bool isValid(Value descriptor);
-
- void setPointer(OpBuilder &builder, Location loc, Value ptr);
- void setBasePointer(OpBuilder &builder, Location loc, Value basePtr);
- void setSize(OpBuilder &builder, Location loc, Value size);
-};
-
-/// Collect the patterns to convert from the OpenACC dialect LLVMIR dialect.
-void populateOpenACCToLLVMConversionPatterns(LLVMTypeConverter &converter,
- RewritePatternSet &patterns);
-} // namespace mlir
-
-#endif // MLIR_CONVERSION_OPENACCTOLLVM_CONVERTOPENACCTOLLVM_H
diff --git a/mlir/include/mlir/Conversion/Passes.h b/mlir/include/mlir/Conversion/Passes.h
index 198e51e3c30e2..ae2fc8464821c 100644
--- a/mlir/include/mlir/Conversion/Passes.h
+++ b/mlir/include/mlir/Conversion/Passes.h
@@ -40,7 +40,6 @@
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
#include "mlir/Conversion/MemRefToSPIRV/MemRefToSPIRVPass.h"
#include "mlir/Conversion/NVGPUToNVVM/NVGPUToNVVM.h"
-#include "mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h"
#include "mlir/Conversion/OpenACCToSCF/ConvertOpenACCToSCF.h"
#include "mlir/Conversion/OpenMPToLLVM/ConvertOpenMPToLLVM.h"
#include "mlir/Conversion/PDLToPDLInterp/PDLToPDLInterp.h"
diff --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index e14b25a78e569..9e39137d970a8 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -732,20 +732,6 @@ def ConvertOpenACCToSCF : Pass<"convert-openacc-to-scf", "ModuleOp"> {
let dependentDialects = ["scf::SCFDialect", "acc::OpenACCDialect"];
}
-//===----------------------------------------------------------------------===//
-// OpenACCToLLVM
-//===----------------------------------------------------------------------===//
-
-def ConvertOpenACCToLLVMPass : Pass<"convert-openacc-to-llvm", "ModuleOp"> {
- let summary = "Convert the OpenACC ops to LLVM dialect";
- let dependentDialects = ["LLVM::LLVMDialect"];
- let options = [
- Option<"useOpaquePointers", "use-opaque-pointers", "bool",
- /*default=*/"true", "Generate LLVM IR using opaque pointers "
- "instead of typed pointers">,
- ];
-}
-
//===----------------------------------------------------------------------===//
// OpenMPToLLVM
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Conversion/CMakeLists.txt b/mlir/lib/Conversion/CMakeLists.txt
index 5a2683a353780..33efa59a6c066 100644
--- a/mlir/lib/Conversion/CMakeLists.txt
+++ b/mlir/lib/Conversion/CMakeLists.txt
@@ -30,7 +30,6 @@ add_subdirectory(MathToSPIRV)
add_subdirectory(MemRefToLLVM)
add_subdirectory(MemRefToSPIRV)
add_subdirectory(NVGPUToNVVM)
-add_subdirectory(OpenACCToLLVM)
add_subdirectory(OpenACCToSCF)
add_subdirectory(OpenMPToLLVM)
add_subdirectory(PDLToPDLInterp)
diff --git a/mlir/lib/Conversion/OpenACCToLLVM/CMakeLists.txt b/mlir/lib/Conversion/OpenACCToLLVM/CMakeLists.txt
deleted file mode 100644
index 01e2c3fee6374..0000000000000
--- a/mlir/lib/Conversion/OpenACCToLLVM/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-add_mlir_conversion_library(MLIROpenACCToLLVM
- OpenACCToLLVM.cpp
-
- ADDITIONAL_HEADER_DIRS
- ${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/OpenACCToLLVM
-
- DEPENDS
- MLIRConversionPassIncGen
-
- LINK_LIBS PUBLIC
- MLIRIR
- MLIRLLVMDialect
- MLIRMemRefToLLVM
- MLIROpenACCDialect
- MLIRTransforms
- )
diff --git a/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp b/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
deleted file mode 100644
index 6bc52c99e9e52..0000000000000
--- a/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-//===- OpenACCToLLVM.cpp - Prepare OpenACC data for LLVM translation ------===//
-//
-// 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/ConvertOpenACCToLLVM.h"
-
-#include "mlir/Conversion/LLVMCommon/Pattern.h"
-#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
-#include "mlir/Dialect/OpenACC/OpenACC.h"
-#include "mlir/IR/Builders.h"
-#include "mlir/Pass/Pass.h"
-
-namespace mlir {
-#define GEN_PASS_DEF_CONVERTOPENACCTOLLVMPASS
-#include "mlir/Conversion/Passes.h.inc"
-} // namespace mlir
-
-using namespace mlir;
-
-//===----------------------------------------------------------------------===//
-// DataDescriptor implementation
-//===----------------------------------------------------------------------===//
-
-constexpr StringRef getStructName() { return "openacc_data"; }
-
-/// Construct a helper for the given descriptor value.
-DataDescriptor::DataDescriptor(Value descriptor) : StructBuilder(descriptor) {
- assert(value != nullptr && "value cannot be null");
-}
-
-/// Builds IR creating an `undef` value of the data descriptor.
-DataDescriptor DataDescriptor::undef(OpBuilder &builder, Location loc,
- Type basePtrTy, Type ptrTy) {
- Type descriptorType = LLVM::LLVMStructType::getNewIdentified(
- builder.getContext(), getStructName(),
- {basePtrTy, ptrTy, builder.getI64Type()});
- Value descriptor = builder.create<LLVM::UndefOp>(loc, descriptorType);
- return DataDescriptor(descriptor);
-}
-
-/// Check whether the type is a valid data descriptor.
-bool DataDescriptor::isValid(Value descriptor) {
- if (auto type = descriptor.getType().dyn_cast<LLVM::LLVMStructType>()) {
- if (type.isIdentified() && type.getName().startswith(getStructName()) &&
- type.getBody().size() == 3 &&
- (type.getBody()[kPtrBasePosInDataDescriptor]
- .isa<LLVM::LLVMPointerType>() ||
- type.getBody()[kPtrBasePosInDataDescriptor]
- .isa<LLVM::LLVMStructType>()) &&
- type.getBody()[kPtrPosInDataDescriptor].isa<LLVM::LLVMPointerType>() &&
- type.getBody()[kSizePosInDataDescriptor].isInteger(64))
- return true;
- }
- return false;
-}
-
-/// Builds IR inserting the base pointer value into the descriptor.
-void DataDescriptor::setBasePointer(OpBuilder &builder, Location loc,
- Value basePtr) {
- setPtr(builder, loc, kPtrBasePosInDataDescriptor, basePtr);
-}
-
-/// Builds IR inserting the pointer value into the descriptor.
-void DataDescriptor::setPointer(OpBuilder &builder, Location loc, Value ptr) {
- setPtr(builder, loc, kPtrPosInDataDescriptor, ptr);
-}
-
-/// Builds IR inserting the size value into the descriptor.
-void DataDescriptor::setSize(OpBuilder &builder, Location loc, Value size) {
- setPtr(builder, loc, kSizePosInDataDescriptor, size);
-}
-
-//===----------------------------------------------------------------------===//
-// Conversion patterns
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-template <typename Op>
-class LegalizeDataOpForLLVMTranslation : public ConvertOpToLLVMPattern<Op> {
- using ConvertOpToLLVMPattern<Op>::ConvertOpToLLVMPattern;
-
- LogicalResult
- matchAndRewrite(Op op, typename Op::Adaptor adaptor,
- ConversionPatternRewriter &builder) const override {
- Location loc = op.getLoc();
- TypeConverter *converter = ConvertToLLVMPattern::getTypeConverter();
-
- unsigned numDataOperand = op.getNumDataOperands();
-
- // Keep the non data operands without modification.
- auto nonDataOperands = adaptor.getOperands().take_front(
- adaptor.getOperands().size() - numDataOperand);
- SmallVector<Value> convertedOperands;
- convertedOperands.append(nonDataOperands.begin(), nonDataOperands.end());
-
- // Go over the data operand and legalize them for translation.
- for (unsigned idx = 0; idx < numDataOperand; ++idx) {
- Value originalDataOperand = op.getDataOperand(idx);
-
- // Traverse operands that were converted to MemRefDescriptors.
- if (auto memRefType =
- originalDataOperand.getType().dyn_cast<MemRefType>()) {
- Type structType = converter->convertType(memRefType);
- Value memRefDescriptor = builder
- .create<UnrealizedConversionCastOp>(
- loc, structType, originalDataOperand)
- .getResult(0);
-
- // Calculate the size of the memref and get the pointer to the allocated
- // buffer.
- SmallVector<Value> sizes;
- SmallVector<Value> strides;
- Value sizeBytes;
- ConvertToLLVMPattern::getMemRefDescriptorSizes(
- loc, memRefType, {}, builder, sizes, strides, sizeBytes);
- MemRefDescriptor descriptor(memRefDescriptor);
- Value dataPtr = descriptor.alignedPtr(builder, loc);
- auto ptrType = descriptor.getElementPtrType();
-
- auto descr = DataDescriptor::undef(builder, loc, structType, ptrType);
- descr.setBasePointer(builder, loc, memRefDescriptor);
- descr.setPointer(builder, loc, dataPtr);
- descr.setSize(builder, loc, sizeBytes);
- convertedOperands.push_back(descr);
- } else if (originalDataOperand.getType().isa<LLVM::LLVMPointerType>()) {
- convertedOperands.push_back(originalDataOperand);
- } else {
- // Type not supported.
- return builder.notifyMatchFailure(op, "unsupported type");
- }
- }
-
- if constexpr (std::is_same_v<Op, acc::ParallelOp> ||
- std::is_same_v<Op, acc::DataOp>) {
- auto newOp =
- builder.create<Op>(op.getLoc(), TypeRange(), convertedOperands,
- op.getOperation()->getAttrs());
- builder.inlineRegionBefore(op.getRegion(), newOp.getRegion(),
- newOp.getRegion().end());
- builder.eraseOp(op);
- } else {
- builder.replaceOpWithNewOp<Op>(op, TypeRange(), convertedOperands,
- op.getOperation()->getAttrs());
- }
-
- return success();
- }
-};
-} // namespace
-
-void mlir::populateOpenACCToLLVMConversionPatterns(
- LLVMTypeConverter &converter, RewritePatternSet &patterns) {
- patterns.add<LegalizeDataOpForLLVMTranslation<acc::ParallelOp>>(converter);
-}
-
-namespace {
-struct ConvertOpenACCToLLVMPass
- : public impl::ConvertOpenACCToLLVMPassBase<ConvertOpenACCToLLVMPass> {
- using Base::Base;
-
- void runOnOperation() override;
-};
-} // namespace
-
-void ConvertOpenACCToLLVMPass::runOnOperation() {
- auto op = getOperation();
- auto *context = op.getContext();
-
- // Convert to OpenACC operations with LLVM IR dialect
- RewritePatternSet patterns(context);
- LowerToLLVMOptions options(context);
- options.useOpaquePointers = useOpaquePointers;
- LLVMTypeConverter converter(context, options);
- populateOpenACCToLLVMConversionPatterns(converter, patterns);
-
- ConversionTarget target(*context);
- target.addLegalDialect<LLVM::LLVMDialect>();
- target.addLegalOp<UnrealizedConversionCastOp>();
-
- auto allDataOperandsAreConverted = [](ValueRange operands) {
- for (Value operand : operands) {
- if (!DataDescriptor::isValid(operand) &&
- !operand.getType().isa<LLVM::LLVMPointerType>())
- return false;
- }
- return true;
- };
-
- target.addDynamicallyLegalOp<acc::ParallelOp>(
- [allDataOperandsAreConverted](acc::ParallelOp op) {
- return allDataOperandsAreConverted(op.getReductionOperands()) &&
- allDataOperandsAreConverted(op.getGangPrivateOperands()) &&
- allDataOperandsAreConverted(op.getGangFirstPrivateOperands());
- });
-
- if (failed(applyPartialConversion(op, target, std::move(patterns))))
- signalPassFailure();
-}
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenACC/CMakeLists.txt b/mlir/lib/Target/LLVMIR/Dialect/OpenACC/CMakeLists.txt
index 84997d7648aeb..5e79e4be58f29 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenACC/CMakeLists.txt
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenACC/CMakeLists.txt
@@ -8,7 +8,6 @@ add_mlir_translation_library(MLIROpenACCToLLVMIRTranslation
MLIRIR
MLIRLLVMDialect
MLIROpenACCDialect
- MLIROpenACCToLLVM
MLIRSupport
MLIRTargetLLVMIRExport
)
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
index 90aefac763428..91ff17437bbcf 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "mlir/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.h"
-#include "mlir/Conversion/OpenACCToLLVM/ConvertOpenACCToLLVM.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
#include "mlir/IR/BuiltinOps.h"
@@ -100,14 +99,7 @@ processOperands(llvm::IRBuilderBase &builder,
llvm::Value *dataPtr;
llvm::Value *dataSize;
- // Handle operands that were converted to DataDescriptor.
- if (DataDescriptor::isValid(data)) {
- dataPtrBase =
- builder.CreateExtractValue(dataValue, kPtrBasePosInDataDescriptor);
- dataPtr = builder.CreateExtractValue(dataValue, kPtrPosInDataDescriptor);
- dataSize =
- builder.CreateExtractValue(dataValue, kSizePosInDataDescriptor);
- } else if (data.getType().isa<LLVM::LLVMPointerType>()) {
+ if (data.getType().isa<LLVM::LLVMPointerType>()) {
dataPtrBase = dataValue;
dataPtr = dataValue;
dataSize = accBuilder->getSizeInBytes(dataValue);
More information about the flang-commits
mailing list