[all-commits] [llvm/llvm-project] 584306: [CodeExtractor] Improve debug info for input value...

Abid Qadeer via All-commits all-commits at lists.llvm.org
Sat Apr 26 02:13:05 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 58430692fc15545e4e74103033498ba0464785f1
      https://github.com/llvm/llvm-project/commit/58430692fc15545e4e74103033498ba0464785f1
  Author: Abid Qadeer <haqadeer at amd.com>
  Date:   2025-04-26 (Sat, 26 Apr 2025)

  Changed paths:
    M llvm/include/llvm/Transforms/Utils/CodeExtractor.h
    M llvm/lib/Transforms/Utils/CodeExtractor.cpp
    M llvm/test/Transforms/CodeExtractor/LoopExtractor_alloca.ll
    A llvm/test/Transforms/CodeExtractor/input-value-debug.ll
    M llvm/test/Transforms/HotColdSplit/transfer-debug-info.ll
    M llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp

  Log Message:
  -----------
  [CodeExtractor] Improve debug info for input values. (#136016)

If we use `CodeExtractor` to extract the block1 into a new function,

```
define void @foo() !dbg !2 {
entry:
  %1 = alloca i32, i64 1, align 4
  %2 = alloca i32, i64 1, align 4
  #dbg_declare(ptr %1, !8, !DIExpression(), !1)
  br label %block1

block1:
  store i32 1, ptr %1, align 4
  store i32 2, ptr %2, align 4
  #dbg_declare(ptr %2, !10, !DIExpression(), !1)
  ret void
}
```

it will look like the extracted function shown below (with some
irrelevent details removed).

```
define internal void @extracted(ptr %arg0, ptr %arg1) { 
newFuncRoot:
  br label %block1

block1:
  store i32 1, ptr %arg0, align 4
  store i32 2, ptr %arg1, align 4
  ret void
}
```

You will notice that it has replaced the usage of values that were in
the parent function (%1 and %2) with the arguments to the new function.
But it did not do the same thing with `#dbg_declare` which was simply
dropped because its location pointed to a value outside of the new
function. Similarly arg0 is without any debug record, although the value
that it replaced had one and we could materialize one for it based on
that.

This is not just a theoretical limitations. `CodeExtractor` is used to
create functions that implement many of the `OpenMP` constructs in
`OMPIRBuilder`. As a result of these limitations, the debug information
is missing from the created functions.

This PR tries to address this problem. It iterates over the input to the
extracted function and looks at their debug uses. If they were present
in the new function, it updates their location. Otherwise it materialize
a similar usage in the new function.

Most of these changes are localized in `fixupDebugInfoPostExtraction`.
Only other change is to propagate function inputs and the replacement
values to it.

---------

Co-authored-by: Tim Gymnich <tim at gymni.ch>
Co-authored-by: Michael Kruse <llvm-project at meinersbur.de>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list