17 #ifndef LLVM_CODEGEN_LEXICALSCOPES_H
18 #define LLVM_CODEGEN_LEXICALSCOPES_H
26 #include <unordered_map>
31 class MachineBasicBlock;
32 class MachineFunction;
40 using InsnRange = std::pair<const MachineInstr *, const MachineInstr *>;
49 : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A) {
53 "Don't build lexical scopes for non-debug locations");
84 assert(FirstInsn &&
"MI Range is not open!");
94 assert(LastInsn &&
"Last insn missing!");
100 if (Parent && (!NewScope || !Parent->
dominates(NewScope)))
120 void dump(
unsigned Indent = 0)
const;
154 bool empty() {
return CurrentFnLexicalScope ==
nullptr; }
158 return CurrentFnLexicalScope;
177 return AbstractScopesList;
182 auto I = AbstractScopeMap.find(N);
183 return I != AbstractScopeMap.end() ? &
I->second :
nullptr;
188 auto I = InlinedLexicalScopeMap.find(std::make_pair(N, IA));
189 return I != InlinedLexicalScopeMap.end() ? &
I->second :
nullptr;
194 auto I = LexicalScopeMap.find(N);
195 return I != LexicalScopeMap.end() ? &
I->second :
nullptr;
210 return DL ? getOrCreateLexicalScope(DL->getScope(), DL->getInlinedAt())
215 LexicalScope *getOrCreateRegularScope(
const DILocalScope *Scope);
218 LexicalScope *getOrCreateInlinedScope(
const DILocalScope *Scope,
219 const DILocation *InlinedAt);
223 void extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges,
224 DenseMap<const MachineInstr *, LexicalScope *> &M);
225 void constructScopeNest(LexicalScope *Scope);
227 assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
228 DenseMap<const MachineInstr *, LexicalScope *> &M);
230 const MachineFunction *MF =
nullptr;
234 std::unordered_map<const DILocalScope *, LexicalScope> LexicalScopeMap;
238 std::unordered_map<std::pair<const DILocalScope *, const DILocation *>,
240 pair_hash<const DILocalScope *, const DILocation *>>
241 InlinedLexicalScopeMap;
245 std::unordered_map<const DILocalScope *, LexicalScope> AbstractScopeMap;
249 SmallVector<LexicalScope *, 4> AbstractScopesList;
253 LexicalScope *CurrentFnLexicalScope =
nullptr;
258 #endif // LLVM_CODEGEN_LEXICALSCOPES_H
void push_back(const T &Elt)
void openInsnRange(const MachineInstr *MI)
openInsnRange - This scope covers instruction range starting from MI.
const DILocalScope * getScopeNode() const
void extendInsnRange(const MachineInstr *MI)
extendInsnRange - Extend the current instruction range covered by this scope.
bool dominates(const DILocation *DL, MachineBasicBlock *MBB)
dominates - Return true if DebugLoc's lexical scope dominates at least one machine instruction's lexi...
SmallVectorImpl< InsnRange > & getRanges()
void dump() const
dump - Print data structures to dbgs().
LexicalScope - This class is used to track scope information.
const DILocation * getInlinedAt() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
ArrayRef< LexicalScope * > getAbstractScopesList() const
getAbstractScopesList - Return a reference to list of abstract scopes.
LexicalScope * getOrCreateAbstractScope(const DILocalScope *Scope)
getOrCreateAbstractScope - Find or create an abstract lexical scope.
SmallVectorImpl< LexicalScope * > & getChildren()
void setDFSOut(unsigned O)
void reset()
releaseMemory - release memory.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LexicalScope * getCurrentFunctionScope() const
getCurrentFunctionScope - Return lexical scope for the current function.
LexicalScope * getParent() const
void initialize(const MachineFunction &)
initialize - Scan machine function and constuct lexical scope nest, resets the instance if necessary...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
LexicalScope * findAbstractScope(const DILocalScope *N)
findAbstractScope - Find an abstract scope or return null.
bool dominates(const LexicalScope *S) const
dominates - Return true if current scope dominates given lexical scope.
LexicalScope * findLexicalScope(const DILocalScope *N)
findLexicalScope - Find regular lexical scope or return null.
const MDNode * getDesc() const
unsigned getDFSOut() const
bool isAbstractScope() const
void setDFSIn(unsigned I)
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
void getMachineBasicBlocks(const DILocation *DL, SmallPtrSetImpl< const MachineBasicBlock * > &MBBs)
getMachineBasicBlocks - Populate given set using machine basic blocks which have machine instructions...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LexicalScope(LexicalScope *P, const DILocalScope *D, const DILocation *I, bool A)
unsigned getDFSIn() const
Representation of each machine instruction.
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
void closeInsnRange(LexicalScope *NewScope=nullptr)
closeInsnRange - Create a range based on FirstInsn and LastInsn collected until now.
void addChild(LexicalScope *S)
addChild - Add a child scope.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isResolved() const
Check if node is fully resolved.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
void dump(unsigned Indent=0) const
dump - print lexical scope.
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
bool empty()
empty - Return true if there is any lexical scope information available.