From 8d2cc3b2819c40a62a394462e56ee94326095dbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Markus=20B=C3=B6ck?= Date: Wed, 11 Jan 2023 16:13:14 +0100 Subject: [PATCH] [flang][NFC] Enable and migrate to new fold API See https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618 for context This simply ports all dialects in flang to use the new fold API. These were relatively little and basically just a function signature change, since in-tree folds did not make use of any of the constant operands values. Differential Revision: https://reviews.llvm.org/D141488 --- flang/include/flang/Optimizer/CodeGen/CGOps.td | 1 + flang/include/flang/Optimizer/Dialect/FIRDialect.td | 1 + flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td | 1 + flang/lib/Optimizer/Dialect/FIROps.cpp | 7 +++---- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flang/include/flang/Optimizer/CodeGen/CGOps.td b/flang/include/flang/Optimizer/CodeGen/CGOps.td index d17e4f3..7df9fdc 100644 --- a/flang/include/flang/Optimizer/CodeGen/CGOps.td +++ b/flang/include/flang/Optimizer/CodeGen/CGOps.td @@ -20,6 +20,7 @@ include "flang/Optimizer/Dialect/FIRTypes.td" def fircg_Dialect : Dialect { let name = "fircg"; let cppNamespace = "::fir::cg"; + let useFoldAPI = kEmitFoldAdaptorFolder; } // Base class for FIR CG operations. diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.td b/flang/include/flang/Optimizer/Dialect/FIRDialect.td index 4050117..8042670 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRDialect.td +++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.td @@ -31,6 +31,7 @@ def fir_Dialect : Dialect { // supported by some FIR operations. "arith::ArithDialect" ]; + let useFoldAPI = kEmitFoldAdaptorFolder; } #endif // FORTRAN_DIALECT_FIR_DIALECT diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td index d17a4cb..dbcc83a 100644 --- a/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td @@ -39,6 +39,7 @@ def hlfir_Dialect : Dialect { let useDefaultTypePrinterParser = 1; let cppNamespace = "hlfir"; + let useFoldAPI = kEmitFoldAdaptorFolder; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index 7bee0a2..579fd83 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -600,7 +600,7 @@ mlir::LogicalResult fir::ArrayModifyOp::verify() { // BoxAddrOp //===----------------------------------------------------------------------===// -mlir::OpFoldResult fir::BoxAddrOp::fold(llvm::ArrayRef opnds) { +mlir::OpFoldResult fir::BoxAddrOp::fold(FoldAdaptor adaptor) { if (auto *v = getVal().getDefiningOp()) { if (auto box = mlir::dyn_cast(v)) { if (!box.getSlice()) // Fold only if not sliced @@ -616,8 +616,7 @@ mlir::OpFoldResult fir::BoxAddrOp::fold(llvm::ArrayRef opnds) { // BoxCharLenOp //===----------------------------------------------------------------------===// -mlir::OpFoldResult -fir::BoxCharLenOp::fold(llvm::ArrayRef opnds) { +mlir::OpFoldResult fir::BoxCharLenOp::fold(FoldAdaptor adaptor) { if (auto v = getVal().getDefiningOp()) { if (auto box = mlir::dyn_cast(v)) return box.getLen(); @@ -885,7 +884,7 @@ void fir::ConvertOp::getCanonicalizationPatterns( ForwardConstantConvertPattern>(context); } -mlir::OpFoldResult fir::ConvertOp::fold(llvm::ArrayRef opnds) { +mlir::OpFoldResult fir::ConvertOp::fold(FoldAdaptor adaptor) { if (getValue().getType() == getType()) return getValue(); if (matchPattern(getValue(), mlir::m_Op())) { -- 2.7.4