[flang-commits] [flang] [flang] Initial debug info support for local variables. (PR #90905)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Tue May 7 08:21:04 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);
----------------
abidh wrote:

Thanks. I looked at the IR in such case and it seems that function that gets inlined loses any `FuncOp`. Name in `DeclareOp` and `CallSiteLoc` may provide some clues but work will be required to retain enough information during inlining to enable `AddDebugInfo` to do its job. In any case, our first target should be to get the debug working with -O0. 

https://github.com/llvm/llvm-project/pull/90905


More information about the flang-commits mailing list