[flang-commits] [flang] [flang] Initial debug info support for local variables. (PR #90905)
via flang-commits
flang-commits at lists.llvm.org
Mon May 6 01:17:10 PDT 2024
================
@@ -276,7 +276,29 @@ class DeclareOpConversion : public mlir::OpRewritePattern<fir::DeclareOp> {
mlir::LogicalResult
matchAndRewrite(fir::DeclareOp declareOp,
mlir::PatternRewriter &rewriter) const override {
- rewriter.replaceOp(declareOp, declareOp.getMemref());
+ auto loc = declareOp.getLoc();
+ llvm::SmallVector<mlir::Value> shapeOpers;
+ llvm::SmallVector<mlir::Value> shiftOpers;
+ if (auto shapeVal = declareOp.getShape()) {
+ if (auto shapeOp = mlir::dyn_cast<fir::ShapeOp>(shapeVal.getDefiningOp()))
+ populateShape(shapeOpers, shapeOp);
+ else if (auto shiftOp =
+ mlir::dyn_cast<fir::ShapeShiftOp>(shapeVal.getDefiningOp()))
+ populateShapeAndShift(shapeOpers, shiftOpers, shiftOp);
+ else if (auto shiftOp =
+ mlir::dyn_cast<fir::ShiftOp>(shapeVal.getDefiningOp()))
+ populateShift(shiftOpers, shiftOp);
+ else
+ return mlir::failure();
+ }
+ // FIXME: Add FortranAttrs and CudaAttrs
+ auto xDeclOp = rewriter.create<fir::cg::XDeclareOp>(
+ loc, declareOp.getType(), declareOp.getMemref(), shapeOpers, shiftOpers,
----------------
jeanPerier wrote:
Good point. I think adding a pass option "preserveDeclare" to pre-cg-rewrite passwould be simpler and cheaper then. It can be set in createDefaultFIRCodeGenPassPipeline [here](https://github.com/llvm/llvm-project/blob/37f3661f4e8d180dc702ab42fa015bc3c21ceb51/flang/include/flang/Tools/CLOptions.inc#L308) given the debug level.
https://github.com/llvm/llvm-project/pull/90905
More information about the flang-commits
mailing list