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

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Fri May 3 10:42:15 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:

The argNo value we pass will determine the order in which debugger will show the variables.

```
function fn1(c1, a1, b1) result (res1)
...
end function

(GDB) frame
#0  fn1 (c1=.FALSE., a1=1, b1=2.1000000000000001) at ../test1.f90:20

```
You were right that `DeclareOP` were in alphabetical order. I have now used `BlockArgument::getArgNumber` and it seems to return the correct order value. I am also using cast to BlockArgument to check if it is a dummy argument. But the problem of argument cooking in certain cases remain. I added a FIXME for that. Once I know all the cases where it can happen, it probably should not be too difficult to handle.

>From inlining, you mean inlining that can happen before we process `DeclareOp` or after. If it happens after then I think it is up to that pass to adjust any metadata accordingly. Are there instances where inlining will happen before `AddDebugInfo` runs?

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


More information about the flang-commits mailing list