diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 36611b117296a..35abd990f9689 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -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(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) { @@ -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(); diff --git a/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll b/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll index 4a68f0548bbaf..8309090908829 100644 --- a/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll +++ b/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll @@ -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:.*]]