Skip to content

Commit 0aaf634

Browse files
Move DBG_VALUE's that depend on loads to after a
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
1 parent 144562e commit 0aaf634

File tree

6 files changed

+918
-10
lines changed

6 files changed

+918
-10
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/StringRef.h"
2222
#include "llvm/ADT/iterator_range.h"
23+
#include "llvm/CodeGen/MachineInstr.h"
2324
#include "llvm/IR/Constants.h"
2425
#include "llvm/IR/Metadata.h"
2526
#include "llvm/Support/Casting.h"
@@ -3770,6 +3771,10 @@ class DebugVariable {
37703771
Fragment(DIExpr ? DIExpr->getFragmentInfo() : std::nullopt),
37713772
InlinedAt(InlinedAt) {}
37723773

3774+
DebugVariable(const MachineInstr *MI)
3775+
: DebugVariable(MI->getDebugVariable(), MI->getDebugExpression(),
3776+
MI->getDebugLoc()->getInlinedAt()) {}
3777+
37733778
const DILocalVariable *getVariable() const { return Variable; }
37743779
std::optional<FragmentInfo> getFragment() const { return Fragment; }
37753780
const DILocation *getInlinedAt() const { return InlinedAt; }

0 commit comments

Comments
 (0)