17 #ifndef LLVM_CODEGEN_LEXICALSCOPES_H
18 #define LLVM_CODEGEN_LEXICALSCOPES_H
28 #include <unordered_map>
33 class MachineBasicBlock;
40 typedef std::pair<const MachineInstr *, const MachineInstr *>
InsnRange;
50 : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A),
51 LastInsn(nullptr), FirstInsn(nullptr), DFSIn(0), DFSOut(0) {
82 assert(FirstInsn &&
"MI Range is not open!");
92 assert(LastInsn &&
"Last insn missing!");
98 if (Parent && (!NewScope || !Parent->
dominates(NewScope)))
118 void dump(
unsigned Indent = 0)
const;
132 unsigned DFSIn, DFSOut;
152 bool empty() {
return CurrentFnLexicalScope ==
nullptr; }
156 return CurrentFnLexicalScope;
175 return AbstractScopesList;
180 auto I = AbstractScopeMap.find(N);
181 return I != AbstractScopeMap.end() ? &
I->second :
nullptr;
186 auto I = InlinedLexicalScopeMap.find(std::make_pair(N, IA));
187 return I != InlinedLexicalScopeMap.end() ? &
I->second :
nullptr;
192 auto I = LexicalScopeMap.find(N);
193 return I != LexicalScopeMap.end() ? &
I->second :
nullptr;
208 return DL ? getOrCreateLexicalScope(DL->getScope(), DL->getInlinedAt())
213 LexicalScope *getOrCreateRegularScope(
const DILocalScope *Scope);
216 LexicalScope *getOrCreateInlinedScope(
const DILocalScope *Scope,
217 const DILocation *InlinedAt);
221 void extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges,
222 DenseMap<const MachineInstr *, LexicalScope *> &M);
223 void constructScopeNest(LexicalScope *Scope);
225 assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
226 DenseMap<const MachineInstr *, LexicalScope *> &M);
229 const MachineFunction *MF;
233 std::unordered_map<const DILocalScope *, LexicalScope> LexicalScopeMap;
237 std::unordered_map<std::pair<const DILocalScope *, const DILocation *>,
239 pair_hash<const DILocalScope *, const DILocation *>>
240 InlinedLexicalScopeMap;
244 std::unordered_map<const DILocalScope *, LexicalScope> AbstractScopeMap;
248 SmallVector<LexicalScope *, 4> AbstractScopesList;
252 LexicalScope *CurrentFnLexicalScope;
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 dump(unsigned Indent=0) const
dump - print lexical scope.
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()
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...
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
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)
void dump()
dump - Print data structures to dbgs().
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.
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
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.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
bool empty()
empty - Return true if there is any lexical scope information available.