Index: include/llvm/CodeGen/DbgEntityHistoryCalculator.h =================================================================== --- include/llvm/CodeGen/DbgEntityHistoryCalculator.h +++ include/llvm/CodeGen/DbgEntityHistoryCalculator.h @@ -30,7 +30,18 @@ // instruction of the next instruction range, or until the end of the // function. public: - using InstrRange = std::pair; + class InstrRange { + const MachineInstr *Begin; + const MachineInstr *End; + + public: + InstrRange(const MachineInstr *Begin) : Begin(Begin), End(nullptr) {} + + const MachineInstr *getBegin() const { return Begin; } + const MachineInstr *getEnd() const { return End; } + + void endRange(const MachineInstr &End); + }; using InstrRanges = SmallVector; using InlinedEntity = std::pair; using InstrRangesMap = MapVector; Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1159,8 +1159,8 @@ // Calculate the definition ranges. for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { - const InsnRange &Range = *I; - const MachineInstr *DVInst = Range.first; + const auto &Range = *I; + const MachineInstr *DVInst = Range.getBegin(); assert(DVInst->isDebugValue() && "Invalid History entry"); // FIXME: Find a way to represent constant variables, since they are // relatively common. @@ -1215,18 +1215,18 @@ } // Compute the label range. - const MCSymbol *Begin = getLabelBeforeInsn(Range.first); - const MCSymbol *End = getLabelAfterInsn(Range.second); + const MCSymbol *Begin = getLabelBeforeInsn(Range.getBegin()); + const MCSymbol *End = getLabelAfterInsn(Range.getEnd()); if (!End) { // This range is valid until the next overlapping bitpiece. In the // common case, ranges will not be bitpieces, so they will overlap. auto J = std::next(I); const DIExpression *DIExpr = DVInst->getDebugExpression(); while (J != E && - !DIExpr->fragmentsOverlap(J->first->getDebugExpression())) + !DIExpr->fragmentsOverlap(J->getBegin()->getDebugExpression())) ++J; if (J != E) - End = getLabelBeforeInsn(J->first); + End = getLabelBeforeInsn(J->getBegin()); else End = Asm->getFunctionEnd(); } Index: lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp +++ lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp @@ -47,24 +47,29 @@ // variable. assert(MI.isDebugValue() && "not a DBG_VALUE"); auto &Ranges = VarInstrRanges[Var]; - if (!Ranges.empty() && Ranges.back().second == nullptr && - Ranges.back().first->isIdenticalTo(MI)) { + if (!Ranges.empty() && Ranges.back().getEnd() == nullptr && + Ranges.back().getBegin()->isIdenticalTo(MI)) { LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n" - << "\t" << Ranges.back().first << "\t" << MI << "\n"); + << "\t" << Ranges.back().getBegin() << "\t" << MI + << "\n"); return; } - Ranges.push_back(std::make_pair(&MI, nullptr)); + Ranges.emplace_back(&MI); } void DbgValueHistoryMap::endInstrRange(InlinedEntity Var, const MachineInstr &MI) { auto &Ranges = VarInstrRanges[Var]; - // Verify that the current instruction range is not yet closed. - assert(!Ranges.empty() && Ranges.back().second == nullptr); + assert(!Ranges.empty() && "No range exists for variable!"); + Ranges.back().endRange(MI); +} + +void DbgValueHistoryMap::InstrRange::endRange(const MachineInstr &MI) { // For now, instruction ranges are not allowed to cross basic block // boundaries. - assert(Ranges.back().first->getParent() == MI.getParent()); - Ranges.back().second = &MI; + assert(Begin->getParent() == MI.getParent()); + assert(End == nullptr && "Range is already closed!"); + End = &MI; } unsigned DbgValueHistoryMap::getRegisterForVar(InlinedEntity Var) const { @@ -72,9 +77,9 @@ if (I == VarInstrRanges.end()) return 0; const auto &Ranges = I->second; - if (Ranges.empty() || Ranges.back().second != nullptr) + if (Ranges.empty() || Ranges.back().getEnd() != nullptr) return 0; - return isDescribedByReg(*Ranges.back().first); + return isDescribedByReg(*Ranges.back().getBegin()); } void DbgLabelInstrMap::addInstr(InlinedEntity Label, const MachineInstr &MI) { @@ -304,9 +309,9 @@ dbgs() << " --\n"; for (const InstrRange &Range : Ranges) { - dbgs() << " Begin: " << *Range.first; - if (Range.second) - dbgs() << " End : " << *Range.second; + dbgs() << " Begin: " << *Range.getBegin(); + if (Range.getEnd()) + dbgs() << " End : " << *Range.getEnd(); dbgs() << "\n"; } } Index: lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp +++ lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp @@ -228,31 +228,32 @@ // doing that violates the ranges that are calculated in the history map. // However, we currently do not emit debug values for constant arguments // directly at the start of the function, so this code is still useful. - const DILocalVariable *DIVar = Ranges.front().first->getDebugVariable(); + const DILocalVariable *DIVar = + Ranges.front().getBegin()->getDebugVariable(); if (DIVar->isParameter() && getDISubprogram(DIVar->getScope())->describes(&MF->getFunction())) { - if (!IsDescribedByReg(Ranges.front().first)) - LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin(); - if (Ranges.front().first->getDebugExpression()->isFragment()) { + if (!IsDescribedByReg(Ranges.front().getBegin())) + LabelsBeforeInsn[Ranges.front().getBegin()] = Asm->getFunctionBegin(); + if (Ranges.front().getBegin()->getDebugExpression()->isFragment()) { // Mark all non-overlapping initial fragments. for (auto I = Ranges.begin(); I != Ranges.end(); ++I) { - const DIExpression *Fragment = I->first->getDebugExpression(); + const DIExpression *Fragment = I->getBegin()->getDebugExpression(); if (std::any_of(Ranges.begin(), I, [&](DbgValueHistoryMap::InstrRange Pred) { return Fragment->fragmentsOverlap( - Pred.first->getDebugExpression()); + Pred.getBegin()->getDebugExpression()); })) break; - if (!IsDescribedByReg(I->first)) - LabelsBeforeInsn[I->first] = Asm->getFunctionBegin(); + if (!IsDescribedByReg(I->getBegin())) + LabelsBeforeInsn[I->getBegin()] = Asm->getFunctionBegin(); } } } for (const auto &Range : Ranges) { - requestLabelBeforeInsn(Range.first); - if (Range.second) - requestLabelAfterInsn(Range.second); + requestLabelBeforeInsn(Range.getBegin()); + if (Range.getEnd()) + requestLabelAfterInsn(Range.getEnd()); } } Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1123,8 +1123,8 @@ SmallVector OpenRanges; for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { - const MachineInstr *Begin = I->first; - const MachineInstr *End = I->second; + const MachineInstr *Begin = I->getBegin(); + const MachineInstr *End = I->getEnd(); assert(Begin->isDebugValue() && "Invalid History entry"); // Check if a variable is inaccessible in this range. @@ -1150,7 +1150,7 @@ else if (std::next(I) == Ranges.end()) EndLabel = Asm->getFunctionEnd(); else - EndLabel = getLabelBeforeInsn(std::next(I)->first); + EndLabel = getLabelBeforeInsn(std::next(I)->getBegin()); assert(EndLabel && "Forgot label after instruction ending a range!"); LLVM_DEBUG(dbgs() << "DotDebugLoc: " << *Begin << "\n"); @@ -1293,12 +1293,12 @@ DbgVariable *RegVar = cast(createConcreteEntity(TheCU, *Scope, LocalVar, IV.second)); - const MachineInstr *MInsn = Ranges.front().first; + const MachineInstr *MInsn = Ranges.front().getBegin(); assert(MInsn->isDebugValue() && "History must begin with debug value"); // Check if there is a single DBG_VALUE, valid throughout the var's scope. if (Ranges.size() == 1 && - validThroughout(LScopes, MInsn, Ranges.front().second)) { + validThroughout(LScopes, MInsn, Ranges.front().getEnd())) { RegVar->initializeDbgValue(MInsn); continue; }