16#ifndef LLVM_CODEGEN_LEXICALSCOPES_H
17#define LLVM_CODEGEN_LEXICALSCOPES_H
26#include <unordered_map>
31class MachineBasicBlock;
40using InsnRange = std::pair<const MachineInstr *, const MachineInstr *>;
49 : Parent(
P),
Desc(
D), InlinedAtLocation(
I), AbstractScope(
A) {
51 assert(
D->getSubprogram()->getUnit()->getEmissionKind() !=
53 "Don't build lexical scopes for non-debug locations");
54 assert(
D->isResolved() &&
"Expected resolved node");
55 assert((!
I ||
I->isResolved()) &&
"Expected resolved node");
84 assert(FirstInsn &&
"MI Range is not open!");
94 assert(LastInsn &&
"Last insn missing!");
100 if (Parent && (!NewScope || !Parent->
dominates(NewScope)))
154 bool empty() {
return CurrentFnLexicalScope ==
nullptr; }
158 return CurrentFnLexicalScope;
178 return AbstractScopesList;
183 auto I = AbstractScopeMap.find(
N);
184 return I != AbstractScopeMap.end() ? &
I->second :
nullptr;
189 auto I = InlinedLexicalScopeMap.find(std::make_pair(
N, IA));
190 return I != InlinedLexicalScopeMap.end() ? &
I->second :
nullptr;
195 auto I = LexicalScopeMap.find(
N);
196 return I != LexicalScopeMap.end() ? &
I->second :
nullptr;
209 return DL ? getOrCreateLexicalScope(
DL->getScope(),
DL->getInlinedAt())
214 LexicalScope *getOrCreateRegularScope(
const DILocalScope *Scope);
217 LexicalScope *getOrCreateInlinedScope(
const DILocalScope *Scope,
218 const DILocation *InlinedAt);
222 void extractLexicalScopes(SmallVectorImpl<InsnRange> &MIRanges,
223 DenseMap<const MachineInstr *, LexicalScope *> &M);
224 void constructScopeNest(LexicalScope *Scope);
226 assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
227 DenseMap<const MachineInstr *, LexicalScope *> &M);
229 const MachineFunction *MF =
nullptr;
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 =
nullptr;
256 using BlockSetT = SmallPtrSet<const MachineBasicBlock *, 4>;
257 DenseMap<const DILocation *, std::unique_ptr<BlockSetT>> DominatedBlocks;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LexicalScope - This class is used to track scope information.
unsigned getDFSIn() const
void extendInsnRange(const MachineInstr *MI)
extendInsnRange - Extend the current instruction range covered by this scope.
SmallVectorImpl< LexicalScope * > & getChildren()
const DILocation * getInlinedAt() const
SmallVectorImpl< InsnRange > & getRanges()
LexicalScope(LexicalScope *P, const DILocalScope *D, const DILocation *I, bool A)
const DILocalScope * getScopeNode() const
void setDFSOut(unsigned O)
unsigned getDFSOut() const
void openInsnRange(const MachineInstr *MI)
openInsnRange - This scope covers instruction range starting from MI.
void addChild(LexicalScope *S)
addChild - Add a child scope.
LLVM_ABI void dump(unsigned Indent=0) const
dump - print lexical scope.
void setDFSIn(unsigned I)
LexicalScope * getParent() const
const MDNode * getDesc() const
bool dominates(const LexicalScope *S) const
dominates - Return true if current scope dominates given lexical scope.
void closeInsnRange(LexicalScope *NewScope=nullptr)
closeInsnRange - Create a range based on FirstInsn and LastInsn collected until now.
bool isAbstractScope() const
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
LLVM_ABI void reset()
releaseMemory - release memory.
LLVM_ABI LexicalScope * getOrCreateAbstractScope(const DILocalScope *Scope)
getOrCreateAbstractScope - Find or create an abstract lexical scope.
LLVM_ABI void initialize(const MachineFunction &)
initialize - Scan machine function and constuct lexical scope nest, resets the instance if necessary.
LLVM_ABI LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
LLVM_ABI void getMachineBasicBlocks(const DILocation *DL, SmallPtrSetImpl< const MachineBasicBlock * > &MBBs)
getMachineBasicBlocks - Populate given set using machine basic blocks which have machine instructions...
ArrayRef< LexicalScope * > getAbstractScopesList() const
getAbstractScopesList - Return a reference to list of abstract scopes.
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
LexicalScope * findAbstractScope(const DILocalScope *N)
findAbstractScope - Find an abstract scope or return null.
LexicalScope * findLexicalScope(const DILocalScope *N)
findLexicalScope - Find regular lexical scope or return null.
bool empty()
empty - Return true if there is any lexical scope information available.
LLVM_ABI bool dominates(const DILocation *DL, MachineBasicBlock *MBB)
Return true if DebugLoc's lexical scope dominates at least one machine instruction's lexical scope in...
LexicalScope * getCurrentFunctionScope() const
getCurrentFunctionScope - Return lexical scope for the current function.
Representation of each machine instruction.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
Description of the encoding of one expression Op.