Skip to content

Commit

Permalink
[SelectionDAG][DebugInfo] Implement translation of entry_value vars
Browse files Browse the repository at this point in the history
This commit implements SelectionDAG lowering of dbg.declare intrinsics targeting
swiftasync Arguments, by putting them in the MachineFunction's table of
variables whose location doesn't change throughout the function.

Depends on D149882

Differential Revision: https://reviews.llvm.org/D149883
  • Loading branch information
felipepiovezan committed May 12, 2023
1 parent 53a4adc commit 2da2995
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,30 @@ static bool isFoldedOrDeadInstruction(const Instruction *I,
!FuncInfo.isExportedInst(I); // Exported instrs must be computed.
}

static bool processIfEntryValueDbgDeclare(FunctionLoweringInfo &FuncInfo,
const Value *Arg, DIExpression *Expr,
DILocalVariable *Var,
DebugLoc DbgLoc) {
if (!Expr->isEntryValue() || !isa<Argument>(Arg))
return false;

auto ArgIt = FuncInfo.ValueMap.find(Arg);
if (ArgIt == FuncInfo.ValueMap.end())
return false;
Register ArgVReg = ArgIt->getSecond();

// Find the corresponding livein physical register to this argument.
for (auto [PhysReg, VirtReg] : FuncInfo.RegInfo->liveins())
if (VirtReg == ArgVReg) {
FuncInfo.MF->setVariableDbgInfo(Var, Expr, PhysReg, DbgLoc);
LLVM_DEBUG(dbgs() << "processDbgDeclare: setVariableDbgInfo Var=" << *Var
<< ", Expr=" << *Expr << ", MCRegister=" << PhysReg
<< ", DbgLoc=" << DbgLoc << "\n");
return true;
}
return false;
}

static bool processDbgDeclare(FunctionLoweringInfo &FuncInfo,
const Value *Address, DIExpression *Expr,
DILocalVariable *Var, DebugLoc DbgLoc) {
Expand All @@ -1350,6 +1374,10 @@ static bool processDbgDeclare(FunctionLoweringInfo &FuncInfo,
<< " (bad address)\n");
return false;
}

if (processIfEntryValueDbgDeclare(FuncInfo, Address, Expr, Var, DbgLoc))
return true;

MachineFunction *MF = FuncInfo.MF;
const DataLayout &DL = MF->getDataLayout();

Expand Down
2 changes: 2 additions & 0 deletions llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
; RUN: llc -O0 -global-isel -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s
; RUN: llc -O0 -fast-isel -stop-after=finalize-isel %s -o - | FileCheck %s
; RUN: llc -O0 -fast-isel=false -global-isel=false -stop-after=finalize-isel %s -o - | FileCheck %s

; CHECK: void @foo
; CHECK-NEXT: dbg.declare(metadata {{.*}}, metadata ![[VAR:.*]], metadata ![[EXPR:.*]]), !dbg ![[LOC:.*]]
Expand Down

0 comments on commit 2da2995

Please sign in to comment.