summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp178
1 files changed, 12 insertions, 166 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 2632a6abe75..ec7329eafb7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -202,8 +202,8 @@ static LLVM_CONSTEXPR DwarfAccelTable::Atom TypeAtoms[] = {
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)};
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
- : Asm(A), MMI(Asm->MMI), DebugLocs(A->OutStreamer->isVerboseAsm()),
- PrevLabel(nullptr), InfoHolder(A, "info_string", DIEValueAllocator),
+ : DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
+ InfoHolder(A, "info_string", DIEValueAllocator),
SkeletonHolder(A, "skel_string", DIEValueAllocator),
IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()),
AccelNames(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
@@ -215,7 +215,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
AccelTypes(TypeAtoms), DebuggerTuning(DebuggerKind::Default) {
CurFn = nullptr;
- CurMI = nullptr;
Triple TT(Asm->getTargetTriple());
// Make sure we know our "debugger tuning." The target option takes
@@ -788,29 +787,6 @@ static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) {
llvm_unreachable("Unexpected 4-operand DBG_VALUE instruction!");
}
-// Determine the relative position of the pieces described by P1 and P2.
-// Returns -1 if P1 is entirely before P2, 0 if P1 and P2 overlap,
-// 1 if P1 is entirely after P2.
-static int pieceCmp(const DIExpression *P1, const DIExpression *P2) {
- unsigned l1 = P1->getBitPieceOffset();
- unsigned l2 = P2->getBitPieceOffset();
- unsigned r1 = l1 + P1->getBitPieceSize();
- unsigned r2 = l2 + P2->getBitPieceSize();
- if (r1 <= l2)
- return -1;
- else if (r2 <= l1)
- return 1;
- else
- return 0;
-}
-
-/// Determine whether two variable pieces overlap.
-static bool piecesOverlap(const DIExpression *P1, const DIExpression *P2) {
- if (!P1->isBitPiece() || !P2->isBitPiece())
- return true;
- return pieceCmp(P1, P2) == 0;
-}
-
/// \brief If this and Next are describing different pieces of the same
/// variable, merge them by appending Next's values to the current
/// list of values.
@@ -827,8 +803,9 @@ bool DebugLocEntry::MergeValues(const DebugLocEntry &Next) {
// sorted.
for (unsigned i = 0, j = 0; i < Values.size(); ++i) {
for (; j < Next.Values.size(); ++j) {
- int res = pieceCmp(cast<DIExpression>(Values[i].Expression),
- cast<DIExpression>(Next.Values[j].Expression));
+ int res = DebugHandlerBase::pieceCmp(
+ cast<DIExpression>(Values[i].Expression),
+ cast<DIExpression>(Next.Values[j].Expression));
if (res == 0) // The two expressions overlap, we can't merge.
return false;
// Values[i] is entirely before Next.Values[j],
@@ -1022,22 +999,11 @@ void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
}
}
-// Return Label preceding the instruction.
-MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
- MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
- assert(Label && "Didn't insert label before instruction");
- return Label;
-}
-
-// Return Label immediately following the instruction.
-MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
- return LabelsAfterInsn.lookup(MI);
-}
-
// Process beginning of an instruction.
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
- assert(CurMI == nullptr);
- CurMI = MI;
+ DebugHandlerBase::beginInstruction(MI);
+ assert(CurMI);
+
// Check if source location changes, but ignore DBG_VALUE locations.
if (!MI->isDebugValue()) {
DebugLoc DL = MI->getDebugLoc();
@@ -1062,78 +1028,6 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
}
}
}
-
- // Insert labels where requested.
- DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
- LabelsBeforeInsn.find(MI);
-
- // No label needed.
- if (I == LabelsBeforeInsn.end())
- return;
-
- // Label already assigned.
- if (I->second)
- return;
-
- if (!PrevLabel) {
- PrevLabel = MMI->getContext().createTempSymbol();
- Asm->OutStreamer->EmitLabel(PrevLabel);
- }
- I->second = PrevLabel;
-}
-
-// Process end of an instruction.
-void DwarfDebug::endInstruction() {
- assert(CurMI != nullptr);
- // Don't create a new label after DBG_VALUE instructions.
- // They don't generate code.
- if (!CurMI->isDebugValue())
- PrevLabel = nullptr;
-
- DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
- LabelsAfterInsn.find(CurMI);
- CurMI = nullptr;
-
- // No label needed.
- if (I == LabelsAfterInsn.end())
- return;
-
- // Label already assigned.
- if (I->second)
- return;
-
- // We need a label after this instruction.
- if (!PrevLabel) {
- PrevLabel = MMI->getContext().createTempSymbol();
- Asm->OutStreamer->EmitLabel(PrevLabel);
- }
- I->second = PrevLabel;
-}
-
-// Each LexicalScope has first instruction and last instruction to mark
-// beginning and end of a scope respectively. Create an inverse map that list
-// scopes starts (and ends) with an instruction. One instruction may start (or
-// end) multiple scopes. Ignore scopes that are not reachable.
-void DwarfDebug::identifyScopeMarkers() {
- SmallVector<LexicalScope *, 4> WorkList;
- WorkList.push_back(LScopes.getCurrentFunctionScope());
- while (!WorkList.empty()) {
- LexicalScope *S = WorkList.pop_back_val();
-
- const SmallVectorImpl<LexicalScope *> &Children = S->getChildren();
- if (!Children.empty())
- WorkList.append(Children.begin(), Children.end());
-
- if (S->isAbstractScope())
- continue;
-
- for (const InsnRange &R : S->getRanges()) {
- assert(R.first && "InsnRange does not have first instruction!");
- assert(R.second && "InsnRange does not have second instruction!");
- requestLabelBeforeInsn(R.first);
- requestLabelAfterInsn(R.second);
- }
- }
}
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
@@ -1162,15 +1056,10 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
// Grab the lexical scopes for the function, if we don't have any of those
// then we're not going to be able to do anything.
- LScopes.initialize(*MF);
+ DebugHandlerBase::beginFunction(MF);
if (LScopes.empty())
return;
- assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
-
- // Make sure that each lexical scope will have a begin/end label.
- identifyScopeMarkers();
-
// Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
// belongs to so that we add to the correct per-cu line table in the
// non-asm case.
@@ -1191,47 +1080,6 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
else
Asm->OutStreamer->getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
- // Calculate history for local variables.
- calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),
- DbgValues);
-
- // Request labels for the full history.
- for (const auto &I : DbgValues) {
- const auto &Ranges = I.second;
- if (Ranges.empty())
- continue;
-
- // The first mention of a function argument gets the CurrentFnBegin
- // label, so arguments are visible when breaking at function entry.
- const DILocalVariable *DIVar = Ranges.front().first->getDebugVariable();
- if (DIVar->isParameter() &&
- getDISubprogram(DIVar->getScope())->describes(MF->getFunction())) {
- LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
- if (Ranges.front().first->getDebugExpression()->isBitPiece()) {
- // Mark all non-overlapping initial pieces.
- for (auto I = Ranges.begin(); I != Ranges.end(); ++I) {
- const DIExpression *Piece = I->first->getDebugExpression();
- if (std::all_of(Ranges.begin(), I,
- [&](DbgValueHistoryMap::InstrRange Pred) {
- return !piecesOverlap(Piece, Pred.first->getDebugExpression());
- }))
- LabelsBeforeInsn[I->first] = Asm->getFunctionBegin();
- else
- break;
- }
- }
- }
-
- for (const auto &Range : Ranges) {
- requestLabelBeforeInsn(Range.first);
- if (Range.second)
- requestLabelAfterInsn(Range.second);
- }
- }
-
- PrevInstLoc = DebugLoc();
- PrevLabel = Asm->getFunctionBegin();
-
// Record beginning of function.
PrologEndLoc = findPrologueEndLoc(MF);
if (DILocation *L = PrologEndLoc) {
@@ -1254,6 +1102,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
// previously used section to nullptr.
PrevCU = nullptr;
CurFn = nullptr;
+ DebugHandlerBase::endFunction(MF);
return;
}
@@ -1279,10 +1128,9 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
// FIXME: This wouldn't be true in LTO with a -g (with inlining) CU followed
// by a -gmlt CU. Add a test and remove this assertion.
assert(AbstractVariables.empty());
- LabelsBeforeInsn.clear();
- LabelsAfterInsn.clear();
PrevLabel = nullptr;
CurFn = nullptr;
+ DebugHandlerBase::endFunction(MF);
return;
}
@@ -1314,11 +1162,9 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
// DbgVariables except those that are also in AbstractVariables (since they
// can be used cross-function)
InfoHolder.getScopeVariables().clear();
- DbgValues.clear();
- LabelsBeforeInsn.clear();
- LabelsAfterInsn.clear();
PrevLabel = nullptr;
CurFn = nullptr;
+ DebugHandlerBase::endFunction(MF);
}
// Register a source line with debug info. Returns the unique label that was
OpenPOWER on IntegriCloud