2011-08-10 19:04:06 +00:00
|
|
|
//===- LexicalScopes.cpp - Collecting lexical scope info ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements LexicalScopes analysis.
|
|
|
|
//
|
|
|
|
// This pass collects lexical scope information and maps machine instructions
|
|
|
|
// to respective lexical scopes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/LexicalScopes.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2014-03-06 00:46:21 +00:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
2011-08-10 19:04:06 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 02:02:50 +00:00
|
|
|
#define DEBUG_TYPE "lexicalscopes"
|
|
|
|
|
2013-11-20 00:54:28 +00:00
|
|
|
/// reset - Reset the instance so that it's prepared for another function.
|
|
|
|
void LexicalScopes::reset() {
|
2014-04-14 00:51:57 +00:00
|
|
|
MF = nullptr;
|
|
|
|
CurrentFnLexicalScope = nullptr;
|
2014-05-08 22:24:51 +00:00
|
|
|
LexicalScopeMap.clear();
|
|
|
|
AbstractScopeMap.clear();
|
2011-08-10 19:04:06 +00:00
|
|
|
InlinedLexicalScopeMap.clear();
|
|
|
|
AbstractScopesList.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// initialize - Scan machine function and constuct lexical scope nest.
|
|
|
|
void LexicalScopes::initialize(const MachineFunction &Fn) {
|
2013-11-20 00:54:28 +00:00
|
|
|
reset();
|
2011-08-10 19:04:06 +00:00
|
|
|
MF = &Fn;
|
|
|
|
SmallVector<InsnRange, 4> MIRanges;
|
|
|
|
DenseMap<const MachineInstr *, LexicalScope *> MI2ScopeMap;
|
|
|
|
extractLexicalScopes(MIRanges, MI2ScopeMap);
|
|
|
|
if (CurrentFnLexicalScope) {
|
|
|
|
constructScopeNest(CurrentFnLexicalScope);
|
|
|
|
assignInstructionRanges(MIRanges, MI2ScopeMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// extractLexicalScopes - Extract instruction ranges for each lexical scopes
|
|
|
|
/// for the given machine function.
|
2013-11-20 00:54:19 +00:00
|
|
|
void LexicalScopes::extractLexicalScopes(
|
|
|
|
SmallVectorImpl<InsnRange> &MIRanges,
|
|
|
|
DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
|
2011-08-10 19:04:06 +00:00
|
|
|
|
|
|
|
// Scan each instruction and create scopes. First build working set of scopes.
|
2014-04-30 18:29:51 +00:00
|
|
|
for (const auto &MBB : *MF) {
|
2014-04-14 00:51:57 +00:00
|
|
|
const MachineInstr *RangeBeginMI = nullptr;
|
|
|
|
const MachineInstr *PrevMI = nullptr;
|
2011-08-10 19:04:06 +00:00
|
|
|
DebugLoc PrevDL;
|
2014-04-30 22:17:38 +00:00
|
|
|
for (const auto &MInsn : MBB) {
|
2011-08-10 19:04:06 +00:00
|
|
|
// Check if instruction has valid location information.
|
2014-04-30 22:17:38 +00:00
|
|
|
const DebugLoc MIDL = MInsn.getDebugLoc();
|
2011-08-10 19:04:06 +00:00
|
|
|
if (MIDL.isUnknown()) {
|
2014-04-30 22:17:38 +00:00
|
|
|
PrevMI = &MInsn;
|
2011-08-10 19:04:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If scope has not changed then skip this instruction.
|
|
|
|
if (MIDL == PrevDL) {
|
2014-04-30 22:17:38 +00:00
|
|
|
PrevMI = &MInsn;
|
2011-08-10 19:04:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore DBG_VALUE. It does not contribute to any instruction in output.
|
2014-04-30 22:17:38 +00:00
|
|
|
if (MInsn.isDebugValue())
|
2011-08-10 19:04:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (RangeBeginMI) {
|
|
|
|
// If we have already seen a beginning of an instruction range and
|
|
|
|
// current instruction scope does not match scope of first instruction
|
|
|
|
// in this range then create a new instruction range.
|
|
|
|
InsnRange R(RangeBeginMI, PrevMI);
|
|
|
|
MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL);
|
|
|
|
MIRanges.push_back(R);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a beginning of a new instruction range.
|
2014-04-30 22:17:38 +00:00
|
|
|
RangeBeginMI = &MInsn;
|
2011-08-10 19:04:06 +00:00
|
|
|
|
|
|
|
// Reset previous markers.
|
2014-04-30 22:17:38 +00:00
|
|
|
PrevMI = &MInsn;
|
2011-08-10 19:04:06 +00:00
|
|
|
PrevDL = MIDL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create last instruction range.
|
|
|
|
if (RangeBeginMI && PrevMI && !PrevDL.isUnknown()) {
|
|
|
|
InsnRange R(RangeBeginMI, PrevMI);
|
|
|
|
MIRanges.push_back(R);
|
|
|
|
MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findLexicalScope - Find lexical scope, either regular or inlined, for the
|
|
|
|
/// given DebugLoc. Return NULL if not found.
|
|
|
|
LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) {
|
2014-04-14 00:51:57 +00:00
|
|
|
MDNode *Scope = nullptr;
|
|
|
|
MDNode *IA = nullptr;
|
2011-08-10 19:04:06 +00:00
|
|
|
DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext());
|
2013-11-20 00:54:19 +00:00
|
|
|
if (!Scope)
|
2014-04-14 00:51:57 +00:00
|
|
|
return nullptr;
|
2011-10-11 22:59:11 +00:00
|
|
|
|
|
|
|
// The scope that we were created with could have an extra file - which
|
|
|
|
// isn't what we care about in this case.
|
|
|
|
DIDescriptor D = DIDescriptor(Scope);
|
|
|
|
if (D.isLexicalBlockFile())
|
|
|
|
Scope = DILexicalBlockFile(Scope).getScope();
|
2013-11-20 00:54:19 +00:00
|
|
|
|
2014-05-14 01:08:28 +00:00
|
|
|
if (IA) {
|
|
|
|
auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));
|
|
|
|
return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;
|
|
|
|
}
|
2014-05-08 22:24:51 +00:00
|
|
|
return findLexicalScope(Scope);
|
2011-08-10 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
|
|
|
|
/// not available then create new lexical scope.
|
|
|
|
LexicalScope *LexicalScopes::getOrCreateLexicalScope(DebugLoc DL) {
|
DebugInfo: Ensure that all debug location scope chains from instructions within a function, lead to the function itself.
Let me tell you a tale...
Originally committed in r211723 after discovering a nasty case of weird
scoping due to inlining, this was reverted in r211724 after it fired in
ASan/compiler-rt.
(minor diversion where I accidentally committed/reverted again in
r211871/r211873)
After further testing and fixing bugs in ArgumentPromotion (r211872) and
Inlining (r212065) it was recommitted in r212085. Reverted in r212089
after the sanitizer buildbots still showed problems.
Fixed another bug in ArgumentPromotion (r212128) found by this
assertion.
Recommitted in r212205, reverted in r212226 after it crashed some more
on sanitizer buildbots.
Fix clang some more in r212761.
Recommitted in r212776, reverted in r212793. ASan failures.
Recommitted in r213391, reverted in r213432, trying to reproduce flakey
ASan build failure.
Fixed bugs in r213805 (ArgPromo + DebugInfo), r213952
(LiveDebugVariables strips dbg_value intrinsics in functions not
described by debug info).
Recommitted in r214761, reverted in r214999, flakey failure on Windows
buildbot.
Fixed DeadArgElimination + DebugInfo bug in r219210.
Recommitted in r219215, reverted in r219512, failure on ObjC++ atomic
properties in the test-suite on Darwin.
Fixed ObjC++ atomic properties issue in Clang in r219690.
[This commit is provided 'as is' with no hope that this is the last time
I commit this change either expressed or implied]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219702 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-14 18:22:52 +00:00
|
|
|
if (DL.isUnknown())
|
|
|
|
return nullptr;
|
2014-04-14 00:51:57 +00:00
|
|
|
MDNode *Scope = nullptr;
|
|
|
|
MDNode *InlinedAt = nullptr;
|
2011-08-10 19:04:06 +00:00
|
|
|
DL.getScopeAndInlinedAt(Scope, InlinedAt, MF->getFunction()->getContext());
|
2011-10-11 22:59:11 +00:00
|
|
|
|
2011-08-10 19:04:06 +00:00
|
|
|
if (InlinedAt) {
|
|
|
|
// Create an abstract scope for inlined function.
|
|
|
|
getOrCreateAbstractScope(Scope);
|
|
|
|
// Create an inlined scope for inlined function.
|
|
|
|
return getOrCreateInlinedScope(Scope, InlinedAt);
|
|
|
|
}
|
2013-11-20 00:54:19 +00:00
|
|
|
|
2011-08-10 19:04:06 +00:00
|
|
|
return getOrCreateRegularScope(Scope);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateRegularScope - Find or create a regular lexical scope.
|
|
|
|
LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) {
|
2011-10-11 22:59:11 +00:00
|
|
|
DIDescriptor D = DIDescriptor(Scope);
|
2011-10-13 21:43:44 +00:00
|
|
|
if (D.isLexicalBlockFile()) {
|
2011-10-11 22:59:11 +00:00
|
|
|
Scope = DILexicalBlockFile(Scope).getScope();
|
2011-10-13 21:43:44 +00:00
|
|
|
D = DIDescriptor(Scope);
|
|
|
|
}
|
2013-11-20 00:54:19 +00:00
|
|
|
|
2014-05-08 22:24:51 +00:00
|
|
|
auto I = LexicalScopeMap.find(Scope);
|
|
|
|
if (I != LexicalScopeMap.end())
|
|
|
|
return &I->second;
|
2011-08-10 19:04:06 +00:00
|
|
|
|
2014-04-14 00:51:57 +00:00
|
|
|
LexicalScope *Parent = nullptr;
|
2011-10-11 22:59:11 +00:00
|
|
|
if (D.isLexicalBlock())
|
2011-08-10 19:04:06 +00:00
|
|
|
Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope));
|
2015-02-16 18:21:19 +00:00
|
|
|
I = LexicalScopeMap.emplace(std::piecewise_construct,
|
|
|
|
std::forward_as_tuple(Scope),
|
|
|
|
std::forward_as_tuple(Parent, DIDescriptor(Scope),
|
|
|
|
nullptr, false)).first;
|
2014-05-08 22:24:51 +00:00
|
|
|
|
DebugInfo: Ensure that all debug location scope chains from instructions within a function, lead to the function itself.
Let me tell you a tale...
Originally committed in r211723 after discovering a nasty case of weird
scoping due to inlining, this was reverted in r211724 after it fired in
ASan/compiler-rt.
(minor diversion where I accidentally committed/reverted again in
r211871/r211873)
After further testing and fixing bugs in ArgumentPromotion (r211872) and
Inlining (r212065) it was recommitted in r212085. Reverted in r212089
after the sanitizer buildbots still showed problems.
Fixed another bug in ArgumentPromotion (r212128) found by this
assertion.
Recommitted in r212205, reverted in r212226 after it crashed some more
on sanitizer buildbots.
Fix clang some more in r212761.
Recommitted in r212776, reverted in r212793. ASan failures.
Recommitted in r213391, reverted in r213432, trying to reproduce flakey
ASan build failure.
Fixed bugs in r213805 (ArgPromo + DebugInfo), r213952
(LiveDebugVariables strips dbg_value intrinsics in functions not
described by debug info).
Recommitted in r214761, reverted in r214999, flakey failure on Windows
buildbot.
Fixed DeadArgElimination + DebugInfo bug in r219210.
Recommitted in r219215, reverted in r219512, failure on ObjC++ atomic
properties in the test-suite on Darwin.
Fixed ObjC++ atomic properties issue in Clang in r219690.
[This commit is provided 'as is' with no hope that this is the last time
I commit this change either expressed or implied]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219702 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-14 18:22:52 +00:00
|
|
|
if (!Parent) {
|
|
|
|
assert(DIDescriptor(Scope).isSubprogram());
|
|
|
|
assert(DISubprogram(Scope).describes(MF->getFunction()));
|
|
|
|
assert(!CurrentFnLexicalScope);
|
2014-05-08 22:24:51 +00:00
|
|
|
CurrentFnLexicalScope = &I->second;
|
DebugInfo: Ensure that all debug location scope chains from instructions within a function, lead to the function itself.
Let me tell you a tale...
Originally committed in r211723 after discovering a nasty case of weird
scoping due to inlining, this was reverted in r211724 after it fired in
ASan/compiler-rt.
(minor diversion where I accidentally committed/reverted again in
r211871/r211873)
After further testing and fixing bugs in ArgumentPromotion (r211872) and
Inlining (r212065) it was recommitted in r212085. Reverted in r212089
after the sanitizer buildbots still showed problems.
Fixed another bug in ArgumentPromotion (r212128) found by this
assertion.
Recommitted in r212205, reverted in r212226 after it crashed some more
on sanitizer buildbots.
Fix clang some more in r212761.
Recommitted in r212776, reverted in r212793. ASan failures.
Recommitted in r213391, reverted in r213432, trying to reproduce flakey
ASan build failure.
Fixed bugs in r213805 (ArgPromo + DebugInfo), r213952
(LiveDebugVariables strips dbg_value intrinsics in functions not
described by debug info).
Recommitted in r214761, reverted in r214999, flakey failure on Windows
buildbot.
Fixed DeadArgElimination + DebugInfo bug in r219210.
Recommitted in r219215, reverted in r219512, failure on ObjC++ atomic
properties in the test-suite on Darwin.
Fixed ObjC++ atomic properties issue in Clang in r219690.
[This commit is provided 'as is' with no hope that this is the last time
I commit this change either expressed or implied]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219702 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-14 18:22:52 +00:00
|
|
|
}
|
2013-11-20 00:54:19 +00:00
|
|
|
|
2014-05-08 22:24:51 +00:00
|
|
|
return &I->second;
|
2011-08-10 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateInlinedScope - Find or create an inlined lexical scope.
|
2014-05-14 01:08:28 +00:00
|
|
|
LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *ScopeNode,
|
2011-08-10 19:04:06 +00:00
|
|
|
MDNode *InlinedAt) {
|
2014-05-14 01:08:28 +00:00
|
|
|
std::pair<const MDNode*, const MDNode*> P(ScopeNode, InlinedAt);
|
|
|
|
auto I = InlinedLexicalScopeMap.find(P);
|
|
|
|
if (I != InlinedLexicalScopeMap.end())
|
2014-05-08 22:24:51 +00:00
|
|
|
return &I->second;
|
2011-08-10 19:04:06 +00:00
|
|
|
|
2014-05-14 01:08:28 +00:00
|
|
|
LexicalScope *Parent;
|
|
|
|
DILexicalBlock Scope(ScopeNode);
|
|
|
|
if (Scope.isSubprogram())
|
|
|
|
Parent = getOrCreateLexicalScope(DebugLoc::getFromDILocation(InlinedAt));
|
|
|
|
else
|
|
|
|
Parent = getOrCreateInlinedScope(Scope.getContext(), InlinedAt);
|
|
|
|
|
|
|
|
I = InlinedLexicalScopeMap.emplace(std::piecewise_construct,
|
2015-02-16 18:21:19 +00:00
|
|
|
std::forward_as_tuple(P),
|
|
|
|
std::forward_as_tuple(Parent, Scope,
|
|
|
|
InlinedAt, false))
|
|
|
|
.first;
|
2014-05-08 22:24:51 +00:00
|
|
|
return &I->second;
|
2011-08-10 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateAbstractScope - Find or create an abstract lexical scope.
|
|
|
|
LexicalScope *LexicalScopes::getOrCreateAbstractScope(const MDNode *N) {
|
|
|
|
assert(N && "Invalid Scope encoding!");
|
|
|
|
|
2011-10-11 22:59:11 +00:00
|
|
|
DIDescriptor Scope(N);
|
|
|
|
if (Scope.isLexicalBlockFile())
|
|
|
|
Scope = DILexicalBlockFile(Scope).getScope();
|
2014-05-25 18:11:35 +00:00
|
|
|
auto I = AbstractScopeMap.find(Scope);
|
2014-05-08 22:24:51 +00:00
|
|
|
if (I != AbstractScopeMap.end())
|
|
|
|
return &I->second;
|
2011-08-10 19:04:06 +00:00
|
|
|
|
2014-04-14 00:51:57 +00:00
|
|
|
LexicalScope *Parent = nullptr;
|
2011-08-10 19:04:06 +00:00
|
|
|
if (Scope.isLexicalBlock()) {
|
2014-05-25 18:11:35 +00:00
|
|
|
DILexicalBlock DB(Scope);
|
2011-08-10 19:04:06 +00:00
|
|
|
DIDescriptor ParentDesc = DB.getContext();
|
|
|
|
Parent = getOrCreateAbstractScope(ParentDesc);
|
|
|
|
}
|
2014-05-08 22:24:51 +00:00
|
|
|
I = AbstractScopeMap.emplace(std::piecewise_construct,
|
2014-05-25 18:11:35 +00:00
|
|
|
std::forward_as_tuple(Scope),
|
|
|
|
std::forward_as_tuple(Parent, Scope,
|
2014-05-08 22:24:51 +00:00
|
|
|
nullptr, true)).first;
|
2014-05-25 18:11:35 +00:00
|
|
|
if (Scope.isSubprogram())
|
2014-05-08 22:24:51 +00:00
|
|
|
AbstractScopesList.push_back(&I->second);
|
|
|
|
return &I->second;
|
2011-08-10 19:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// constructScopeNest
|
|
|
|
void LexicalScopes::constructScopeNest(LexicalScope *Scope) {
|
2013-11-20 00:54:19 +00:00
|
|
|
assert(Scope && "Unable to calculate scope dominance graph!");
|
2011-08-10 19:04:06 +00:00
|
|
|
SmallVector<LexicalScope *, 4> WorkStack;
|
|
|
|
WorkStack.push_back(Scope);
|
|
|
|
unsigned Counter = 0;
|
|
|
|
while (!WorkStack.empty()) {
|
|
|
|
LexicalScope *WS = WorkStack.back();
|
2013-07-03 04:30:58 +00:00
|
|
|
const SmallVectorImpl<LexicalScope *> &Children = WS->getChildren();
|
2011-08-10 19:04:06 +00:00
|
|
|
bool visitedChildren = false;
|
2013-07-03 04:42:33 +00:00
|
|
|
for (SmallVectorImpl<LexicalScope *>::const_iterator SI = Children.begin(),
|
2013-11-20 00:54:19 +00:00
|
|
|
SE = Children.end();
|
|
|
|
SI != SE; ++SI) {
|
2011-08-10 19:04:06 +00:00
|
|
|
LexicalScope *ChildScope = *SI;
|
|
|
|
if (!ChildScope->getDFSOut()) {
|
|
|
|
WorkStack.push_back(ChildScope);
|
|
|
|
visitedChildren = true;
|
|
|
|
ChildScope->setDFSIn(++Counter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!visitedChildren) {
|
|
|
|
WorkStack.pop_back();
|
|
|
|
WS->setDFSOut(++Counter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-10 23:58:09 +00:00
|
|
|
/// assignInstructionRanges - Find ranges of instructions covered by each
|
|
|
|
/// lexical scope.
|
2013-11-20 00:54:19 +00:00
|
|
|
void LexicalScopes::assignInstructionRanges(
|
|
|
|
SmallVectorImpl<InsnRange> &MIRanges,
|
|
|
|
DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
|
|
|
|
|
2014-04-14 00:51:57 +00:00
|
|
|
LexicalScope *PrevLexicalScope = nullptr;
|
2011-08-10 19:04:06 +00:00
|
|
|
for (SmallVectorImpl<InsnRange>::const_iterator RI = MIRanges.begin(),
|
2013-11-20 00:54:19 +00:00
|
|
|
RE = MIRanges.end();
|
|
|
|
RI != RE; ++RI) {
|
2011-08-10 19:04:06 +00:00
|
|
|
const InsnRange &R = *RI;
|
|
|
|
LexicalScope *S = MI2ScopeMap.lookup(R.first);
|
2013-11-20 00:54:19 +00:00
|
|
|
assert(S && "Lost LexicalScope for a machine instruction!");
|
2011-08-10 19:04:06 +00:00
|
|
|
if (PrevLexicalScope && !PrevLexicalScope->dominates(S))
|
|
|
|
PrevLexicalScope->closeInsnRange(S);
|
|
|
|
S->openInsnRange(R.first);
|
|
|
|
S->extendInsnRange(R.second);
|
|
|
|
PrevLexicalScope = S;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PrevLexicalScope)
|
|
|
|
PrevLexicalScope->closeInsnRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getMachineBasicBlocks - Populate given set using machine basic blocks which
|
2013-11-20 00:54:19 +00:00
|
|
|
/// have machine instructions that belong to lexical scope identified by
|
2011-08-10 19:04:06 +00:00
|
|
|
/// DebugLoc.
|
2013-11-20 00:54:19 +00:00
|
|
|
void LexicalScopes::getMachineBasicBlocks(
|
2014-08-21 05:55:13 +00:00
|
|
|
DebugLoc DL, SmallPtrSetImpl<const MachineBasicBlock *> &MBBs) {
|
2011-08-10 19:04:06 +00:00
|
|
|
MBBs.clear();
|
|
|
|
LexicalScope *Scope = getOrCreateLexicalScope(DL);
|
|
|
|
if (!Scope)
|
|
|
|
return;
|
2013-11-20 00:54:19 +00:00
|
|
|
|
2011-08-12 18:01:34 +00:00
|
|
|
if (Scope == CurrentFnLexicalScope) {
|
2014-04-30 18:29:51 +00:00
|
|
|
for (const auto &MBB : *MF)
|
|
|
|
MBBs.insert(&MBB);
|
2011-08-12 18:01:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-03 04:30:58 +00:00
|
|
|
SmallVectorImpl<InsnRange> &InsnRanges = Scope->getRanges();
|
2013-07-03 04:42:33 +00:00
|
|
|
for (SmallVectorImpl<InsnRange>::iterator I = InsnRanges.begin(),
|
2013-11-20 00:54:19 +00:00
|
|
|
E = InsnRanges.end();
|
|
|
|
I != E; ++I) {
|
2011-08-10 19:04:06 +00:00
|
|
|
InsnRange &R = *I;
|
|
|
|
MBBs.insert(R.first->getParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// dominates - Return true if DebugLoc's lexical scope dominates at least one
|
|
|
|
/// machine instruction's lexical scope in a given machine basic block.
|
|
|
|
bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) {
|
|
|
|
LexicalScope *Scope = getOrCreateLexicalScope(DL);
|
|
|
|
if (!Scope)
|
|
|
|
return false;
|
2011-08-12 18:01:34 +00:00
|
|
|
|
|
|
|
// Current function scope covers all basic blocks in the function.
|
|
|
|
if (Scope == CurrentFnLexicalScope && MBB->getParent() == MF)
|
|
|
|
return true;
|
|
|
|
|
2011-08-10 19:04:06 +00:00
|
|
|
bool Result = false;
|
2013-11-20 00:54:19 +00:00
|
|
|
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
|
|
|
|
++I) {
|
2011-08-10 19:04:06 +00:00
|
|
|
DebugLoc IDL = I->getDebugLoc();
|
|
|
|
if (IDL.isUnknown())
|
|
|
|
continue;
|
|
|
|
if (LexicalScope *IScope = getOrCreateLexicalScope(IDL))
|
|
|
|
if (Scope->dominates(IScope))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// dump - Print data structures.
|
2013-02-02 00:02:03 +00:00
|
|
|
void LexicalScope::dump(unsigned Indent) const {
|
2011-08-10 19:04:06 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
raw_ostream &err = dbgs();
|
2013-02-02 00:02:03 +00:00
|
|
|
err.indent(Indent);
|
2011-08-10 19:04:06 +00:00
|
|
|
err << "DFSIn: " << DFSIn << " DFSOut: " << DFSOut << "\n";
|
|
|
|
const MDNode *N = Desc;
|
2013-02-02 00:02:03 +00:00
|
|
|
err.indent(Indent);
|
2011-08-10 19:04:06 +00:00
|
|
|
N->dump();
|
|
|
|
if (AbstractScope)
|
2013-02-02 00:02:03 +00:00
|
|
|
err << std::string(Indent, ' ') << "Abstract Scope\n";
|
2011-08-10 19:04:06 +00:00
|
|
|
|
|
|
|
if (!Children.empty())
|
2013-02-02 00:02:03 +00:00
|
|
|
err << std::string(Indent + 2, ' ') << "Children ...\n";
|
2011-08-10 19:04:06 +00:00
|
|
|
for (unsigned i = 0, e = Children.size(); i != e; ++i)
|
|
|
|
if (Children[i] != this)
|
2013-02-02 00:02:03 +00:00
|
|
|
Children[i]->dump(Indent + 2);
|
2011-08-10 19:04:06 +00:00
|
|
|
#endif
|
|
|
|
}
|