Skip to content

[mlir][Flang][NFC] Replace use of vector.insertelement/extractelement #143272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flang/include/flang/Optimizer/Support/InitFIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "mlir/Dialect/Affine/Passes.h"
#include "mlir/Dialect/Complex/IR/Complex.h"
#include "mlir/Dialect/Func/Extensions/InlinerExtension.h"
#include "mlir/Dialect/Index/IR/IndexDialect.h"
#include "mlir/Dialect/LLVMIR/NVVMDialect.h"
#include "mlir/Dialect/OpenACC/Transforms/Passes.h"
#include "mlir/Dialect/SCF/Transforms/Passes.h"
Expand All @@ -41,7 +42,8 @@ namespace fir::support {
mlir::cf::ControlFlowDialect, mlir::func::FuncDialect, \
mlir::vector::VectorDialect, mlir::math::MathDialect, \
mlir::complex::ComplexDialect, mlir::DLTIDialect, cuf::CUFDialect, \
mlir::NVVM::NVVMDialect, mlir::gpu::GPUDialect
mlir::NVVM::NVVMDialect, mlir::gpu::GPUDialect, \
mlir::index::IndexDialect

#define FLANG_CODEGEN_DIALECT_LIST FIRCodeGenDialect, mlir::LLVM::LLVMDialect

Expand Down
11 changes: 8 additions & 3 deletions flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "flang/Evaluate/common.h"
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/MutableBox.h"
#include "mlir/Dialect/Index/IR/IndexOps.h"
#include "mlir/Dialect/Vector/IR/VectorOps.h"

namespace fir {
Expand Down Expand Up @@ -1685,7 +1686,9 @@ PPCIntrinsicLibrary::genVecExtract(mlir::Type resultType,
if (!isNativeVecElemOrderOnLE())
uremOp = convertVectorElementOrder(builder, loc, vecTyInfo, uremOp);

return builder.create<mlir::vector::ExtractElementOp>(loc, varg0, uremOp);
mlir::Value index = builder.createOrFold<mlir::index::CastUOp>(
loc, builder.getIndexType(), uremOp);
return builder.create<mlir::vector::ExtractOp>(loc, varg0, index);
}

// VEC_INSERT
Expand All @@ -1706,8 +1709,10 @@ PPCIntrinsicLibrary::genVecInsert(mlir::Type resultType,
if (!isNativeVecElemOrderOnLE())
uremOp = convertVectorElementOrder(builder, loc, vecTyInfo, uremOp);

auto res{builder.create<mlir::vector::InsertElementOp>(loc, argBases[0],
varg1, uremOp)};
mlir::Value index = builder.createOrFold<mlir::index::CastUOp>(
loc, builder.getIndexType(), uremOp);
mlir::Value res =
builder.create<mlir::vector::InsertOp>(loc, argBases[0], varg1, index);
return builder.create<fir::ConvertOp>(loc, vecTyInfo.toFirVectorType(), res);
}

Expand Down
1 change: 1 addition & 0 deletions flang/lib/Optimizer/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_flang_library(FIRCodeGen
MLIRComplexToLLVM
MLIRComplexToStandard
MLIRGPUDialect
MLIRIndexToLLVM
MLIRMathToFuncs
MLIRMathToLLVM
MLIRMathToLibm
Expand Down
2 changes: 2 additions & 0 deletions flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mlir/Conversion/ComplexToStandard/ComplexToStandard.h"
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
#include "mlir/Conversion/LLVMCommon/Pattern.h"
#include "mlir/Conversion/MathToFuncs/MathToFuncs.h"
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
Expand Down Expand Up @@ -4198,6 +4199,7 @@ class FIRToLLVMLowering
if (!isAMDGCN)
mlir::populateMathToLibmConversionPatterns(pattern);
mlir::populateComplexToLLVMConversionPatterns(typeConverter, pattern);
mlir::index::populateIndexToLLVMConversionPatterns(typeConverter, pattern);
mlir::populateVectorToLLVMConversionPatterns(typeConverter, pattern);

// Flang specific overloads for OpenMP operations, to allow for special
Expand Down
Loading