[flang-commits] [flang] [flang] Initial debug info support for local variables. (PR #90905)
via flang-commits
flang-commits at lists.llvm.org
Fri May 3 05:51:23 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:
Maybe this should only be created if there is a DILocalVariableAttr fused with the location of the DeclareOp.
Creating MLIR operations, especially with many arguments, has a compile time cost (both memory and time), so I would be inclined to start by only doing it when we know it is needed, which is easy here currently. That way, there is no extra compile time cost for filed compiled without -g.
Future use cases can enable this translation when they arise.
https://github.com/llvm/llvm-project/pull/90905
More information about the flang-commits
mailing list