From: David Stenberg Date: Wed, 10 Apr 2019 09:07:43 +0000 (+0000) Subject: [DebugInfo] Rename DbgValueHistoryMap::{InstrRange -> Entry}, NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2477cfa4b9447a6da87e19d579fe7b955d20aea;p=llvm [DebugInfo] Rename DbgValueHistoryMap::{InstrRange -> Entry}, NFC Summary: In an upcoming commit the history map will be changed so that it contains explicit entries for instructions that clobber preceding debug values, rather than Begin- End range pairs, so generalize the name to "Entry". Also, prefix the iterator variable names in buildLocationList() with "E". In an upcoming commit the entry will have query functions such as "isD(e)b(u)gValue", which could at a glance make one confuse it for iterations over MachineInstrs, so make the iterator names a bit more distinct to avoid that. Reviewers: aprantl Reviewed By: aprantl Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59939 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358060 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/DbgEntityHistoryCalculator.h b/include/llvm/CodeGen/DbgEntityHistoryCalculator.h index a28b66f45b9..82f882f86d8 100644 --- a/include/llvm/CodeGen/DbgEntityHistoryCalculator.h +++ b/include/llvm/CodeGen/DbgEntityHistoryCalculator.h @@ -32,39 +32,39 @@ public: /// End is not specified, the location is valid until the first overlapping /// DBG_VALUE if any such DBG_VALUE exists, otherwise it is valid until the /// end of the function. - class InstrRange { + class Entry { const MachineInstr *Begin; const MachineInstr *End; public: - InstrRange(const MachineInstr *Begin) : Begin(Begin), End(nullptr) {} + Entry(const MachineInstr *Begin) : Begin(Begin), End(nullptr) {} const MachineInstr *getBegin() const { return Begin; } const MachineInstr *getEnd() const { return End; } bool isClosed() const { return End; } - void endRange(const MachineInstr &End); + void endEntry(const MachineInstr &End); }; - using InstrRanges = SmallVector; + using Entries = SmallVector; using InlinedEntity = std::pair; - using InstrRangesMap = MapVector; + using EntriesMap = MapVector; private: - InstrRangesMap VarInstrRanges; + EntriesMap VarEntries; public: - void startInstrRange(InlinedEntity Var, const MachineInstr &MI); - void endInstrRange(InlinedEntity Var, const MachineInstr &MI); + void startEntry(InlinedEntity Var, const MachineInstr &MI); + void endEntry(InlinedEntity Var, const MachineInstr &MI); // Returns register currently describing @Var. If @Var is currently // unaccessible or is not described by a register, returns 0. unsigned getRegisterForVar(InlinedEntity Var) const; - bool empty() const { return VarInstrRanges.empty(); } - void clear() { VarInstrRanges.clear(); } - InstrRangesMap::const_iterator begin() const { return VarInstrRanges.begin(); } - InstrRangesMap::const_iterator end() const { return VarInstrRanges.end(); } + bool empty() const { return VarEntries.empty(); } + void clear() { VarEntries.clear(); } + EntriesMap::const_iterator begin() const { return VarEntries.begin(); } + EntriesMap::const_iterator end() const { return VarEntries.end(); } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void dump() const; diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index b91f40de148..75a63df083a 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1154,13 +1154,13 @@ static bool needsReferenceType(const DbgVariableLocation &Loc) { } void CodeViewDebug::calculateRanges( - LocalVariable &Var, const DbgValueHistoryMap::InstrRanges &Ranges) { + LocalVariable &Var, const DbgValueHistoryMap::Entries &Entries) { const TargetRegisterInfo *TRI = Asm->MF->getSubtarget().getRegisterInfo(); // Calculate the definition ranges. - for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { - const auto &Range = *I; - const MachineInstr *DVInst = Range.getBegin(); + for (auto I = Entries.begin(), E = Entries.end(); I != E; ++I) { + const auto &Entry = *I; + const MachineInstr *DVInst = Entry.getBegin(); assert(DVInst->isDebugValue() && "Invalid History entry"); // FIXME: Find a way to represent constant variables, since they are // relatively common. @@ -1187,7 +1187,7 @@ void CodeViewDebug::calculateRanges( // Start over using that. Var.UseReferenceType = true; Var.DefRanges.clear(); - calculateRanges(Var, Ranges); + calculateRanges(Var, Entries); return; } @@ -1215,8 +1215,8 @@ void CodeViewDebug::calculateRanges( } // Compute the label range. - const MCSymbol *Begin = getLabelBeforeInsn(Range.getBegin()); - const MCSymbol *End = getLabelAfterInsn(Range.getEnd()); + const MCSymbol *Begin = getLabelBeforeInsn(Entry.getBegin()); + const MCSymbol *End = getLabelAfterInsn(Entry.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. @@ -1257,7 +1257,7 @@ void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { const DILocation *InlinedAt = IV.second; // Instruction ranges, specifying where IV is accessible. - const auto &Ranges = I.second; + const auto &Entries = I.second; LexicalScope *Scope = nullptr; if (InlinedAt) @@ -1271,7 +1271,7 @@ void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { LocalVariable Var; Var.DIVar = DIVar; - calculateRanges(Var, Ranges); + calculateRanges(Var, Entries); recordLocalVariable(std::move(Var), Scope); } } diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/lib/CodeGen/AsmPrinter/CodeViewDebug.h index 7cf7b19ec70..35902302c21 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -222,7 +222,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase { codeview::TypeIndex getFuncIdForSubprogram(const DISubprogram *SP); void calculateRanges(LocalVariable &Var, - const DbgValueHistoryMap::InstrRanges &Ranges); + const DbgValueHistoryMap::Entries &Entries); static void collectInlineSiteChildren(SmallVectorImpl &Children, const FunctionInfo &FI, diff --git a/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp b/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp index bf510b9e21d..618fee9544d 100644 --- a/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp +++ b/lib/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp @@ -41,30 +41,28 @@ static unsigned isDescribedByReg(const MachineInstr &MI) { return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0; } -void DbgValueHistoryMap::startInstrRange(InlinedEntity Var, - const MachineInstr &MI) { +void DbgValueHistoryMap::startEntry(InlinedEntity Var, const MachineInstr &MI) { // Instruction range should start with a DBG_VALUE instruction for the // variable. assert(MI.isDebugValue() && "not a DBG_VALUE"); - auto &Ranges = VarInstrRanges[Var]; - if (!Ranges.empty() && !Ranges.back().isClosed() && - Ranges.back().getBegin()->isIdenticalTo(MI)) { + auto &Entries = VarEntries[Var]; + if (!Entries.empty() && !Entries.back().isClosed() && + Entries.back().getBegin()->isIdenticalTo(MI)) { LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n" - << "\t" << Ranges.back().getBegin() << "\t" << MI + << "\t" << Entries.back().getBegin() << "\t" << MI << "\n"); return; } - Ranges.emplace_back(&MI); + Entries.emplace_back(&MI); } -void DbgValueHistoryMap::endInstrRange(InlinedEntity Var, - const MachineInstr &MI) { - auto &Ranges = VarInstrRanges[Var]; - assert(!Ranges.empty() && "No range exists for variable!"); - Ranges.back().endRange(MI); +void DbgValueHistoryMap::endEntry(InlinedEntity Var, const MachineInstr &MI) { + auto &Entries = VarEntries[Var]; + assert(!Entries.empty() && "No range exists for variable!"); + Entries.back().endEntry(MI); } -void DbgValueHistoryMap::InstrRange::endRange(const MachineInstr &MI) { +void DbgValueHistoryMap::Entry::endEntry(const MachineInstr &MI) { // For now, instruction ranges are not allowed to cross basic block // boundaries. assert(Begin->getParent() == MI.getParent()); @@ -73,13 +71,13 @@ void DbgValueHistoryMap::InstrRange::endRange(const MachineInstr &MI) { } unsigned DbgValueHistoryMap::getRegisterForVar(InlinedEntity Var) const { - const auto &I = VarInstrRanges.find(Var); - if (I == VarInstrRanges.end()) + const auto &I = VarEntries.find(Var); + if (I == VarEntries.end()) return 0; - const auto &Ranges = I->second; - if (Ranges.empty() || Ranges.back().isClosed()) + const auto &Entries = I->second; + if (Entries.empty() || Entries.back().isClosed()) return 0; - return isDescribedByReg(*Ranges.back().getBegin()); + return isDescribedByReg(*Entries.back().getBegin()); } void DbgLabelInstrMap::addInstr(InlinedEntity Label, const MachineInstr &MI) { @@ -127,7 +125,7 @@ static void clobberRegisterUses(RegDescribedVarsMap &RegVars, // Iterate over all variables described by this register and add this // instruction to their history, clobbering it. for (const auto &Var : I->second) - HistMap.endInstrRange(Var, ClobberingInstr); + HistMap.endEntry(Var, ClobberingInstr); RegVars.erase(I); } @@ -257,7 +255,7 @@ void llvm::calculateDbgEntityHistory(const MachineFunction *MF, if (unsigned PrevReg = DbgValues.getRegisterForVar(Var)) dropRegDescribedVar(RegVars, PrevReg, Var); - DbgValues.startInstrRange(Var, MI); + DbgValues.startEntry(Var, MI); if (unsigned NewReg = isDescribedByReg(MI)) addRegDescribedVar(RegVars, NewReg, Var); @@ -293,7 +291,7 @@ LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const { dbgs() << "DbgValueHistoryMap:\n"; for (const auto &VarRangePair : *this) { const InlinedEntity &Var = VarRangePair.first; - const InstrRanges &Ranges = VarRangePair.second; + const Entries &Entries = VarRangePair.second; const DILocalVariable *LocalVar = cast(Var.first); const DILocation *Location = Var.second; @@ -308,10 +306,10 @@ LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const { dbgs() << " --\n"; - for (const InstrRange &Range : Ranges) { - dbgs() << " Begin: " << *Range.getBegin(); - if (Range.getEnd()) - dbgs() << " End : " << *Range.getEnd(); + for (const auto &Entry : Entries) { + dbgs() << " Begin: " << *Entry.getBegin(); + if (Entry.getEnd()) + dbgs() << " End : " << *Entry.getEnd(); dbgs() << "\n"; } } diff --git a/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp b/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp index 7a435422652..00e4cea3135 100644 --- a/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp +++ b/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp @@ -211,8 +211,8 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) { // Request labels for the full history. for (const auto &I : DbgValues) { - const auto &Ranges = I.second; - if (Ranges.empty()) + const auto &Entries = I.second; + if (Entries.empty()) continue; auto IsDescribedByReg = [](const MachineInstr *MI) { @@ -229,17 +229,17 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) { // 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().getBegin()->getDebugVariable(); + Entries.front().getBegin()->getDebugVariable(); if (DIVar->isParameter() && getDISubprogram(DIVar->getScope())->describes(&MF->getFunction())) { - if (!IsDescribedByReg(Ranges.front().getBegin())) - LabelsBeforeInsn[Ranges.front().getBegin()] = Asm->getFunctionBegin(); - if (Ranges.front().getBegin()->getDebugExpression()->isFragment()) { + if (!IsDescribedByReg(Entries.front().getBegin())) + LabelsBeforeInsn[Entries.front().getBegin()] = Asm->getFunctionBegin(); + if (Entries.front().getBegin()->getDebugExpression()->isFragment()) { // Mark all non-overlapping initial fragments. - for (auto I = Ranges.begin(); I != Ranges.end(); ++I) { + for (auto I = Entries.begin(); I != Entries.end(); ++I) { const DIExpression *Fragment = I->getBegin()->getDebugExpression(); - if (std::any_of(Ranges.begin(), I, - [&](DbgValueHistoryMap::InstrRange Pred) { + if (std::any_of(Entries.begin(), I, + [&](DbgValueHistoryMap::Entry Pred) { return Fragment->fragmentsOverlap( Pred.getBegin()->getDebugExpression()); })) @@ -250,10 +250,10 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) { } } - for (const auto &Range : Ranges) { - requestLabelBeforeInsn(Range.getBegin()); - if (Range.getEnd()) - requestLabelAfterInsn(Range.getEnd()); + for (const auto &Entry : Entries) { + requestLabelBeforeInsn(Entry.getBegin()); + if (Entry.getEnd()) + requestLabelAfterInsn(Entry.getEnd()); } } diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 1547822b695..07232b5082a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1117,14 +1117,13 @@ static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) { // [1-3] [x, (reg0, fragment 0, 32), (reg1, fragment 32, 32)] // [3-4] [x, (reg1, fragment 32, 32)] // [4- ] [x, (mem, fragment 0, 64)] -void -DwarfDebug::buildLocationList(SmallVectorImpl &DebugLoc, - const DbgValueHistoryMap::InstrRanges &Ranges) { +void DwarfDebug::buildLocationList(SmallVectorImpl &DebugLoc, + const DbgValueHistoryMap::Entries &Entries) { SmallVector OpenRanges; - for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) { - const MachineInstr *Begin = I->getBegin(); - const MachineInstr *End = I->getEnd(); + for (auto EI = Entries.begin(), EE = Entries.end(); EI != EE; ++EI) { + const MachineInstr *Begin = EI->getBegin(); + const MachineInstr *End = EI->getEnd(); assert(Begin->isDebugValue() && "Invalid History entry"); // Check if a variable is inaccessible in this range. @@ -1147,10 +1146,10 @@ DwarfDebug::buildLocationList(SmallVectorImpl &DebugLoc, const MCSymbol *EndLabel; if (End != nullptr) EndLabel = getLabelAfterInsn(End); - else if (std::next(I) == Ranges.end()) + else if (std::next(EI) == Entries.end()) EndLabel = Asm->getFunctionEnd(); else - EndLabel = getLabelBeforeInsn(std::next(I)->getBegin()); + EndLabel = getLabelBeforeInsn(std::next(EI)->getBegin()); assert(EndLabel && "Forgot label after instruction ending a range!"); LLVM_DEBUG(dbgs() << "DotDebugLoc: " << *Begin << "\n"); @@ -1275,8 +1274,8 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, continue; // Instruction ranges, specifying where IV is accessible. - const auto &Ranges = I.second; - if (Ranges.empty()) + const auto &HistoryMapEntries = I.second; + if (HistoryMapEntries.empty()) continue; LexicalScope *Scope = nullptr; @@ -1293,12 +1292,12 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, DbgVariable *RegVar = cast(createConcreteEntity(TheCU, *Scope, LocalVar, IV.second)); - const MachineInstr *MInsn = Ranges.front().getBegin(); + const MachineInstr *MInsn = HistoryMapEntries.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().getEnd())) { + if (HistoryMapEntries.size() == 1 && + validThroughout(LScopes, MInsn, HistoryMapEntries.front().getEnd())) { RegVar->initializeDbgValue(MInsn); continue; } @@ -1311,7 +1310,7 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU, // Build the location list for this variable. SmallVector Entries; - buildLocationList(Entries, Ranges); + buildLocationList(Entries, HistoryMapEntries); // If the variable has a DIBasicType, extract it. Basic types cannot have // unique identifiers, so don't bother resolving the type with the diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index ec5040f6c10..a8cadaa60eb 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -559,7 +559,7 @@ class DwarfDebug : public DebugHandlerBase { /// Build the location list for all DBG_VALUEs in the /// function that describe the same variable. void buildLocationList(SmallVectorImpl &DebugLoc, - const DbgValueHistoryMap::InstrRanges &Ranges); + const DbgValueHistoryMap::Entries &Entries); /// Collect variable information from the side table maintained by MF. void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU,