blob: 170fc8b6d49f52897a17e397cd4ccbdf6b53f8e2 [file] [log] [blame]
Hsiangkai Wang2532ac82018-08-17 15:22:04 +00001//===- llvm/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp -------------===//
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00006//
7//===----------------------------------------------------------------------===//
8
Yonghong Song61b189e2018-12-18 23:10:17 +00009#include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
Benjamin Kramer6bf8af52014-10-06 15:31:04 +000010#include "llvm/ADT/BitVector.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000011#include "llvm/ADT/STLExtras.h"
David Stenberg5ffec6d2019-04-10 11:28:20 +000012#include "llvm/ADT/SmallSet.h"
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +000013#include "llvm/ADT/SmallVector.h"
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000014#include "llvm/CodeGen/MachineBasicBlock.h"
15#include "llvm/CodeGen/MachineFunction.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000016#include "llvm/CodeGen/MachineInstr.h"
17#include "llvm/CodeGen/MachineOperand.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000018#include "llvm/CodeGen/TargetLowering.h"
19#include "llvm/CodeGen/TargetRegisterInfo.h"
20#include "llvm/CodeGen/TargetSubtargetInfo.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000021#include "llvm/IR/DebugInfoMetadata.h"
22#include "llvm/IR/DebugLoc.h"
23#include "llvm/MC/MCRegisterInfo.h"
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000024#include "llvm/Support/Debug.h"
Benjamin Kramer16132e62015-03-23 18:07:13 +000025#include "llvm/Support/raw_ostream.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000026#include <cassert>
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +000027#include <map>
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000028#include <utility>
29
Benjamin Kramer6bf8af52014-10-06 15:31:04 +000030using namespace llvm;
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000031
32#define DEBUG_TYPE "dwarfdebug"
33
David Stenberg5ffec6d2019-04-10 11:28:20 +000034namespace {
35using EntryIndex = DbgValueHistoryMap::EntryIndex;
36}
37
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000038// If @MI is a DBG_VALUE with debug value described by a
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +000039// defined register, returns the number of this register.
40// In the other case, returns 0.
Matt Arsenaulte3a676e2019-06-24 15:50:29 +000041static Register isDescribedByReg(const MachineInstr &MI) {
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +000042 assert(MI.isDebugValue());
Adrian Prantl87b7eb92014-10-01 18:55:02 +000043 assert(MI.getNumOperands() == 4);
David Stenberg1ae2d9a2019-10-15 11:31:21 +000044 // If the location of variable is an entry value (DW_OP_LLVM_entry_value)
Djordje Todorovica0d45052019-06-27 13:52:34 +000045 // do not consider it as a register location.
46 if (MI.getDebugExpression()->isEntryValue())
47 return 0;
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +000048 // If location of variable is described using a register (directly or
Dominic Chen6ba19652016-08-11 17:52:40 +000049 // indirectly), this register is always a first operand.
Matt Arsenaulte3a676e2019-06-24 15:50:29 +000050 return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : Register();
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +000051}
52
David Stenberg5ffec6d2019-04-10 11:28:20 +000053bool DbgValueHistoryMap::startDbgValue(InlinedEntity Var,
54 const MachineInstr &MI,
55 EntryIndex &NewIndex) {
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000056 // Instruction range should start with a DBG_VALUE instruction for the
57 // variable.
Adrian Prantl87b7eb92014-10-01 18:55:02 +000058 assert(MI.isDebugValue() && "not a DBG_VALUE");
David Stenberg6feef562019-04-10 09:07:43 +000059 auto &Entries = VarEntries[Var];
David Stenberg5ffec6d2019-04-10 11:28:20 +000060 if (!Entries.empty() && Entries.back().isDbgValue() &&
61 !Entries.back().isClosed() &&
62 Entries.back().getInstr()->isIdenticalTo(MI)) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +000063 LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
David Stenberg5ffec6d2019-04-10 11:28:20 +000064 << "\t" << Entries.back().getInstr() << "\t" << MI
David Stenberg37399792019-04-10 09:07:32 +000065 << "\n");
David Stenberg5ffec6d2019-04-10 11:28:20 +000066 return false;
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000067 }
David Stenberg5ffec6d2019-04-10 11:28:20 +000068 Entries.emplace_back(&MI, Entry::DbgValue);
69 NewIndex = Entries.size() - 1;
70 return true;
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000071}
72
David Stenberg5ffec6d2019-04-10 11:28:20 +000073EntryIndex DbgValueHistoryMap::startClobber(InlinedEntity Var,
74 const MachineInstr &MI) {
David Stenberg6feef562019-04-10 09:07:43 +000075 auto &Entries = VarEntries[Var];
David Stenbergb96943b2019-04-10 11:28:28 +000076 // If an instruction clobbers multiple registers that the variable is
77 // described by, then we may have already created a clobbering instruction.
78 if (Entries.back().isClobber() && Entries.back().getInstr() == &MI)
79 return Entries.size() - 1;
David Stenberg5ffec6d2019-04-10 11:28:20 +000080 Entries.emplace_back(&MI, Entry::Clobber);
81 return Entries.size() - 1;
David Stenberg37399792019-04-10 09:07:32 +000082}
83
David Stenberg5ffec6d2019-04-10 11:28:20 +000084void DbgValueHistoryMap::Entry::endEntry(EntryIndex Index) {
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000085 // For now, instruction ranges are not allowed to cross basic block
86 // boundaries.
David Stenberg5ffec6d2019-04-10 11:28:20 +000087 assert(isDbgValue() && "Setting end index for non-debug value");
88 assert(!isClosed() && "End index has already been set");
89 EndIndex = Index;
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000090}
91
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +000092void DbgLabelInstrMap::addInstr(InlinedEntity Label, const MachineInstr &MI) {
Hsiangkai Wang2532ac82018-08-17 15:22:04 +000093 assert(MI.isDebugLabel() && "not a DBG_LABEL");
94 LabelInstr[Label] = &MI;
95}
96
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000097namespace {
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000098
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000099// Maps physreg numbers to the variables they describe.
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000100using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
101using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000102
David Stenberg5ffec6d2019-04-10 11:28:20 +0000103// Keeps track of the debug value entries that are currently live for each
104// inlined entity. As the history map entries are stored in a SmallVector, they
105// may be moved at insertion of new entries, so store indices rather than
106// pointers.
107using DbgValueEntriesMap = std::map<InlinedEntity, SmallSet<EntryIndex, 1>>;
108
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000109} // end anonymous namespace
Alexey Samsonovbb2990d2014-05-27 23:09:50 +0000110
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000111// Claim that @Var is not described by @RegNo anymore.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000112static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000113 InlinedEntity Var) {
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000114 const auto &I = RegVars.find(RegNo);
115 assert(RegNo != 0U && I != RegVars.end());
116 auto &VarSet = I->second;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000117 const auto &VarPos = llvm::find(VarSet, Var);
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000118 assert(VarPos != VarSet.end());
119 VarSet.erase(VarPos);
120 // Don't keep empty sets in a map to keep it as small as possible.
121 if (VarSet.empty())
122 RegVars.erase(I);
123}
124
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000125// Claim that @Var is now described by @RegNo.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +0000126static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000127 InlinedEntity Var) {
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000128 assert(RegNo != 0U);
Alexey Samsonovbb2990d2014-05-27 23:09:50 +0000129 auto &VarSet = RegVars[RegNo];
David Majnemer0d955d02016-08-11 22:21:41 +0000130 assert(!is_contained(VarSet, Var));
Alexey Samsonovbb2990d2014-05-27 23:09:50 +0000131 VarSet.push_back(Var);
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000132}
133
David Stenbergb96943b2019-04-10 11:28:28 +0000134/// Create a clobbering entry and end all open debug value entries
135/// for \p Var that are described by \p RegNo using that entry.
David Stenberg5ffec6d2019-04-10 11:28:20 +0000136static void clobberRegEntries(InlinedEntity Var, unsigned RegNo,
137 const MachineInstr &ClobberingInstr,
138 DbgValueEntriesMap &LiveEntries,
139 DbgValueHistoryMap &HistMap) {
140 EntryIndex ClobberIndex = HistMap.startClobber(Var, ClobberingInstr);
141
David Stenbergb96943b2019-04-10 11:28:28 +0000142 // Close all entries whose values are described by the register.
143 SmallVector<EntryIndex, 4> IndicesToErase;
144 for (auto Index : LiveEntries[Var]) {
145 auto &Entry = HistMap.getEntry(Var, Index);
146 assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
147 if (isDescribedByReg(*Entry.getInstr()) == RegNo) {
148 IndicesToErase.push_back(Index);
149 Entry.endEntry(ClobberIndex);
150 }
151 }
152
153 // Drop all entries that have ended.
154 for (auto Index : IndicesToErase)
155 LiveEntries[Var].erase(Index);
David Stenberg5ffec6d2019-04-10 11:28:20 +0000156}
157
158/// Add a new debug value for \p Var. Closes all overlapping debug values.
159static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
160 RegDescribedVarsMap &RegVars,
161 DbgValueEntriesMap &LiveEntries,
162 DbgValueHistoryMap &HistMap) {
David Stenberg5ffec6d2019-04-10 11:28:20 +0000163 EntryIndex NewIndex;
164 if (HistMap.startDbgValue(Var, DV, NewIndex)) {
David Stenbergb96943b2019-04-10 11:28:28 +0000165 SmallDenseMap<unsigned, bool, 4> TrackedRegs;
166
David Stenberg5ffec6d2019-04-10 11:28:20 +0000167 // If we have created a new debug value entry, close all preceding
168 // live entries that overlap.
169 SmallVector<EntryIndex, 4> IndicesToErase;
170 const DIExpression *DIExpr = DV.getDebugExpression();
171 for (auto Index : LiveEntries[Var]) {
172 auto &Entry = HistMap.getEntry(Var, Index);
173 assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
174 const MachineInstr &DV = *Entry.getInstr();
David Stenbergb96943b2019-04-10 11:28:28 +0000175 bool Overlaps = DIExpr->fragmentsOverlap(DV.getDebugExpression());
176 if (Overlaps) {
David Stenberg5ffec6d2019-04-10 11:28:20 +0000177 IndicesToErase.push_back(Index);
178 Entry.endEntry(NewIndex);
179 }
Daniel Sanders0c476112019-08-15 19:22:08 +0000180 if (Register Reg = isDescribedByReg(DV))
David Stenbergb96943b2019-04-10 11:28:28 +0000181 TrackedRegs[Reg] |= !Overlaps;
David Stenberg5ffec6d2019-04-10 11:28:20 +0000182 }
David Stenbergb96943b2019-04-10 11:28:28 +0000183
184 // If the new debug value is described by a register, add tracking of
185 // that register if it is not already tracked.
Daniel Sanders0c476112019-08-15 19:22:08 +0000186 if (Register NewReg = isDescribedByReg(DV)) {
David Stenbergb96943b2019-04-10 11:28:28 +0000187 if (!TrackedRegs.count(NewReg))
188 addRegDescribedVar(RegVars, NewReg, Var);
189 LiveEntries[Var].insert(NewIndex);
190 TrackedRegs[NewReg] = true;
191 }
192
193 // Drop tracking of registers that are no longer used.
194 for (auto I : TrackedRegs)
195 if (!I.second)
196 dropRegDescribedVar(RegVars, I.first, Var);
197
David Stenberg5ffec6d2019-04-10 11:28:20 +0000198 // Drop all entries that have ended, and mark the new entry as live.
199 for (auto Index : IndicesToErase)
200 LiveEntries[Var].erase(Index);
201 LiveEntries[Var].insert(NewIndex);
202 }
David Stenberg5ffec6d2019-04-10 11:28:20 +0000203}
204
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000205// Terminate the location range for variables described by register at
Benjamin Kramer6bf8af52014-10-06 15:31:04 +0000206// @I by inserting @ClobberingInstr to their history.
207static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
208 RegDescribedVarsMap::iterator I,
209 DbgValueHistoryMap &HistMap,
David Stenberg5ffec6d2019-04-10 11:28:20 +0000210 DbgValueEntriesMap &LiveEntries,
Benjamin Kramer6bf8af52014-10-06 15:31:04 +0000211 const MachineInstr &ClobberingInstr) {
212 // Iterate over all variables described by this register and add this
213 // instruction to their history, clobbering it.
214 for (const auto &Var : I->second)
David Stenberg5ffec6d2019-04-10 11:28:20 +0000215 clobberRegEntries(Var, I->first, ClobberingInstr, LiveEntries, HistMap);
Benjamin Kramer6bf8af52014-10-06 15:31:04 +0000216 RegVars.erase(I);
217}
218
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000219// Terminate the location range for variables described by register
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000220// @RegNo by inserting @ClobberingInstr to their history.
221static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,
222 DbgValueHistoryMap &HistMap,
David Stenberg5ffec6d2019-04-10 11:28:20 +0000223 DbgValueEntriesMap &LiveEntries,
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000224 const MachineInstr &ClobberingInstr) {
225 const auto &I = RegVars.find(RegNo);
226 if (I == RegVars.end())
227 return;
David Stenberg5ffec6d2019-04-10 11:28:20 +0000228 clobberRegisterUses(RegVars, I, HistMap, LiveEntries, ClobberingInstr);
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000229}
230
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000231void llvm::calculateDbgEntityHistory(const MachineFunction *MF,
232 const TargetRegisterInfo *TRI,
233 DbgValueHistoryMap &DbgValues,
234 DbgLabelInstrMap &DbgLabels) {
Reid Klecknerf6f04f82016-03-25 17:54:46 +0000235 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
236 unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
Daniel Sanders0c476112019-08-15 19:22:08 +0000237 Register FrameReg = TRI->getFrameRegister(*MF);
Alexey Samsonov8000e272014-06-09 21:53:47 +0000238 RegDescribedVarsMap RegVars;
David Stenberg5ffec6d2019-04-10 11:28:20 +0000239 DbgValueEntriesMap LiveEntries;
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000240 for (const auto &MBB : *MF) {
241 for (const auto &MI : MBB) {
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000242 if (MI.isDebugValue()) {
243 assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");
244 // Use the base variable (without any DW_OP_piece expressions)
245 // as index into History. The full variables including the
246 // piece expressions are attached to the MI.
247 const DILocalVariable *RawVar = MI.getDebugVariable();
248 assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
249 "Expected inlined-at fields to agree");
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000250 InlinedEntity Var(RawVar, MI.getDebugLoc()->getInlinedAt());
Shiva Chen801bf7e2018-05-09 02:42:00 +0000251
David Stenberg5ffec6d2019-04-10 11:28:20 +0000252 handleNewDebugValue(Var, MI, RegVars, LiveEntries, DbgValues);
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000253 } else if (MI.isDebugLabel()) {
254 assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");
255 const DILabel *RawLabel = MI.getDebugLabel();
256 assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
257 "Expected inlined-at fields to agree");
258 // When collecting debug information for labels, there is no MCSymbol
259 // generated for it. So, we keep MachineInstr in DbgLabels in order
260 // to query MCSymbol afterward.
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000261 InlinedEntity L(RawLabel, MI.getDebugLoc()->getInlinedAt());
Hsiangkai Wang2532ac82018-08-17 15:22:04 +0000262 DbgLabels.addInstr(L, MI);
263 }
Alexey Samsonovdfcaf9c2014-05-20 18:34:54 +0000264
Tom Weaver453dc4d2019-12-20 14:03:34 +0000265 // Meta Instructions have no output and do not change any values and so
266 // can be safely ignored.
267 if (MI.isMetaInstruction())
Jeremy Morsebcff4172019-06-10 15:23:46 +0000268 continue;
269
270 // Not a DBG_VALUE instruction. It may clobber registers which describe
271 // some variables.
272 for (const MachineOperand &MO : MI.operands()) {
273 if (MO.isReg() && MO.isDef() && MO.getReg()) {
274 // Ignore call instructions that claim to clobber SP. The AArch64
275 // backend does this for aggregate function arguments.
276 if (MI.isCall() && MO.getReg() == SP)
277 continue;
278 // If this is a virtual register, only clobber it since it doesn't
279 // have aliases.
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000280 if (Register::isVirtualRegister(MO.getReg()))
Jeremy Morsebcff4172019-06-10 15:23:46 +0000281 clobberRegisterUses(RegVars, MO.getReg(), DbgValues, LiveEntries,
282 MI);
283 // If this is a register def operand, it may end a debug value
Jeremy Morse181bf0c2019-06-13 10:03:17 +0000284 // range. Ignore frame-register defs in the epilogue and prologue,
285 // we expect debuggers to understand that stack-locations are
286 // invalid outside of the function body.
Jeremy Morsebcff4172019-06-10 15:23:46 +0000287 else if (MO.getReg() != FrameReg ||
Jeremy Morse181bf0c2019-06-13 10:03:17 +0000288 (!MI.getFlag(MachineInstr::FrameDestroy) &&
289 !MI.getFlag(MachineInstr::FrameSetup))) {
Jeremy Morsebcff4172019-06-10 15:23:46 +0000290 for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
291 ++AI)
292 clobberRegisterUses(RegVars, *AI, DbgValues, LiveEntries, MI);
293 }
294 } else if (MO.isRegMask()) {
295 // If this is a register mask operand, clobber all debug values in
296 // non-CSRs.
297 SmallVector<unsigned, 32> RegsToClobber;
298 // Don't consider SP to be clobbered by register masks.
299 for (auto It : RegVars) {
300 unsigned int Reg = It.first;
Daniel Sanders2bea69b2019-08-01 23:27:28 +0000301 if (Reg != SP && Register::isPhysicalRegister(Reg) &&
Jeremy Morsebcff4172019-06-10 15:23:46 +0000302 MO.clobbersPhysReg(Reg))
303 RegsToClobber.push_back(Reg);
304 }
305
306 for (unsigned Reg : RegsToClobber) {
307 clobberRegisterUses(RegVars, Reg, DbgValues, LiveEntries, MI);
308 }
309 }
310 } // End MO loop.
311 } // End instr loop.
312
313 // Make sure locations for all variables are valid only until the end of
314 // the basic block (unless it's the last basic block, in which case let
315 // their liveness run off to the end of the function).
Benjamin Kramer6bf8af52014-10-06 15:31:04 +0000316 if (!MBB.empty() && &MBB != &MF->back()) {
Jeremy Morsebcff4172019-06-10 15:23:46 +0000317 // Iterate over all variables that have open debug values.
318 for (auto &Pair : LiveEntries) {
319 if (Pair.second.empty())
320 continue;
321
322 // Create a clobbering entry.
323 EntryIndex ClobIdx = DbgValues.startClobber(Pair.first, MBB.back());
324
325 // End all entries.
326 for (EntryIndex Idx : Pair.second) {
327 DbgValueHistoryMap::Entry &Ent = DbgValues.getEntry(Pair.first, Idx);
328 assert(Ent.isDbgValue() && !Ent.isClosed());
329 Ent.endEntry(ClobIdx);
330 }
Benjamin Kramer6bf8af52014-10-06 15:31:04 +0000331 }
Jeremy Morsebcff4172019-06-10 15:23:46 +0000332
333 LiveEntries.clear();
334 RegVars.clear();
Alexey Samsonov8000e272014-06-09 21:53:47 +0000335 }
Alexey Samsonov414b6fb2014-04-30 21:34:11 +0000336 }
337}
Vedant Kumar7224c082018-06-01 22:33:15 +0000338
339#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
340LLVM_DUMP_METHOD void DbgValueHistoryMap::dump() const {
341 dbgs() << "DbgValueHistoryMap:\n";
342 for (const auto &VarRangePair : *this) {
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000343 const InlinedEntity &Var = VarRangePair.first;
David Stenberg6feef562019-04-10 09:07:43 +0000344 const Entries &Entries = VarRangePair.second;
Vedant Kumar7224c082018-06-01 22:33:15 +0000345
Hsiangkai Wang760c1ab2018-09-06 02:22:06 +0000346 const DILocalVariable *LocalVar = cast<DILocalVariable>(Var.first);
Vedant Kumar7224c082018-06-01 22:33:15 +0000347 const DILocation *Location = Var.second;
348
349 dbgs() << " - " << LocalVar->getName() << " at ";
350
351 if (Location)
352 dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
353 << Location->getColumn();
354 else
355 dbgs() << "<unknown location>";
356
357 dbgs() << " --\n";
358
David Stenberg5ffec6d2019-04-10 11:28:20 +0000359 for (const auto &E : enumerate(Entries)) {
360 const auto &Entry = E.value();
361 dbgs() << " Entry[" << E.index() << "]: ";
362 if (Entry.isDbgValue())
363 dbgs() << "Debug value\n";
364 else
365 dbgs() << "Clobber\n";
366 dbgs() << " Instr: " << *Entry.getInstr();
367 if (Entry.isDbgValue()) {
368 if (Entry.getEndIndex() == NoEntry)
369 dbgs() << " - Valid until end of function\n";
370 else
371 dbgs() << " - Closed by Entry[" << Entry.getEndIndex() << "]\n";
372 }
Vedant Kumar7224c082018-06-01 22:33:15 +0000373 dbgs() << "\n";
374 }
375 }
376}
377#endif