17 #define DEBUG_TYPE "lexicalscopes"
35 CurrentFnLexicalScope = NULL;
38 InlinedLexicalScopeMap.clear();
39 AbstractScopesList.clear();
48 extractLexicalScopes(MIRanges, MI2ScopeMap);
49 if (CurrentFnLexicalScope) {
50 constructScopeNest(CurrentFnLexicalScope);
51 assignInstructionRanges(MIRanges, MI2ScopeMap);
93 MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL);
106 if (RangeBeginMI && PrevMI && !PrevDL.
isUnknown()) {
109 MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL);
120 if (!Scope)
return NULL;
130 return LexicalScopeMap.lookup(Scope);
142 getOrCreateAbstractScope(Scope);
144 return getOrCreateInlinedScope(Scope, InlinedAt);
147 return getOrCreateRegularScope(Scope);
166 LexicalScopeMap.insert(std::make_pair(Scope, WScope));
169 CurrentFnLexicalScope = WScope;
177 LexicalScope *InlinedScope = LexicalScopeMap.lookup(InlinedAt);
182 InlinedScope =
new LexicalScope(getOrCreateLexicalScope(InlinedLoc),
184 InlinedLexicalScopeMap[InlinedLoc] = InlinedScope;
185 LexicalScopeMap[InlinedAt] = InlinedScope;
191 assert(N &&
"Invalid Scope encoding!");
194 if (Scope.isLexicalBlockFile())
201 if (Scope.isLexicalBlock()) {
204 Parent = getOrCreateAbstractScope(ParentDesc);
207 AbstractScopeMap[
N] = AScope;
209 AbstractScopesList.push_back(AScope);
214 void LexicalScopes::constructScopeNest(
LexicalScope *Scope) {
215 assert (Scope &&
"Unable to calculate scope dominance graph!");
218 unsigned Counter = 0;
219 while (!WorkStack.
empty()) {
222 bool visitedChildren =
false;
224 SE = Children.
end(); SI != SE; ++SI) {
228 visitedChildren =
true;
233 if (!visitedChildren) {
249 RE = MIRanges.
end(); RI != RE; ++RI) {
252 assert (S &&
"Lost LexicalScope for a machine instruction!");
253 if (PrevLexicalScope && !PrevLexicalScope->
dominates(S))
257 PrevLexicalScope = S;
260 if (PrevLexicalScope)
275 if (Scope == CurrentFnLexicalScope) {
284 E = InsnRanges.
end();
I != E; ++
I) {
286 MBBs.
insert(R.first->getParent());
298 if (Scope == CurrentFnLexicalScope && MBB->
getParent() == MF)
307 if (
LexicalScope *IScope = getOrCreateLexicalScope(IDL))
314 void LexicalScope::anchor() { }
321 err <<
"DFSIn: " << DFSIn <<
" DFSOut: " << DFSOut <<
"\n";
326 err << std::string(Indent,
' ') <<
"Abstract Scope\n";
328 if (!Children.
empty())
329 err << std::string(Indent + 2,
' ') <<
"Children ...\n";
330 for (
unsigned i = 0, e = Children.
size(); i != e; ++i)
331 if (Children[i] !=
this)
332 Children[i]->dump(Indent + 2);
void DeleteContainerSeconds(Container &C)
void push_back(const T &Elt)
const MachineFunction * getParent() const
void openInsnRange(const MachineInstr *MI)
openInsnRange - This scope covers instruction range starting from MI.
void dump(unsigned Indent=0) const
dump - print lexical scope.
void extendInsnRange(const MachineInstr *MI)
LLVMContext & getContext() const
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
SmallVectorImpl< InsnRange > & getRanges()
void getScopeAndInlinedAt(MDNode *&Scope, MDNode *&IA, const LLVMContext &Ctx) const
getScopeAndInlinedAt - Return both the Scope and the InlinedAt values.
MDNode - a tuple of other values.
const Function * getFunction() const
bool isUnknown() const
isUnknown - Return true if this is an unknown location.
void dump() const
dump - Support for debugging, callable in GDB: V->dump()
SmallVectorImpl< LexicalScope * > & getChildren()
void setDFSOut(unsigned O)
DISubprogram - This is a wrapper for a subprogram (e.g. a function).
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
virtual void initialize(const MachineFunction &)
initialize - Scan machine function and constuct lexical scope nest.
bool dominates(DebugLoc DL, MachineBasicBlock *MBB)
LexicalScope * findLexicalScope(DebugLoc DL)
DILexicalBlock - This is a wrapper for a lexical block.
bool isDebugValue() const
static DebugLoc getFromDILexicalBlock(MDNode *N)
getFromDILexicalBlock - Translate the DILexicalBlock into a DebugLoc.
bundle_iterator< MachineInstr, instr_iterator > iterator
void closeInsnRange(LexicalScope *NewScope=NULL)
bool dominates(const LexicalScope *S) const
dominates - Return true if current scope dominates given lexical scope.
DILexicalBlock getScope() const
unsigned getDFSOut() const
void setDFSIn(unsigned I)
bool isLexicalBlockFile() const
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
static DebugLoc getFromDILocation(MDNode *N)
getFromDILocation - Translate the DILocation quad into a DebugLoc.
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
ValueT lookup(const KeyT &Val) const
virtual void releaseMemory()
releaseMemory - release memory.
bool isLexicalBlock() const
isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
void getMachineBasicBlocks(DebugLoc DL, SmallPtrSet< const MachineBasicBlock *, 4 > &MBBs)
DebugLoc getDebugLoc() const