blob: 690b429832a5a81ac504df70dc13577caeb1f6b8 [file] [log] [blame]
Devang Patele1649c32011-08-10 19:04:06 +00001//===- LexicalScopes.cpp - Collecting lexical scope info ------------------===//
2//
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
Devang Patele1649c32011-08-10 19:04:06 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements LexicalScopes analysis.
10//
11// This pass collects lexical scope information and maps machine instructions
12// to respective lexical scopes.
13//
14//===----------------------------------------------------------------------===//
15
Chandler Carruth6bda14b2017-06-06 11:49:48 +000016#include "llvm/CodeGen/LexicalScopes.h"
Eugene Zelenko5db84df2017-02-17 21:43:25 +000017#include "llvm/ADT/DenseMap.h"
18#include "llvm/ADT/SmallVector.h"
Eugene Zelenko5db84df2017-02-17 21:43:25 +000019#include "llvm/CodeGen/MachineBasicBlock.h"
Devang Patele1649c32011-08-10 19:04:06 +000020#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstr.h"
Nico Weber432a3882018-04-30 14:59:11 +000022#include "llvm/Config/llvm-config.h"
Eugene Zelenko5db84df2017-02-17 21:43:25 +000023#include "llvm/IR/DebugInfoMetadata.h"
Reid Kleckner1d7b4132019-10-19 00:22:07 +000024#include "llvm/IR/Function.h"
Eugene Zelenko5db84df2017-02-17 21:43:25 +000025#include "llvm/IR/Metadata.h"
26#include "llvm/Support/Casting.h"
27#include "llvm/Support/Compiler.h"
Devang Patele1649c32011-08-10 19:04:06 +000028#include "llvm/Support/Debug.h"
Eugene Zelenko5db84df2017-02-17 21:43:25 +000029#include "llvm/Support/raw_ostream.h"
30#include <cassert>
31#include <string>
32#include <tuple>
33#include <utility>
34
Devang Patele1649c32011-08-10 19:04:06 +000035using namespace llvm;
36
Chandler Carruth1b9dde02014-04-22 02:02:50 +000037#define DEBUG_TYPE "lexicalscopes"
38
Eric Christopherb7dee8a2013-11-20 00:54:28 +000039/// reset - Reset the instance so that it's prepared for another function.
40void LexicalScopes::reset() {
Craig Topperc0196b12014-04-14 00:51:57 +000041 MF = nullptr;
42 CurrentFnLexicalScope = nullptr;
David Blaikie2f143e02014-05-08 22:24:51 +000043 LexicalScopeMap.clear();
44 AbstractScopeMap.clear();
Devang Patele1649c32011-08-10 19:04:06 +000045 InlinedLexicalScopeMap.clear();
46 AbstractScopesList.clear();
Vedant Kumar19876262020-05-28 15:57:11 -070047 DominatedBlocks.clear();
Devang Patele1649c32011-08-10 19:04:06 +000048}
49
50/// initialize - Scan machine function and constuct lexical scope nest.
51void LexicalScopes::initialize(const MachineFunction &Fn) {
Wolfgang Piebe018bbd2017-07-19 19:36:40 +000052 reset();
Teresa Johnson76b5b742017-02-17 00:21:19 +000053 // Don't attempt any lexical scope creation for a NoDebug compile unit.
Matthias Braunf1caa282017-12-15 22:22:58 +000054 if (Fn.getFunction().getSubprogram()->getUnit()->getEmissionKind() ==
Teresa Johnson76b5b742017-02-17 00:21:19 +000055 DICompileUnit::NoDebug)
56 return;
Devang Patele1649c32011-08-10 19:04:06 +000057 MF = &Fn;
58 SmallVector<InsnRange, 4> MIRanges;
59 DenseMap<const MachineInstr *, LexicalScope *> MI2ScopeMap;
60 extractLexicalScopes(MIRanges, MI2ScopeMap);
61 if (CurrentFnLexicalScope) {
62 constructScopeNest(CurrentFnLexicalScope);
63 assignInstructionRanges(MIRanges, MI2ScopeMap);
64 }
65}
66
67/// extractLexicalScopes - Extract instruction ranges for each lexical scopes
68/// for the given machine function.
Eric Christopher6211e4b2013-11-20 00:54:19 +000069void LexicalScopes::extractLexicalScopes(
70 SmallVectorImpl<InsnRange> &MIRanges,
71 DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
Devang Patele1649c32011-08-10 19:04:06 +000072 // Scan each instruction and create scopes. First build working set of scopes.
Alexey Samsonov41b977d2014-04-30 18:29:51 +000073 for (const auto &MBB : *MF) {
Craig Topperc0196b12014-04-14 00:51:57 +000074 const MachineInstr *RangeBeginMI = nullptr;
75 const MachineInstr *PrevMI = nullptr;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000076 const DILocation *PrevDL = nullptr;
Alexey Samsonovf74bde62014-04-30 22:17:38 +000077 for (const auto &MInsn : MBB) {
Devang Patele1649c32011-08-10 19:04:06 +000078 // Check if instruction has valid location information.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000079 const DILocation *MIDL = MInsn.getDebugLoc();
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +000080 if (!MIDL) {
Alexey Samsonovf74bde62014-04-30 22:17:38 +000081 PrevMI = &MInsn;
Devang Patele1649c32011-08-10 19:04:06 +000082 continue;
83 }
84
85 // If scope has not changed then skip this instruction.
86 if (MIDL == PrevDL) {
Alexey Samsonovf74bde62014-04-30 22:17:38 +000087 PrevMI = &MInsn;
Devang Patele1649c32011-08-10 19:04:06 +000088 continue;
89 }
90
Adrian Prantlfb31da12017-05-22 20:47:09 +000091 // Ignore DBG_VALUE and similar instruction that do not contribute to any
92 // instruction in the output.
93 if (MInsn.isMetaInstruction())
Devang Patele1649c32011-08-10 19:04:06 +000094 continue;
95
96 if (RangeBeginMI) {
97 // If we have already seen a beginning of an instruction range and
98 // current instruction scope does not match scope of first instruction
99 // in this range then create a new instruction range.
100 InsnRange R(RangeBeginMI, PrevMI);
101 MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL);
102 MIRanges.push_back(R);
103 }
104
105 // This is a beginning of a new instruction range.
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000106 RangeBeginMI = &MInsn;
Devang Patele1649c32011-08-10 19:04:06 +0000107
108 // Reset previous markers.
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000109 PrevMI = &MInsn;
Devang Patele1649c32011-08-10 19:04:06 +0000110 PrevDL = MIDL;
111 }
112
113 // Create last instruction range.
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000114 if (RangeBeginMI && PrevMI && PrevDL) {
Devang Patele1649c32011-08-10 19:04:06 +0000115 InsnRange R(RangeBeginMI, PrevMI);
116 MIRanges.push_back(R);
117 MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL);
118 }
119 }
120}
121
122/// findLexicalScope - Find lexical scope, either regular or inlined, for the
123/// given DebugLoc. Return NULL if not found.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000124LexicalScope *LexicalScopes::findLexicalScope(const DILocation *DL) {
125 DILocalScope *Scope = DL->getScope();
Eric Christopher6211e4b2013-11-20 00:54:19 +0000126 if (!Scope)
Craig Topperc0196b12014-04-14 00:51:57 +0000127 return nullptr;
Eric Christopher6647b832011-10-11 22:59:11 +0000128
129 // The scope that we were created with could have an extra file - which
130 // isn't what we care about in this case.
Amjad Abouda5ba9912016-04-21 16:58:49 +0000131 Scope = Scope->getNonLexicalBlockFileScope();
Eric Christopher6211e4b2013-11-20 00:54:19 +0000132
Duncan P. N. Exon Smith5a227ff2015-03-30 21:54:46 +0000133 if (auto *IA = DL->getInlinedAt()) {
David Blaikie9b8c8cd2014-05-14 01:08:28 +0000134 auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));
135 return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;
136 }
David Blaikie2f143e02014-05-08 22:24:51 +0000137 return findLexicalScope(Scope);
Devang Patele1649c32011-08-10 19:04:06 +0000138}
139
140/// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
141/// not available then create new lexical scope.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000142LexicalScope *LexicalScopes::getOrCreateLexicalScope(const DILocalScope *Scope,
143 const DILocation *IA) {
Duncan P. N. Exon Smith82eba742015-03-30 23:47:26 +0000144 if (IA) {
Teresa Johnson76b5b742017-02-17 00:21:19 +0000145 // Skip scopes inlined from a NoDebug compile unit.
146 if (Scope->getSubprogram()->getUnit()->getEmissionKind() ==
147 DICompileUnit::NoDebug)
148 return getOrCreateLexicalScope(IA);
Devang Patele1649c32011-08-10 19:04:06 +0000149 // Create an abstract scope for inlined function.
150 getOrCreateAbstractScope(Scope);
151 // Create an inlined scope for inlined function.
Duncan P. N. Exon Smith82eba742015-03-30 23:47:26 +0000152 return getOrCreateInlinedScope(Scope, IA);
Devang Patele1649c32011-08-10 19:04:06 +0000153 }
Eric Christopher6211e4b2013-11-20 00:54:19 +0000154
Devang Patele1649c32011-08-10 19:04:06 +0000155 return getOrCreateRegularScope(Scope);
156}
157
158/// getOrCreateRegularScope - Find or create a regular lexical scope.
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000159LexicalScope *
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000160LexicalScopes::getOrCreateRegularScope(const DILocalScope *Scope) {
Amjad Abouda5ba9912016-04-21 16:58:49 +0000161 assert(Scope && "Invalid Scope encoding!");
162 Scope = Scope->getNonLexicalBlockFileScope();
Eric Christopher6211e4b2013-11-20 00:54:19 +0000163
David Blaikie2f143e02014-05-08 22:24:51 +0000164 auto I = LexicalScopeMap.find(Scope);
165 if (I != LexicalScopeMap.end())
166 return &I->second;
Devang Patele1649c32011-08-10 19:04:06 +0000167
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000168 // FIXME: Should the following dyn_cast be DILexicalBlock?
Craig Topperc0196b12014-04-14 00:51:57 +0000169 LexicalScope *Parent = nullptr;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000170 if (auto *Block = dyn_cast<DILexicalBlockBase>(Scope))
Duncan P. N. Exon Smith82eba742015-03-30 23:47:26 +0000171 Parent = getOrCreateLexicalScope(Block->getScope());
Aaron Ballmanf17583e2015-02-16 18:21:19 +0000172 I = LexicalScopeMap.emplace(std::piecewise_construct,
173 std::forward_as_tuple(Scope),
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000174 std::forward_as_tuple(Parent, Scope, nullptr,
175 false)).first;
David Blaikie2f143e02014-05-08 22:24:51 +0000176
David Blaikie3dfe4782014-10-14 18:22:52 +0000177 if (!Parent) {
Matthias Braunf1caa282017-12-15 22:22:58 +0000178 assert(cast<DISubprogram>(Scope)->describes(&MF->getFunction()));
David Blaikie3dfe4782014-10-14 18:22:52 +0000179 assert(!CurrentFnLexicalScope);
David Blaikie2f143e02014-05-08 22:24:51 +0000180 CurrentFnLexicalScope = &I->second;
David Blaikie3dfe4782014-10-14 18:22:52 +0000181 }
Eric Christopher6211e4b2013-11-20 00:54:19 +0000182
David Blaikie2f143e02014-05-08 22:24:51 +0000183 return &I->second;
Devang Patele1649c32011-08-10 19:04:06 +0000184}
185
186/// getOrCreateInlinedScope - Find or create an inlined lexical scope.
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000187LexicalScope *
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000188LexicalScopes::getOrCreateInlinedScope(const DILocalScope *Scope,
189 const DILocation *InlinedAt) {
Amjad Abouda5ba9912016-04-21 16:58:49 +0000190 assert(Scope && "Invalid Scope encoding!");
191 Scope = Scope->getNonLexicalBlockFileScope();
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000192 std::pair<const DILocalScope *, const DILocation *> P(Scope, InlinedAt);
David Blaikie9b8c8cd2014-05-14 01:08:28 +0000193 auto I = InlinedLexicalScopeMap.find(P);
194 if (I != InlinedLexicalScopeMap.end())
David Blaikie2f143e02014-05-08 22:24:51 +0000195 return &I->second;
Devang Patele1649c32011-08-10 19:04:06 +0000196
David Blaikie9b8c8cd2014-05-14 01:08:28 +0000197 LexicalScope *Parent;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000198 if (auto *Block = dyn_cast<DILexicalBlockBase>(Scope))
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000199 Parent = getOrCreateInlinedScope(Block->getScope(), InlinedAt);
David Blaikie9b8c8cd2014-05-14 01:08:28 +0000200 else
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000201 Parent = getOrCreateLexicalScope(InlinedAt);
David Blaikie9b8c8cd2014-05-14 01:08:28 +0000202
Eric Christopher14303d12017-02-14 19:43:50 +0000203 I = InlinedLexicalScopeMap
204 .emplace(std::piecewise_construct, std::forward_as_tuple(P),
205 std::forward_as_tuple(Parent, Scope, InlinedAt, false))
Aaron Ballmanf17583e2015-02-16 18:21:19 +0000206 .first;
David Blaikie2f143e02014-05-08 22:24:51 +0000207 return &I->second;
Devang Patele1649c32011-08-10 19:04:06 +0000208}
209
210/// getOrCreateAbstractScope - Find or create an abstract lexical scope.
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000211LexicalScope *
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000212LexicalScopes::getOrCreateAbstractScope(const DILocalScope *Scope) {
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000213 assert(Scope && "Invalid Scope encoding!");
Amjad Abouda5ba9912016-04-21 16:58:49 +0000214 Scope = Scope->getNonLexicalBlockFileScope();
David Blaikieea862262014-05-25 18:11:35 +0000215 auto I = AbstractScopeMap.find(Scope);
David Blaikie2f143e02014-05-08 22:24:51 +0000216 if (I != AbstractScopeMap.end())
217 return &I->second;
Devang Patele1649c32011-08-10 19:04:06 +0000218
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000219 // FIXME: Should the following isa be DILexicalBlock?
Craig Topperc0196b12014-04-14 00:51:57 +0000220 LexicalScope *Parent = nullptr;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000221 if (auto *Block = dyn_cast<DILexicalBlockBase>(Scope))
Duncan P. N. Exon Smith33af7a82015-03-30 23:21:21 +0000222 Parent = getOrCreateAbstractScope(Block->getScope());
223
David Blaikie2f143e02014-05-08 22:24:51 +0000224 I = AbstractScopeMap.emplace(std::piecewise_construct,
David Blaikieea862262014-05-25 18:11:35 +0000225 std::forward_as_tuple(Scope),
226 std::forward_as_tuple(Parent, Scope,
David Blaikie2f143e02014-05-08 22:24:51 +0000227 nullptr, true)).first;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000228 if (isa<DISubprogram>(Scope))
David Blaikie2f143e02014-05-08 22:24:51 +0000229 AbstractScopesList.push_back(&I->second);
230 return &I->second;
Devang Patele1649c32011-08-10 19:04:06 +0000231}
232
Jan-Willem Maessen3610d312020-06-08 18:38:16 +0100233/// constructScopeNest - Traverse the Scope tree depth-first, storing
234/// traversal state in WorkStack and recording the depth-first
235/// numbering (setDFSIn, setDFSOut) for edge classification.
Devang Patele1649c32011-08-10 19:04:06 +0000236void LexicalScopes::constructScopeNest(LexicalScope *Scope) {
Eric Christopher6211e4b2013-11-20 00:54:19 +0000237 assert(Scope && "Unable to calculate scope dominance graph!");
Jan-Willem Maessen3610d312020-06-08 18:38:16 +0100238 SmallVector<std::pair<LexicalScope *, size_t>, 4> WorkStack;
239 WorkStack.push_back(std::make_pair(Scope, 0));
Devang Patele1649c32011-08-10 19:04:06 +0000240 unsigned Counter = 0;
241 while (!WorkStack.empty()) {
Jan-Willem Maessen3610d312020-06-08 18:38:16 +0100242 auto &ScopePosition = WorkStack.back();
243 LexicalScope *WS = ScopePosition.first;
244 size_t ChildNum = ScopePosition.second++;
Craig Topper80170e52013-07-03 04:30:58 +0000245 const SmallVectorImpl<LexicalScope *> &Children = WS->getChildren();
Jan-Willem Maessen3610d312020-06-08 18:38:16 +0100246 if (ChildNum < Children.size()) {
247 auto &ChildScope = Children[ChildNum];
248 WorkStack.push_back(std::make_pair(ChildScope, 0));
249 ChildScope->setDFSIn(++Counter);
250 } else {
Devang Patele1649c32011-08-10 19:04:06 +0000251 WorkStack.pop_back();
252 WS->setDFSOut(++Counter);
253 }
254 }
255}
256
Devang Patel784077e2011-08-10 23:58:09 +0000257/// assignInstructionRanges - Find ranges of instructions covered by each
258/// lexical scope.
Eric Christopher6211e4b2013-11-20 00:54:19 +0000259void LexicalScopes::assignInstructionRanges(
260 SmallVectorImpl<InsnRange> &MIRanges,
261 DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
Craig Topperc0196b12014-04-14 00:51:57 +0000262 LexicalScope *PrevLexicalScope = nullptr;
Adrian Prantl16b2ace2016-09-28 17:31:17 +0000263 for (const auto &R : MIRanges) {
Devang Patele1649c32011-08-10 19:04:06 +0000264 LexicalScope *S = MI2ScopeMap.lookup(R.first);
Eric Christopher6211e4b2013-11-20 00:54:19 +0000265 assert(S && "Lost LexicalScope for a machine instruction!");
Devang Patele1649c32011-08-10 19:04:06 +0000266 if (PrevLexicalScope && !PrevLexicalScope->dominates(S))
267 PrevLexicalScope->closeInsnRange(S);
268 S->openInsnRange(R.first);
269 S->extendInsnRange(R.second);
270 PrevLexicalScope = S;
271 }
272
273 if (PrevLexicalScope)
274 PrevLexicalScope->closeInsnRange();
275}
276
277/// getMachineBasicBlocks - Populate given set using machine basic blocks which
Eric Christopher6211e4b2013-11-20 00:54:19 +0000278/// have machine instructions that belong to lexical scope identified by
Devang Patele1649c32011-08-10 19:04:06 +0000279/// DebugLoc.
Eric Christopher6211e4b2013-11-20 00:54:19 +0000280void LexicalScopes::getMachineBasicBlocks(
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000281 const DILocation *DL, SmallPtrSetImpl<const MachineBasicBlock *> &MBBs) {
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000282 assert(MF && "Method called on a uninitialized LexicalScopes object!");
Devang Patele1649c32011-08-10 19:04:06 +0000283 MBBs.clear();
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000284
Devang Patele1649c32011-08-10 19:04:06 +0000285 LexicalScope *Scope = getOrCreateLexicalScope(DL);
286 if (!Scope)
287 return;
Eric Christopher6211e4b2013-11-20 00:54:19 +0000288
Devang Pateldb4374a2011-08-12 18:01:34 +0000289 if (Scope == CurrentFnLexicalScope) {
Alexey Samsonov41b977d2014-04-30 18:29:51 +0000290 for (const auto &MBB : *MF)
291 MBBs.insert(&MBB);
Devang Pateldb4374a2011-08-12 18:01:34 +0000292 return;
293 }
294
Jeremy Morse6af859dcc2020-02-28 10:41:23 +0000295 // The scope ranges can cover multiple basic blocks in each span. Iterate over
296 // all blocks (in the order they are in the function) until we reach the one
297 // containing the end of the span.
Craig Topper80170e52013-07-03 04:30:58 +0000298 SmallVectorImpl<InsnRange> &InsnRanges = Scope->getRanges();
Adrian Prantl16b2ace2016-09-28 17:31:17 +0000299 for (auto &R : InsnRanges)
Jeremy Morse6af859dcc2020-02-28 10:41:23 +0000300 for (auto CurMBBIt = R.first->getParent()->getIterator(),
301 EndBBIt = std::next(R.second->getParent()->getIterator());
302 CurMBBIt != EndBBIt; CurMBBIt++)
303 MBBs.insert(&*CurMBBIt);
Devang Patele1649c32011-08-10 19:04:06 +0000304}
305
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000306bool LexicalScopes::dominates(const DILocation *DL, MachineBasicBlock *MBB) {
Wolfgang Piebe018bbd2017-07-19 19:36:40 +0000307 assert(MF && "Unexpected uninitialized LexicalScopes object!");
Devang Patele1649c32011-08-10 19:04:06 +0000308 LexicalScope *Scope = getOrCreateLexicalScope(DL);
309 if (!Scope)
310 return false;
Devang Pateldb4374a2011-08-12 18:01:34 +0000311
312 // Current function scope covers all basic blocks in the function.
313 if (Scope == CurrentFnLexicalScope && MBB->getParent() == MF)
314 return true;
315
Jeremy Morse6af859dcc2020-02-28 10:41:23 +0000316 // Fetch all the blocks in DLs scope. Because the range / block list also
Vedant Kumar19876262020-05-28 15:57:11 -0700317 // contain any subscopes, any instruction that DL dominates can be found in
318 // the block set.
319 //
320 // Cache the set of fetched blocks to avoid repeatedly recomputing the set in
321 // the LiveDebugValues pass.
322 std::unique_ptr<BlockSetT> &Set = DominatedBlocks[DL];
323 if (!Set) {
324 Set = std::make_unique<BlockSetT>();
325 getMachineBasicBlocks(DL, *Set);
326 }
327 return Set->count(MBB) != 0;
Devang Patele1649c32011-08-10 19:04:06 +0000328}
329
Aaron Ballman615eb472017-10-15 14:32:27 +0000330#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000331LLVM_DUMP_METHOD void LexicalScope::dump(unsigned Indent) const {
Devang Patele1649c32011-08-10 19:04:06 +0000332 raw_ostream &err = dbgs();
Manman Rene498b252013-02-02 00:02:03 +0000333 err.indent(Indent);
Devang Patele1649c32011-08-10 19:04:06 +0000334 err << "DFSIn: " << DFSIn << " DFSOut: " << DFSOut << "\n";
335 const MDNode *N = Desc;
Manman Rene498b252013-02-02 00:02:03 +0000336 err.indent(Indent);
Devang Patele1649c32011-08-10 19:04:06 +0000337 N->dump();
338 if (AbstractScope)
Manman Rene498b252013-02-02 00:02:03 +0000339 err << std::string(Indent, ' ') << "Abstract Scope\n";
Devang Patele1649c32011-08-10 19:04:06 +0000340
Devang Patele1649c32011-08-10 19:04:06 +0000341 if (!Children.empty())
Manman Rene498b252013-02-02 00:02:03 +0000342 err << std::string(Indent + 2, ' ') << "Children ...\n";
Devang Patele1649c32011-08-10 19:04:06 +0000343 for (unsigned i = 0, e = Children.size(); i != e; ++i)
344 if (Children[i] != this)
Manman Rene498b252013-02-02 00:02:03 +0000345 Children[i]->dump(Indent + 2);
Devang Patele1649c32011-08-10 19:04:06 +0000346}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000347#endif