Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -1053,6 +1053,9 @@ bool occupiesMultipleRegs() const { return std::accumulate(RegCount.begin(), RegCount.end(), 0) > 1; } + + /// Populate the OutVec with a list of registers and their sizes. + SmallVector, 4> getRegsAndSizes() const; }; } // end namespace llvm Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -971,6 +971,20 @@ } } +SmallVector, 4> +RegsForValue::getRegsAndSizes() const { + SmallVector, 4> OutVec; + unsigned I = 0; + for (auto CountAndVT : zip_first(RegCount, RegVTs)) { + unsigned RegCount = std::get<0>(CountAndVT); + MVT RegisterVT = std::get<1>(CountAndVT); + unsigned RegisterSize = RegisterVT.getSizeInBits(); + for (unsigned E = I + RegCount; I != E; ++I) + OutVec.push_back(std::make_pair(Regs[I], RegisterSize)); + } + return OutVec; +} + void SelectionDAGBuilder::init(GCFunctionInfo *gfi, AliasAnalysis *aa, const TargetLibraryInfo *li) { AA = aa; @@ -4908,26 +4922,18 @@ const auto &TLI = DAG.getTargetLoweringInfo(); RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), VMI->second, V->getType(), isABIRegCopy(V)); - unsigned NumRegs = - std::accumulate(RFV.RegCount.begin(), RFV.RegCount.end(), 0); - if (NumRegs > 1) { - unsigned I = 0; + if (RFV.occupiesMultipleRegs()) { unsigned Offset = 0; - auto RegisterVT = RFV.RegVTs.begin(); - for (auto RegCount : RFV.RegCount) { - unsigned RegisterSize = (RegisterVT++)->getSizeInBits(); - for (unsigned E = I + RegCount; I != E; ++I) { - // The vregs are guaranteed to be allocated in sequence. - Op = MachineOperand::CreateReg(VMI->second + I, false); - auto FragmentExpr = DIExpression::createFragmentExpression( - Expr, Offset, RegisterSize); - if (!FragmentExpr) - continue; - FuncInfo.ArgDbgValues.push_back( - BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare, - Op->getReg(), Variable, *FragmentExpr)); - Offset += RegisterSize; - } + for (auto RegAndSize : RFV.getRegsAndSizes()) { + Op = MachineOperand::CreateReg(RegAndSize.first, false); + auto FragmentExpr = DIExpression::createFragmentExpression( + Expr, Offset, RegAndSize.second); + if (!FragmentExpr) + continue; + FuncInfo.ArgDbgValues.push_back( + BuildMI(MF, DL, TII->get(TargetOpcode::DBG_VALUE), IsDbgDeclare, + Op->getReg(), Variable, *FragmentExpr)); + Offset += RegAndSize.second; } return true; } @@ -5265,23 +5271,17 @@ RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), Reg, V->getType(), false); if (RFV.occupiesMultipleRegs()) { - unsigned I = 0; unsigned Offset = 0; - for (auto CountAndVT : zip_first(RFV.RegCount, RFV.RegVTs)) { - unsigned RegCount = std::get<0>(CountAndVT); - MVT RegisterVT = std::get<1>(CountAndVT); - unsigned RegisterSize = RegisterVT.getSizeInBits(); - for (unsigned E = I + RegCount; I != E; ++I) { - auto FragmentExpr = DIExpression::createFragmentExpression( - Expression, Offset, RegisterSize); - if (!FragmentExpr) - continue; - // The vregs are guaranteed to be allocated in sequence. - SDV = DAG.getVRegDbgValue(Variable, *FragmentExpr, Reg + I, - false, dl, SDNodeOrder); - DAG.AddDbgValue(SDV, nullptr, false); - Offset += RegisterSize; - } + for (auto RegAndSize : RFV.getRegsAndSizes()) { + auto FragmentExpr = DIExpression::createFragmentExpression( + Expression, Offset, RegAndSize.second); + if (!FragmentExpr) + continue; + SDV = DAG.getVRegDbgValue(Variable, *FragmentExpr, + RegAndSize.first, + false, dl, SDNodeOrder); + DAG.AddDbgValue(SDV, nullptr, false); + Offset += RegAndSize.second; } } else { SDV = DAG.getVRegDbgValue(Variable, Expression, Reg, false, dl,