Formatting, 80-col, trailing whitespace.

llvm-svn: 195180
This commit is contained in:
Eric Christopher 2013-11-20 00:54:19 +00:00
parent d4b22dcbf3
commit 6211e4b995
2 changed files with 75 additions and 73 deletions

View File

@ -44,7 +44,7 @@ typedef std::pair<const MachineInstr *, const MachineInstr *> InsnRange;
/// ///
class LexicalScopes { class LexicalScopes {
public: public:
LexicalScopes() : MF(NULL), CurrentFnLexicalScope(NULL) { } LexicalScopes() : MF(NULL), CurrentFnLexicalScope(NULL) {}
virtual ~LexicalScopes(); virtual ~LexicalScopes();
/// initialize - Scan machine function and constuct lexical scope nest. /// initialize - Scan machine function and constuct lexical scope nest.
@ -63,13 +63,15 @@ public:
} }
/// getCurrentFunctionScope - Return lexical scope for the current function. /// getCurrentFunctionScope - Return lexical scope for the current function.
LexicalScope *getCurrentFunctionScope() const { return CurrentFnLexicalScope;} LexicalScope *getCurrentFunctionScope() const {
return CurrentFnLexicalScope;
}
/// getMachineBasicBlocks - Populate given set using machine basic blocks /// getMachineBasicBlocks - Populate given set using machine basic blocks
/// which have machine instructions that belong to lexical scope identified by /// which have machine instructions that belong to lexical scope identified by
/// DebugLoc. /// DebugLoc.
void getMachineBasicBlocks(DebugLoc DL, void getMachineBasicBlocks(DebugLoc DL,
SmallPtrSet<const MachineBasicBlock*, 4> &MBBs); SmallPtrSet<const MachineBasicBlock *, 4> &MBBs);
/// dominates - Return true if DebugLoc's lexical scope dominates at least one /// dominates - Return true if DebugLoc's lexical scope dominates at least one
/// machine instruction's lexical scope in a given machine basic block. /// machine instruction's lexical scope in a given machine basic block.
@ -104,7 +106,6 @@ public:
void dump(); void dump();
private: private:
/// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
/// not available then create new lexical scope. /// not available then create new lexical scope.
LexicalScope *getOrCreateLexicalScope(DebugLoc DL); LexicalScope *getOrCreateLexicalScope(DebugLoc DL);
@ -123,8 +124,9 @@ private:
void extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges, void extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges,
DenseMap<const MachineInstr *, LexicalScope *> &M); DenseMap<const MachineInstr *, LexicalScope *> &M);
void constructScopeNest(LexicalScope *Scope); void constructScopeNest(LexicalScope *Scope);
void assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges, void
DenseMap<const MachineInstr *, LexicalScope *> &M); assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
DenseMap<const MachineInstr *, LexicalScope *> &M);
private: private:
const MachineFunction *MF; const MachineFunction *MF;
@ -133,7 +135,8 @@ private:
/// contained LexicalScope*s. /// contained LexicalScope*s.
DenseMap<const MDNode *, LexicalScope *> LexicalScopeMap; DenseMap<const MDNode *, LexicalScope *> LexicalScopeMap;
/// InlinedLexicalScopeMap - Tracks inlined function scopes in current function. /// InlinedLexicalScopeMap - Tracks inlined function scopes in current
/// function.
DenseMap<DebugLoc, LexicalScope *> InlinedLexicalScopeMap; DenseMap<DebugLoc, LexicalScope *> InlinedLexicalScopeMap;
/// AbstractScopeMap - These scopes are not included LexicalScopeMap. /// AbstractScopeMap - These scopes are not included LexicalScopeMap.
@ -157,8 +160,8 @@ class LexicalScope {
public: public:
LexicalScope(LexicalScope *P, const MDNode *D, const MDNode *I, bool A) LexicalScope(LexicalScope *P, const MDNode *D, const MDNode *I, bool A)
: Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A), : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A), LastInsn(0),
LastInsn(0), FirstInsn(0), DFSIn(0), DFSOut(0) { FirstInsn(0), DFSIn(0), DFSOut(0) {
if (Parent) if (Parent)
Parent->addChild(this); Parent->addChild(this);
} }
@ -166,13 +169,13 @@ public:
virtual ~LexicalScope() {} virtual ~LexicalScope() {}
// Accessors. // Accessors.
LexicalScope *getParent() const { return Parent; } LexicalScope *getParent() const { return Parent; }
const MDNode *getDesc() const { return Desc; } const MDNode *getDesc() const { return Desc; }
const MDNode *getInlinedAt() const { return InlinedAtLocation; } const MDNode *getInlinedAt() const { return InlinedAtLocation; }
const MDNode *getScopeNode() const { return Desc; } const MDNode *getScopeNode() const { return Desc; }
bool isAbstractScope() const { return AbstractScope; } bool isAbstractScope() const { return AbstractScope; }
SmallVectorImpl<LexicalScope *> &getChildren() { return Children; } SmallVectorImpl<LexicalScope *> &getChildren() { return Children; }
SmallVectorImpl<InsnRange> &getRanges() { return Ranges; } SmallVectorImpl<InsnRange> &getRanges() { return Ranges; }
/// addChild - Add a child scope. /// addChild - Add a child scope.
void addChild(LexicalScope *S) { Children.push_back(S); } void addChild(LexicalScope *S) { Children.push_back(S); }
@ -189,7 +192,7 @@ public:
/// extendInsnRange - Extend the current instruction range covered by /// extendInsnRange - Extend the current instruction range covered by
/// this scope. /// this scope.
void extendInsnRange(const MachineInstr *MI) { void extendInsnRange(const MachineInstr *MI) {
assert (FirstInsn && "MI Range is not open!"); assert(FirstInsn && "MI Range is not open!");
LastInsn = MI; LastInsn = MI;
if (Parent) if (Parent)
Parent->extendInsnRange(MI); Parent->extendInsnRange(MI);
@ -199,7 +202,7 @@ public:
/// until now. This is used when a new scope is encountered while walking /// until now. This is used when a new scope is encountered while walking
/// machine instructions. /// machine instructions.
void closeInsnRange(LexicalScope *NewScope = NULL) { void closeInsnRange(LexicalScope *NewScope = NULL) {
assert (LastInsn && "Last insn missing!"); assert(LastInsn && "Last insn missing!");
Ranges.push_back(InsnRange(FirstInsn, LastInsn)); Ranges.push_back(InsnRange(FirstInsn, LastInsn));
FirstInsn = NULL; FirstInsn = NULL;
LastInsn = NULL; LastInsn = NULL;
@ -219,28 +222,28 @@ public:
} }
// Depth First Search support to walk and manipulate LexicalScope hierarchy. // Depth First Search support to walk and manipulate LexicalScope hierarchy.
unsigned getDFSOut() const { return DFSOut; } unsigned getDFSOut() const { return DFSOut; }
void setDFSOut(unsigned O) { DFSOut = O; } void setDFSOut(unsigned O) { DFSOut = O; }
unsigned getDFSIn() const { return DFSIn; } unsigned getDFSIn() const { return DFSIn; }
void setDFSIn(unsigned I) { DFSIn = I; } void setDFSIn(unsigned I) { DFSIn = I; }
/// dump - print lexical scope. /// dump - print lexical scope.
void dump(unsigned Indent = 0) const; void dump(unsigned Indent = 0) const;
private: private:
LexicalScope *Parent; // Parent to this scope. LexicalScope *Parent; // Parent to this scope.
AssertingVH<const MDNode> Desc; // Debug info descriptor. AssertingVH<const MDNode> Desc; // Debug info descriptor.
AssertingVH<const MDNode> InlinedAtLocation; // Location at which this AssertingVH<const MDNode> InlinedAtLocation; // Location at which this
// scope is inlined. // scope is inlined.
bool AbstractScope; // Abstract Scope bool AbstractScope; // Abstract Scope
SmallVector<LexicalScope *, 4> Children; // Scopes defined in scope. SmallVector<LexicalScope *, 4> Children; // Scopes defined in scope.
// Contents not owned. // Contents not owned.
SmallVector<InsnRange, 4> Ranges; SmallVector<InsnRange, 4> Ranges;
const MachineInstr *LastInsn; // Last instruction of this scope. const MachineInstr *LastInsn; // Last instruction of this scope.
const MachineInstr *FirstInsn; // First instruction of this scope. const MachineInstr *FirstInsn; // First instruction of this scope.
unsigned DFSIn, DFSOut; // In & Out Depth use to determine unsigned DFSIn, DFSOut; // In & Out Depth use to determine
// scope nesting. // scope nesting.
}; };
} // end llvm namespace } // end llvm namespace

