LLVM: include/llvm/CodeGen/LexicalScopes.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16#ifndef LLVM_CODEGEN_LEXICALSCOPES_H

17#define LLVM_CODEGEN_LEXICALSCOPES_H

18

25#include

26#include <unordered_map>

27#include

28

29namespace llvm {

30

35

36

37

38

39using InsnRange = std::pair<const MachineInstr *, const MachineInstr *>;

40

41

42

43

45public:

47 bool A)

48 : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A) {

50 assert(D->getSubprogram()->getUnit()->getEmissionKind() !=

52 "Don't build lexical scopes for non-debug locations");

53 assert(D->isResolved() && "Expected resolved node");

54 assert((I || I->isResolved()) && "Expected resolved node");

55 if (Parent)

56 Parent->addChild(this);

57 }

58

59

67

68

70

71

73 if (!FirstInsn)

74 FirstInsn = MI;

75

76 if (Parent)

77 Parent->openInsnRange(MI);

78 }

79

80

82 assert(FirstInsn && "MI Range is not open!");

83 LastInsn = MI;

84 if (Parent)

85 Parent->extendInsnRange(MI);

86 }

87

88

89

90

92 assert(LastInsn && "Last insn missing!");

93 Ranges.push_back(InsnRange(FirstInsn, LastInsn));

94 FirstInsn = nullptr;

95 LastInsn = nullptr;

96

97

98 if (Parent && (!NewScope || !Parent->dominates(NewScope)))

99 Parent->closeInsnRange(NewScope);

100 }

101

102

104 if (S == this)

105 return true;

107 return true;

108 return false;

109 }

110

111

112 unsigned getDFSOut() const { return DFSOut; }

114 unsigned getDFSIn() const { return DFSIn; }

116

117

118 LLVM_ABI void dump(unsigned Indent = 0) const;

119

120private:

121 LexicalScope *Parent;

123 const DILocation *InlinedAtLocation;

124

125 bool AbstractScope;

127

129

130 const MachineInstr *LastInsn = nullptr;

131 const MachineInstr *FirstInsn = nullptr;

132 unsigned DFSIn = 0;

133 unsigned DFSOut = 0;

134};

135

136

137

138

139

141public:

143

144

146

147

148

150

151

153

154

156

157

158 bool empty() { return CurrentFnLexicalScope == nullptr; }

159

160

162 return CurrentFnLexicalScope;

163 }

164

165

166

170

171

172

174

175

176

178

179

181 return AbstractScopesList;

182 }

183

184

186 auto I = AbstractScopeMap.find(N);

187 return I != AbstractScopeMap.end() ? &I->second : nullptr;

188 }

189

190

192 auto I = InlinedLexicalScopeMap.find(std::make_pair(N, IA));

193 return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;

194 }

195

196

198 auto I = LexicalScopeMap.find(N);

199 return I != LexicalScopeMap.end() ? &I->second : nullptr;

200 }

201

202

204

205

207 return FunctionMap.lookup(SP);

208 }

209

210private:

211

212

214 getOrCreateLexicalScope(const DILocalScope *Scope,

217 return DL ? getOrCreateLexicalScope(DL->getScope(), DL->getInlinedAt())

218 : nullptr;

219 }

220

221

222 LexicalScope *getOrCreateRegularScope(const DILocalScope *Scope);

223

224

225 LexicalScope *getOrCreateInlinedScope(const DILocalScope *Scope,

226 const DILocation *InlinedAt);

227

228

229

230 void extractLexicalScopes(SmallVectorImpl &MIRanges,

231 DenseMap<const MachineInstr *, LexicalScope *> &M);

232 void constructScopeNest(LexicalScope *Scope);

233 void

234 assignInstructionRanges(SmallVectorImpl &MIRanges,

235 DenseMap<const MachineInstr *, LexicalScope *> &M);

236

237 const MachineFunction *MF = nullptr;

238

239

240 DenseMap<const DISubprogram *, const Function *> FunctionMap;

241

242

243

244 std::unordered_map<const DILocalScope *, LexicalScope> LexicalScopeMap;

245

246

247 std::unordered_map<std::pair<const DILocalScope *, const DILocation *>,

248 LexicalScope,

249 pair_hash<const DILocalScope *, const DILocation *>>

