[flang-commits] [flang] 3e0f6b2 - [flang][hlfir] clean up intrinsic arg extended values

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Fri Mar 17 02:30:54 PDT 2023


Author: Tom Eccles
Date: 2023-03-17T09:30:04Z
New Revision: 3e0f6b2eb4699e37cc7009d0a2056d85ca15d64c

URL: https://github.com/llvm/llvm-project/commit/3e0f6b2eb4699e37cc7009d0a2056d85ca15d64c
DIFF: https://github.com/llvm/llvm-project/commit/3e0f6b2eb4699e37cc7009d0a2056d85ca15d64c.diff

LOG: [flang][hlfir] clean up intrinsic arg extended values

Depends on D145502

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D145503

Added: 
    

Modified: 
    flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
index eac0621431737..59e5b3b53c6ac 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
@@ -57,6 +57,7 @@ class HlfirIntrinsicConversion : public mlir::OpRewritePattern<OP> {
     fir::FirOpBuilder builder{rewriter, kindMapping};
 
     llvm::SmallVector<fir::ExtendedValue, 3> ret;
+    llvm::SmallVector<std::function<void()>, 2> cleanupFns;
 
     for (size_t i = 0; i < args.size(); ++i) {
       mlir::Value arg = args[i].val;
@@ -77,21 +78,21 @@ class HlfirIntrinsicConversion : public mlir::OpRewritePattern<OP> {
         }
         auto [exv, cleanup] = hlfir::convertToValue(loc, builder, entity);
         if (cleanup)
-          TODO(loc, "extended value cleanup");
+          cleanupFns.push_back(*cleanup);
         ret.emplace_back(exv);
       } break;
       case fir::LowerIntrinsicArgAs::Addr: {
         auto [exv, cleanup] =
             hlfir::convertToAddress(loc, builder, entity, desiredType);
         if (cleanup)
-          TODO(loc, "extended value cleanup");
+          cleanupFns.push_back(*cleanup);
         ret.emplace_back(exv);
       } break;
       case fir::LowerIntrinsicArgAs::Box: {
         auto [box, cleanup] =
             hlfir::convertToBox(loc, builder, entity, desiredType);
         if (cleanup)
-          TODO(loc, "extended value cleanup");
+          cleanupFns.push_back(*cleanup);
         ret.emplace_back(box);
       } break;
       case fir::LowerIntrinsicArgAs::Inquired: {
@@ -109,12 +110,20 @@ class HlfirIntrinsicConversion : public mlir::OpRewritePattern<OP> {
         auto [exv, cleanup] =
             hlfir::translateToExtendedValue(loc, builder, entity);
         if (cleanup)
-          TODO(loc, "extended value cleanup");
+          cleanupFns.push_back(*cleanup);
         ret.emplace_back(exv);
       } break;
       }
     }
 
+    if (cleanupFns.size()) {
+      auto oldInsertionPoint = builder.saveInsertionPoint();
+      builder.setInsertionPointAfter(op);
+      for (std::function<void()> cleanup : cleanupFns)
+        cleanup();
+      builder.restoreInsertionPoint(oldInsertionPoint);
+    }
+
     return ret;
   }
 


        


More information about the flang-commits mailing list