Skip to content

Commit

Permalink
Move DBG_VALUE's that depend on loads to after a
Browse files Browse the repository at this point in the history
load if the load is moved due to the pre register allocation ld/st
optimization pass

The issue here is that there can be a scenario where debug information
is lost because of the pre register allocation load store optimization
pass, where a load who's result describes the debug infomation for a
local variable gets moved below the load and that causes the debug
information for that load to get lost.

Example:

Before the Pre Register Allocation Load Store Pass
inst_a
%2 = ld ...
inst_b
DBG_VALUE %2, "x", ...
%3 = ld ...

After the Pass:
inst_a
inst_b
DBG_VALUE %2, "x", ...
%2 = ld ...
%3 = ld ...

The load has now been moved to after the DBG_VAL that uses its result
and the debug info for "x" has been lost. What we want is:

inst_a
inst_b
%2 = ld ...
DBG_VALUE %2, "x", ...
%3 = ld ...

Which is what this patch addresses

Differential Revision: https://reviews.llvm.org/D145168
  • Loading branch information
rastogishubham committed Apr 12, 2023
1 parent 144562e commit 0aaf634
Show file tree
Hide file tree
Showing 6 changed files with 918 additions and 10 deletions.
5 changes: 5 additions & 0 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Expand Up @@ -20,6 +20,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Casting.h"
Expand Down Expand Up @@ -3770,6 +3771,10 @@ class DebugVariable {
Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
InlinedAt(InlinedAt) {}

DebugVariable(const MachineInstr *MI)
: DebugVariable(MI->getDebugVariable(), MI->getDebugExpression(),
MI->getDebugLoc()->getInlinedAt()) {}

const DILocalVariable *getVariable() const { return Variable; }
std::optional<FragmentInfo> getFragment() const { return Fragment; }
const DILocation *getInlinedAt() const { return InlinedAt; }
Expand Down

0 comments on commit 0aaf634

Please sign in to comment.