250 InlinedLexicalScopeMap;

251

252

253

254 std::unordered_map<const DILocalScope *, LexicalScope> AbstractScopeMap;

255

256

258

259

260 LexicalScope *CurrentFnLexicalScope = nullptr;

261

262

263

264 using BlockSetT = SmallPtrSet<const MachineBasicBlock *, 4>;

265 DenseMap<const DILocation *, std::unique_ptr> DominatedBlocks;

266};

267

268}

269

270#endif

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),...

Subprogram description. Uses SubclassData1.

This class is used to track scope information.

Definition LexicalScopes.h:44

unsigned getDFSIn() const

Definition LexicalScopes.h:114

void extendInsnRange(const MachineInstr *MI)

Extend the current instruction range covered by this scope.

Definition LexicalScopes.h:81

SmallVectorImpl< LexicalScope * > & getChildren()

Definition LexicalScopes.h:65

const DILocation * getInlinedAt() const

Definition LexicalScopes.h:62

SmallVectorImpl< InsnRange > & getRanges()

Definition LexicalScopes.h:66

LexicalScope(LexicalScope *P, const DILocalScope *D, const DILocation *I, bool A)

Definition LexicalScopes.h:46

const DILocalScope * getScopeNode() const

Definition LexicalScopes.h:63

void setDFSOut(unsigned O)

Definition LexicalScopes.h:113

unsigned getDFSOut() const

Definition LexicalScopes.h:112

void openInsnRange(const MachineInstr *MI)

This scope covers instruction range starting from MI.

Definition LexicalScopes.h:72

void addChild(LexicalScope *S)

Add a child scope.

Definition LexicalScopes.h:69

LLVM_ABI void dump(unsigned Indent=0) const

Print lexical scope.

void setDFSIn(unsigned I)

Definition LexicalScopes.h:115

LexicalScope * getParent() const

Definition LexicalScopes.h:60

const MDNode * getDesc() const

Definition LexicalScopes.h:61

bool dominates(const LexicalScope *S) const

Return true if current scope dominates given lexical scope.

Definition LexicalScopes.h:103

void closeInsnRange(LexicalScope *NewScope=nullptr)

Create a range based on FirstInsn and LastInsn collected until now.

Definition LexicalScopes.h:91

bool isAbstractScope() const

Definition LexicalScopes.h:64

LLVM_ABI void scanFunction(const MachineFunction &)

Scan machine function and constuct lexical scope nest, resets the instance if necessary.

LLVM_ABI LexicalScope * getOrCreateAbstractScope(const DILocalScope *Scope)

Find or create an abstract lexical scope.

LLVM_ABI LexicalScope * findLexicalScope(const DILocation *DL)

Find lexical scope, either regular or inlined, for the given DebugLoc.

LLVM_ABI void getMachineBasicBlocks(const DILocation *DL, SmallPtrSetImpl< const MachineBasicBlock * > &MBBs)

Populate given set using machine basic blocks which have machine instructions that belong to lexical ...

LLVM_ABI void initialize(const Module &)

Scan module to build subprogram-to-function map.

const Function * getFunction(const DISubprogram *SP) const

Get function to which the given subprogram is attached, if exists.

Definition LexicalScopes.h:206

ArrayRef< LexicalScope * > getAbstractScopesList() const

Return a reference to list of abstract scopes.

Definition LexicalScopes.h:180

LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)

Find an inlined scope for the given scope/inlined-at.

Definition LexicalScopes.h:191

LexicalScope * findAbstractScope(const DILocalScope *N)

Find an abstract scope or return null.

Definition LexicalScopes.h:185

LLVM_ABI void resetFunction()

Reset the instance so that it's prepared for another function.

LLVM_ABI void resetModule()

Reset the instance so that it's prepared for another module.

LexicalScope * findLexicalScope(const DILocalScope *N)

Find regular lexical scope or return null.

Definition LexicalScopes.h:197

bool empty()

Return true if there is any lexical scope information available.

Definition LexicalScopes.h:158

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

Return lexical scope for the current function.

Definition LexicalScopes.h:161

Representation of each machine instruction.

A Module instance is used to store all the information related to an LLVM module.

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...

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

This is used to track range of instructions with identical lexical scope.

Definition LexicalScopes.h:39

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...