[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
================
@@ -45,13 +46,44 @@ namespace fir {
namespace {
class AddDebugInfoPass : public fir::impl::AddDebugInfoBase<AddDebugInfoPass> {
+ void handleDeclareOp(fir::cg::XDeclareOp declOp,
+ mlir::LLVM::DIFileAttr fileAttr,
+ mlir::LLVM::DIScopeAttr scopeAttr,
+ fir::DebugTypeGenerator &typeGen, uint32_t &argNo);
+
public:
AddDebugInfoPass(fir::AddDebugInfoOptions options) : Base(options) {}
void runOnOperation() override;
};
+static uint32_t getLineFromLoc(mlir::Location loc) {
+ uint32_t line = 1;
+ if (auto fileLoc = mlir::dyn_cast<mlir::FileLineColLoc>(loc))
+ line = fileLoc.getLine();
+ return line;
+}
+
} // namespace
+void AddDebugInfoPass::handleDeclareOp(fir::cg::XDeclareOp declOp,
+ mlir::LLVM::DIFileAttr fileAttr,
+ mlir::LLVM::DIScopeAttr scopeAttr,
+ fir::DebugTypeGenerator &typeGen,
+ uint32_t &argNo) {
+ mlir::MLIRContext *context = &getContext();
+ mlir::OpBuilder builder(context);
+
+ bool isLocal = (declOp.getMemref().getDefiningOp() != nullptr);
+ auto tyAttr = typeGen.convertType(fir::unwrapRefType(declOp.getType()),
+ fileAttr, scopeAttr, declOp.getLoc());
+ auto result = fir::NameUniquer::deconstruct(declOp.getUniqName());
----------------
jeanPerier wrote:
Some hlfir/fir.declare are created for compiler generated temporary. It is useful to treat them as Fortran variables in lowering/FIR, but I do not think we want debug info for those (the name could conflict with user variables).
So I think the location should only get a DILocalVariableAttr if `result.second == fir::NameUniquer::NameKind::VARIABLE`.
https://github.com/llvm/llvm-project/pull/90905
More information about the flang-commits
mailing list