View File

@ -25,9 +25,7 @@
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
using namespace llvm; using namespace llvm;
LexicalScopes::~LexicalScopes() { LexicalScopes::~LexicalScopes() { releaseMemory(); }
releaseMemory();
}
/// releaseMemory - release memory. /// releaseMemory - release memory.
void LexicalScopes::releaseMemory() { void LexicalScopes::releaseMemory() {
@ -54,13 +52,13 @@ void LexicalScopes::initialize(const MachineFunction &Fn) {
/// extractLexicalScopes - Extract instruction ranges for each lexical scopes /// extractLexicalScopes - Extract instruction ranges for each lexical scopes
/// for the given machine function. /// for the given machine function.
void LexicalScopes:: void LexicalScopes::extractLexicalScopes(
extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges, SmallVectorImpl<InsnRange> &MIRanges,
DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) { DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
// Scan each instruction and create scopes. First build working set of scopes. // Scan each instruction and create scopes. First build working set of scopes.
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
I != E; ++I) { ++I) {
const MachineInstr *RangeBeginMI = NULL; const MachineInstr *RangeBeginMI = NULL;
const MachineInstr *PrevMI = NULL; const MachineInstr *PrevMI = NULL;
DebugLoc PrevDL; DebugLoc PrevDL;
@ -117,7 +115,8 @@ LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) {
MDNode *Scope = NULL; MDNode *Scope = NULL;
MDNode *IA = NULL; MDNode *IA = NULL;
DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext()); DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext());
if (!Scope) return NULL; if (!Scope)
return NULL;
// The scope that we were created with could have an extra file - which // The scope that we were created with could have an extra file - which
// isn't what we care about in this case. // isn't what we care about in this case.
@ -164,8 +163,8 @@ LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) {
Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope)); Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope));
WScope = new LexicalScope(Parent, DIDescriptor(Scope), NULL, false); WScope = new LexicalScope(Parent, DIDescriptor(Scope), NULL, false);
LexicalScopeMap.insert(std::make_pair(Scope, WScope)); LexicalScopeMap.insert(std::make_pair(Scope, WScope));
if (!Parent && DIDescriptor(Scope).isSubprogram() if (!Parent && DIDescriptor(Scope).isSubprogram() &&
&& DISubprogram(Scope).describes(MF->getFunction())) DISubprogram(Scope).describes(MF->getFunction()))
CurrentFnLexicalScope = WScope; CurrentFnLexicalScope = WScope;
return WScope; return WScope;
@ -212,7 +211,7 @@ LexicalScope *LexicalScopes::getOrCreateAbstractScope(const MDNode *N) {
/// constructScopeNest /// constructScopeNest
void LexicalScopes::constructScopeNest(LexicalScope *Scope) { void LexicalScopes::constructScopeNest(LexicalScope *Scope) {
assert (Scope && "Unable to calculate scope dominance graph!"); assert(Scope && "Unable to calculate scope dominance graph!");
SmallVector<LexicalScope *, 4> WorkStack; SmallVector<LexicalScope *, 4> WorkStack;
WorkStack.push_back(Scope); WorkStack.push_back(Scope);
unsigned Counter = 0; unsigned Counter = 0;
@ -221,7 +220,8 @@ void LexicalScopes::constructScopeNest(LexicalScope *Scope) {
const SmallVectorImpl<LexicalScope *> &Children = WS->getChildren(); const SmallVectorImpl<LexicalScope *> &Children = WS->getChildren();
bool visitedChildren = false; bool visitedChildren = false;
for (SmallVectorImpl<LexicalScope *>::const_iterator SI = Children.begin(), for (SmallVectorImpl<LexicalScope *>::const_iterator SI = Children.begin(),
SE = Children.end(); SI != SE; ++SI) { SE = Children.end();
SI != SE; ++SI) {
LexicalScope *ChildScope = *SI; LexicalScope *ChildScope = *SI;
if (!ChildScope->getDFSOut()) { if (!ChildScope->getDFSOut()) {
WorkStack.push_back(ChildScope); WorkStack.push_back(ChildScope);
@ -239,17 +239,17 @@ void LexicalScopes::constructScopeNest(LexicalScope *Scope) {
/// assignInstructionRanges - Find ranges of instructions covered by each /// assignInstructionRanges - Find ranges of instructions covered by each
/// lexical scope. /// lexical scope.
void LexicalScopes:: void LexicalScopes::assignInstructionRanges(
assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges, SmallVectorImpl<InsnRange> &MIRanges,
DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
{
LexicalScope *PrevLexicalScope = NULL; LexicalScope *PrevLexicalScope = NULL;
for (SmallVectorImpl<InsnRange>::const_iterator RI = MIRanges.begin(), for (SmallVectorImpl<InsnRange>::const_iterator RI = MIRanges.begin(),
RE = MIRanges.end(); RI != RE; ++RI) { RE = MIRanges.end();
RI != RE; ++RI) {
const InsnRange &R = *RI; const InsnRange &R = *RI;
LexicalScope *S = MI2ScopeMap.lookup(R.first); LexicalScope *S = MI2ScopeMap.lookup(R.first);
assert (S && "Lost LexicalScope for a machine instruction!"); assert(S && "Lost LexicalScope for a machine instruction!");
if (PrevLexicalScope && !PrevLexicalScope->dominates(S)) if (PrevLexicalScope && !PrevLexicalScope->dominates(S))
PrevLexicalScope->closeInsnRange(S); PrevLexicalScope->closeInsnRange(S);
S->openInsnRange(R.first); S->openInsnRange(R.first);
@ -264,24 +264,24 @@ assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
/// getMachineBasicBlocks - Populate given set using machine basic blocks which /// getMachineBasicBlocks - Populate given set using machine basic blocks which
/// have machine instructions that belong to lexical scope identified by /// have machine instructions that belong to lexical scope identified by
/// DebugLoc. /// DebugLoc.
void LexicalScopes:: void LexicalScopes::getMachineBasicBlocks(
getMachineBasicBlocks(DebugLoc DL, DebugLoc DL, SmallPtrSet<const MachineBasicBlock *, 4> &MBBs) {
SmallPtrSet<const MachineBasicBlock*, 4> &MBBs) {
MBBs.clear(); MBBs.clear();
LexicalScope *Scope = getOrCreateLexicalScope(DL); LexicalScope *Scope = getOrCreateLexicalScope(DL);
if (!Scope) if (!Scope)
return; return;
if (Scope == CurrentFnLexicalScope) { if (Scope == CurrentFnLexicalScope) {
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
I != E; ++I) ++I)
MBBs.insert(I); MBBs.insert(I);
return; return;
} }
SmallVectorImpl<InsnRange> &InsnRanges = Scope->getRanges(); SmallVectorImpl<InsnRange> &InsnRanges = Scope->getRanges();
for (SmallVectorImpl<InsnRange>::iterator I = InsnRanges.begin(), for (SmallVectorImpl<InsnRange>::iterator I = InsnRanges.begin(),
E = InsnRanges.end(); I != E; ++I) { E = InsnRanges.end();
I != E; ++I) {
InsnRange &R = *I; InsnRange &R = *I;
MBBs.insert(R.first->getParent()); MBBs.insert(R.first->getParent());
} }
@ -299,8 +299,8 @@ bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) {
return true; return true;
bool Result = false; bool Result = false;
for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;
I != E; ++I) { ++I) {
DebugLoc IDL = I->getDebugLoc(); DebugLoc IDL = I->getDebugLoc();
if (IDL.isUnknown()) if (IDL.isUnknown())
continue; continue;
@ -311,7 +311,7 @@ bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) {
return Result; return Result;
} }
void LexicalScope::anchor() { } void LexicalScope::anchor() {}
/// dump - Print data structures. /// dump - Print data structures.
void LexicalScope::dump(unsigned Indent) const { void LexicalScope::dump(unsigned Indent) const {
@ -332,4 +332,3 @@ void LexicalScope::dump(unsigned Indent) const {
Children[i]->dump(Indent + 2); Children[i]->dump(Indent + 2);
#endif #endif
} }