[flang-commits] [flang] 8d2cc3b - [flang][NFC] Enable and migrate to new fold API

Markus Böck via flang-commits flang-commits at lists.llvm.org
Wed Jan 11 07:38:29 PST 2023


Author: Markus Böck
Date: 2023-01-11T16:38:07+01:00
New Revision: 8d2cc3b2819c40a62a394462e56ee94326095dbe

URL: https://github.com/llvm/llvm-project/commit/8d2cc3b2819c40a62a394462e56ee94326095dbe
DIFF: https://github.com/llvm/llvm-project/commit/8d2cc3b2819c40a62a394462e56ee94326095dbe.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/CodeGen/CGOps.td
    flang/include/flang/Optimizer/Dialect/FIRDialect.td
    flang/include/flang/Optimizer/HLFIR/HLFIROpBase.td
    flang/lib/Optimizer/Dialect/FIROps.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/CodeGen/CGOps.td b/flang/include/flang/Optimizer/CodeGen/CGOps.td
index d17e4f33bdaa2..7df9fdc421de6 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 40501176a4683..8042670ac76e8 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 d17a4cbf5e1b6..dbcc83a15214a 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 7bee0a229ea3a..579fd8317ca9d 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<mlir::Attribute> opnds) {
+mlir::OpFoldResult fir::BoxAddrOp::fold(FoldAdaptor adaptor) {
   if (auto *v = getVal().getDefiningOp()) {
     if (auto box = mlir::dyn_cast<fir::EmboxOp>(v)) {
       if (!box.getSlice()) // Fold only if not sliced
@@ -616,8 +616,7 @@ mlir::OpFoldResult fir::BoxAddrOp::fold(llvm::ArrayRef<mlir::Attribute> opnds) {
 // BoxCharLenOp
 //===----------------------------------------------------------------------===//
 
-mlir::OpFoldResult
-fir::BoxCharLenOp::fold(llvm::ArrayRef<mlir::Attribute> opnds) {
+mlir::OpFoldResult fir::BoxCharLenOp::fold(FoldAdaptor adaptor) {
   if (auto v = getVal().getDefiningOp()) {
     if (auto box = mlir::dyn_cast<fir::EmboxCharOp>(v))
       return box.getLen();
@@ -885,7 +884,7 @@ void fir::ConvertOp::getCanonicalizationPatterns(
                  ForwardConstantConvertPattern>(context);
 }
 
-mlir::OpFoldResult fir::ConvertOp::fold(llvm::ArrayRef<mlir::Attribute> opnds) {
+mlir::OpFoldResult fir::ConvertOp::fold(FoldAdaptor adaptor) {
   if (getValue().getType() == getType())
     return getValue();
   if (matchPattern(getValue(), mlir::m_Op<fir::ConvertOp>())) {


        


More information about the flang-commits mailing list