1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Stmt::Profile method, which builds a unique bit
11 // representation that identifies a statement/expression.
12 //
13 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/DeclObjC.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/ExprCXX.h"
20 #include "clang/AST/ExprObjC.h"
21 #include "clang/AST/ExprOpenMP.h"
22 #include "clang/AST/StmtVisitor.h"
23 #include "llvm/ADT/FoldingSet.h"
24 using namespace clang;
25
26 namespace {
27 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
28 llvm::FoldingSetNodeID &ID;
29 const ASTContext &Context;
30 bool Canonical;
31
32 public:
StmtProfiler(llvm::FoldingSetNodeID & ID,const ASTContext & Context,bool Canonical)33 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
34 bool Canonical)
35 : ID(ID), Context(Context), Canonical(Canonical) { }
36
37 void VisitStmt(const Stmt *S);
38
39 #define STMT(Node, Base) void Visit##Node(const Node *S);
40 #include "clang/AST/StmtNodes.inc"
41
42 /// \brief Visit a declaration that is referenced within an expression
43 /// or statement.
44 void VisitDecl(const Decl *D);
45
46 /// \brief Visit a type that is referenced within an expression or
47 /// statement.
48 void VisitType(QualType T);
49
50 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
52
53 /// \brief Visit a nested-name-specifier that occurs within an expression
54 /// or statement.
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
56
57 /// \brief Visit a template name that occurs within an expression or
58 /// statement.
59 void VisitTemplateName(TemplateName Name);
60
61 /// \brief Visit template arguments that occur within an expression or
62 /// statement.
63 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
64 unsigned NumArgs);
65
66 /// \brief Visit a single template argument.
67 void VisitTemplateArgument(const TemplateArgument &Arg);
68 };
69 }
70
VisitStmt(const Stmt * S)71 void StmtProfiler::VisitStmt(const Stmt *S) {
72 ID.AddInteger(S->getStmtClass());
73 for (const Stmt *SubStmt : S->children()) {
74 if (SubStmt)
75 Visit(SubStmt);
76 else
77 ID.AddInteger(0);
78 }
79 }
80
VisitDeclStmt(const DeclStmt * S)81 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
82 VisitStmt(S);
83 for (const auto *D : S->decls())
84 VisitDecl(D);
85 }
86
VisitNullStmt(const NullStmt * S)87 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
88 VisitStmt(S);
89 }
90
VisitCompoundStmt(const CompoundStmt * S)91 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
92 VisitStmt(S);
93 }
94
VisitSwitchCase(const SwitchCase * S)95 void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
96 VisitStmt(S);
97 }
98
VisitCaseStmt(const CaseStmt * S)99 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
100 VisitStmt(S);
101 }
102
VisitDefaultStmt(const DefaultStmt * S)103 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
104 VisitStmt(S);
105 }
106
VisitLabelStmt(const LabelStmt * S)107 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
108 VisitStmt(S);
109 VisitDecl(S->getDecl());
110 }
111
VisitAttributedStmt(const AttributedStmt * S)112 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
113 VisitStmt(S);
114 // TODO: maybe visit attributes?
115 }
116
VisitIfStmt(const IfStmt * S)117 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
118 VisitStmt(S);
119 VisitDecl(S->getConditionVariable());
120 }
121
VisitSwitchStmt(const SwitchStmt * S)122 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
123 VisitStmt(S);
124 VisitDecl(S->getConditionVariable());
125 }
126
VisitWhileStmt(const WhileStmt * S)127 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
128 VisitStmt(S);
129 VisitDecl(S->getConditionVariable());
130 }
131
VisitDoStmt(const DoStmt * S)132 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
133 VisitStmt(S);
134 }
135
VisitForStmt(const ForStmt * S)136 void StmtProfiler::VisitForStmt(const ForStmt *S) {
137 VisitStmt(S);
138 }
139
VisitGotoStmt(const GotoStmt * S)140 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
141 VisitStmt(S);
142 VisitDecl(S->getLabel());
143 }
144
VisitIndirectGotoStmt(const IndirectGotoStmt * S)145 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
146 VisitStmt(S);
147 }
148
VisitContinueStmt(const ContinueStmt * S)149 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
150 VisitStmt(S);
151 }
152
VisitBreakStmt(const BreakStmt * S)153 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
154 VisitStmt(S);
155 }
156
VisitReturnStmt(const ReturnStmt * S)157 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
158 VisitStmt(S);
159 }
160
VisitGCCAsmStmt(const GCCAsmStmt * S)161 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
162 VisitStmt(S);
163 ID.AddBoolean(S->isVolatile());
164 ID.AddBoolean(S->isSimple());
165 VisitStringLiteral(S->getAsmString());
166 ID.AddInteger(S->getNumOutputs());
167 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
168 ID.AddString(S->getOutputName(I));
169 VisitStringLiteral(S->getOutputConstraintLiteral(I));
170 }
171 ID.AddInteger(S->getNumInputs());
172 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
173 ID.AddString(S->getInputName(I));
174 VisitStringLiteral(S->getInputConstraintLiteral(I));
175 }
176 ID.AddInteger(S->getNumClobbers());
177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
178 VisitStringLiteral(S->getClobberStringLiteral(I));
179 }
180
VisitMSAsmStmt(const MSAsmStmt * S)181 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
182 // FIXME: Implement MS style inline asm statement profiler.
183 VisitStmt(S);
184 }
185
VisitCXXCatchStmt(const CXXCatchStmt * S)186 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
187 VisitStmt(S);
188 VisitType(S->getCaughtType());
189 }
190
VisitCXXTryStmt(const CXXTryStmt * S)191 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
192 VisitStmt(S);
193 }
194
VisitCXXForRangeStmt(const CXXForRangeStmt * S)195 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
196 VisitStmt(S);
197 }
198
VisitMSDependentExistsStmt(const MSDependentExistsStmt * S)199 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
200 VisitStmt(S);
201 ID.AddBoolean(S->isIfExists());
202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
203 VisitName(S->getNameInfo().getName());
204 }
205
VisitSEHTryStmt(const SEHTryStmt * S)206 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
207 VisitStmt(S);
208 }
209
VisitSEHFinallyStmt(const SEHFinallyStmt * S)210 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
211 VisitStmt(S);
212 }
213
VisitSEHExceptStmt(const SEHExceptStmt * S)214 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
215 VisitStmt(S);
216 }
217
VisitSEHLeaveStmt(const SEHLeaveStmt * S)218 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
219 VisitStmt(S);
220 }
221
VisitCapturedStmt(const CapturedStmt * S)222 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
223 VisitStmt(S);
224 }
225
VisitObjCForCollectionStmt(const ObjCForCollectionStmt * S)226 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
227 VisitStmt(S);
228 }
229
VisitObjCAtCatchStmt(const ObjCAtCatchStmt * S)230 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
231 VisitStmt(S);
232 ID.AddBoolean(S->hasEllipsis());
233 if (S->getCatchParamDecl())
234 VisitType(S->getCatchParamDecl()->getType());
235 }
236
VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt * S)237 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
238 VisitStmt(S);
239 }
240
VisitObjCAtTryStmt(const ObjCAtTryStmt * S)241 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
242 VisitStmt(S);
243 }
244
245 void
VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt * S)246 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
247 VisitStmt(S);
248 }
249
VisitObjCAtThrowStmt(const ObjCAtThrowStmt * S)250 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
251 VisitStmt(S);
252 }
253
254 void
VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt * S)255 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
256 VisitStmt(S);
257 }
258
259 namespace {
260 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
261 StmtProfiler *Profiler;
262 /// \brief Process clauses with list of variables.
263 template <typename T>
264 void VisitOMPClauseList(T *Node);
265
266 public:
OMPClauseProfiler(StmtProfiler * P)267 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
268 #define OPENMP_CLAUSE(Name, Class) \
269 void Visit##Class(const Class *C);
270 #include "clang/Basic/OpenMPKinds.def"
271 };
272
VisitOMPIfClause(const OMPIfClause * C)273 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
274 if (C->getCondition())
275 Profiler->VisitStmt(C->getCondition());
276 }
277
VisitOMPFinalClause(const OMPFinalClause * C)278 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
279 if (C->getCondition())
280 Profiler->VisitStmt(C->getCondition());
281 }
282
VisitOMPNumThreadsClause(const OMPNumThreadsClause * C)283 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
284 if (C->getNumThreads())
285 Profiler->VisitStmt(C->getNumThreads());
286 }
287
VisitOMPSafelenClause(const OMPSafelenClause * C)288 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
289 if (C->getSafelen())
290 Profiler->VisitStmt(C->getSafelen());
291 }
292
VisitOMPSimdlenClause(const OMPSimdlenClause * C)293 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
294 if (C->getSimdlen())
295 Profiler->VisitStmt(C->getSimdlen());
296 }
297
VisitOMPCollapseClause(const OMPCollapseClause * C)298 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
299 if (C->getNumForLoops())
300 Profiler->VisitStmt(C->getNumForLoops());
301 }
302
VisitOMPDefaultClause(const OMPDefaultClause * C)303 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
304
VisitOMPProcBindClause(const OMPProcBindClause * C)305 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
306
VisitOMPScheduleClause(const OMPScheduleClause * C)307 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
308 if (C->getChunkSize()) {
309 Profiler->VisitStmt(C->getChunkSize());
310 if (C->getHelperChunkSize()) {
311 Profiler->VisitStmt(C->getChunkSize());
312 }
313 }
314 }
315
VisitOMPOrderedClause(const OMPOrderedClause * C)316 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
317 if (auto *Num = C->getNumForLoops())
318 Profiler->VisitStmt(Num);
319 }
320
VisitOMPNowaitClause(const OMPNowaitClause *)321 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
322
VisitOMPUntiedClause(const OMPUntiedClause *)323 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
324
VisitOMPMergeableClause(const OMPMergeableClause *)325 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
326
VisitOMPReadClause(const OMPReadClause *)327 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
328
VisitOMPWriteClause(const OMPWriteClause *)329 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
330
VisitOMPUpdateClause(const OMPUpdateClause *)331 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
332
VisitOMPCaptureClause(const OMPCaptureClause *)333 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
334
VisitOMPSeqCstClause(const OMPSeqCstClause *)335 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
336
VisitOMPThreadsClause(const OMPThreadsClause *)337 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
338
VisitOMPSIMDClause(const OMPSIMDClause *)339 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
340
VisitOMPNogroupClause(const OMPNogroupClause *)341 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
342
343 template<typename T>
VisitOMPClauseList(T * Node)344 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
345 for (auto *E : Node->varlists()) {
346 Profiler->VisitStmt(E);
347 }
348 }
349
VisitOMPPrivateClause(const OMPPrivateClause * C)350 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
351 VisitOMPClauseList(C);
352 for (auto *E : C->private_copies()) {
353 Profiler->VisitStmt(E);
354 }
355 }
356 void
VisitOMPFirstprivateClause(const OMPFirstprivateClause * C)357 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
358 VisitOMPClauseList(C);
359 for (auto *E : C->private_copies()) {
360 Profiler->VisitStmt(E);
361 }
362 for (auto *E : C->inits()) {
363 Profiler->VisitStmt(E);
364 }
365 }
366 void
VisitOMPLastprivateClause(const OMPLastprivateClause * C)367 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
368 VisitOMPClauseList(C);
369 for (auto *E : C->source_exprs()) {
370 Profiler->VisitStmt(E);
371 }
372 for (auto *E : C->destination_exprs()) {
373 Profiler->VisitStmt(E);
374 }
375 for (auto *E : C->assignment_ops()) {
376 Profiler->VisitStmt(E);
377 }
378 }
VisitOMPSharedClause(const OMPSharedClause * C)379 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
380 VisitOMPClauseList(C);
381 }
VisitOMPReductionClause(const OMPReductionClause * C)382 void OMPClauseProfiler::VisitOMPReductionClause(
383 const OMPReductionClause *C) {
384 Profiler->VisitNestedNameSpecifier(
385 C->getQualifierLoc().getNestedNameSpecifier());
386 Profiler->VisitName(C->getNameInfo().getName());
387 VisitOMPClauseList(C);
388 for (auto *E : C->privates()) {
389 Profiler->VisitStmt(E);
390 }
391 for (auto *E : C->lhs_exprs()) {
392 Profiler->VisitStmt(E);
393 }
394 for (auto *E : C->rhs_exprs()) {
395 Profiler->VisitStmt(E);
396 }
397 for (auto *E : C->reduction_ops()) {
398 Profiler->VisitStmt(E);
399 }
400 }
VisitOMPLinearClause(const OMPLinearClause * C)401 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
402 VisitOMPClauseList(C);
403 for (auto *E : C->privates()) {
404 Profiler->VisitStmt(E);
405 }
406 for (auto *E : C->inits()) {
407 Profiler->VisitStmt(E);
408 }
409 for (auto *E : C->updates()) {
410 Profiler->VisitStmt(E);
411 }
412 for (auto *E : C->finals()) {
413 Profiler->VisitStmt(E);
414 }
415 Profiler->VisitStmt(C->getStep());
416 Profiler->VisitStmt(C->getCalcStep());
417 }
VisitOMPAlignedClause(const OMPAlignedClause * C)418 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
419 VisitOMPClauseList(C);
420 Profiler->VisitStmt(C->getAlignment());
421 }
VisitOMPCopyinClause(const OMPCopyinClause * C)422 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
423 VisitOMPClauseList(C);
424 for (auto *E : C->source_exprs()) {
425 Profiler->VisitStmt(E);
426 }
427 for (auto *E : C->destination_exprs()) {
428 Profiler->VisitStmt(E);
429 }
430 for (auto *E : C->assignment_ops()) {
431 Profiler->VisitStmt(E);
432 }
433 }
434 void
VisitOMPCopyprivateClause(const OMPCopyprivateClause * C)435 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
436 VisitOMPClauseList(C);
437 for (auto *E : C->source_exprs()) {
438 Profiler->VisitStmt(E);
439 }
440 for (auto *E : C->destination_exprs()) {
441 Profiler->VisitStmt(E);
442 }
443 for (auto *E : C->assignment_ops()) {
444 Profiler->VisitStmt(E);
445 }
446 }
VisitOMPFlushClause(const OMPFlushClause * C)447 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
448 VisitOMPClauseList(C);
449 }
VisitOMPDependClause(const OMPDependClause * C)450 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
451 VisitOMPClauseList(C);
452 }
VisitOMPDeviceClause(const OMPDeviceClause * C)453 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
454 Profiler->VisitStmt(C->getDevice());
455 }
VisitOMPMapClause(const OMPMapClause * C)456 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
457 VisitOMPClauseList(C);
458 }
VisitOMPNumTeamsClause(const OMPNumTeamsClause * C)459 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
460 Profiler->VisitStmt(C->getNumTeams());
461 }
VisitOMPThreadLimitClause(const OMPThreadLimitClause * C)462 void OMPClauseProfiler::VisitOMPThreadLimitClause(
463 const OMPThreadLimitClause *C) {
464 Profiler->VisitStmt(C->getThreadLimit());
465 }
VisitOMPPriorityClause(const OMPPriorityClause * C)466 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
467 Profiler->VisitStmt(C->getPriority());
468 }
VisitOMPGrainsizeClause(const OMPGrainsizeClause * C)469 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
470 Profiler->VisitStmt(C->getGrainsize());
471 }
VisitOMPNumTasksClause(const OMPNumTasksClause * C)472 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
473 Profiler->VisitStmt(C->getNumTasks());
474 }
VisitOMPHintClause(const OMPHintClause * C)475 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
476 Profiler->VisitStmt(C->getHint());
477 }
478 }
479
480 void
VisitOMPExecutableDirective(const OMPExecutableDirective * S)481 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
482 VisitStmt(S);
483 OMPClauseProfiler P(this);
484 ArrayRef<OMPClause *> Clauses = S->clauses();
485 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
486 I != E; ++I)
487 if (*I)
488 P.Visit(*I);
489 }
490
VisitOMPLoopDirective(const OMPLoopDirective * S)491 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
492 VisitOMPExecutableDirective(S);
493 }
494
VisitOMPParallelDirective(const OMPParallelDirective * S)495 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
496 VisitOMPExecutableDirective(S);
497 }
498
VisitOMPSimdDirective(const OMPSimdDirective * S)499 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
500 VisitOMPLoopDirective(S);
501 }
502
VisitOMPForDirective(const OMPForDirective * S)503 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
504 VisitOMPLoopDirective(S);
505 }
506
VisitOMPForSimdDirective(const OMPForSimdDirective * S)507 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
508 VisitOMPLoopDirective(S);
509 }
510
VisitOMPSectionsDirective(const OMPSectionsDirective * S)511 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
512 VisitOMPExecutableDirective(S);
513 }
514
VisitOMPSectionDirective(const OMPSectionDirective * S)515 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
516 VisitOMPExecutableDirective(S);
517 }
518
VisitOMPSingleDirective(const OMPSingleDirective * S)519 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
520 VisitOMPExecutableDirective(S);
521 }
522
VisitOMPMasterDirective(const OMPMasterDirective * S)523 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
524 VisitOMPExecutableDirective(S);
525 }
526
VisitOMPCriticalDirective(const OMPCriticalDirective * S)527 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
528 VisitOMPExecutableDirective(S);
529 VisitName(S->getDirectiveName().getName());
530 }
531
532 void
VisitOMPParallelForDirective(const OMPParallelForDirective * S)533 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
534 VisitOMPLoopDirective(S);
535 }
536
VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective * S)537 void StmtProfiler::VisitOMPParallelForSimdDirective(
538 const OMPParallelForSimdDirective *S) {
539 VisitOMPLoopDirective(S);
540 }
541
VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective * S)542 void StmtProfiler::VisitOMPParallelSectionsDirective(
543 const OMPParallelSectionsDirective *S) {
544 VisitOMPExecutableDirective(S);
545 }
546
VisitOMPTaskDirective(const OMPTaskDirective * S)547 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
548 VisitOMPExecutableDirective(S);
549 }
550
VisitOMPTaskyieldDirective(const OMPTaskyieldDirective * S)551 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
552 VisitOMPExecutableDirective(S);
553 }
554
VisitOMPBarrierDirective(const OMPBarrierDirective * S)555 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
556 VisitOMPExecutableDirective(S);
557 }
558
VisitOMPTaskwaitDirective(const OMPTaskwaitDirective * S)559 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
560 VisitOMPExecutableDirective(S);
561 }
562
VisitOMPTaskgroupDirective(const OMPTaskgroupDirective * S)563 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
564 VisitOMPExecutableDirective(S);
565 }
566
VisitOMPFlushDirective(const OMPFlushDirective * S)567 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
568 VisitOMPExecutableDirective(S);
569 }
570
VisitOMPOrderedDirective(const OMPOrderedDirective * S)571 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
572 VisitOMPExecutableDirective(S);
573 }
574
VisitOMPAtomicDirective(const OMPAtomicDirective * S)575 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
576 VisitOMPExecutableDirective(S);
577 }
578
VisitOMPTargetDirective(const OMPTargetDirective * S)579 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
580 VisitOMPExecutableDirective(S);
581 }
582
VisitOMPTargetDataDirective(const OMPTargetDataDirective * S)583 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
584 VisitOMPExecutableDirective(S);
585 }
586
VisitOMPTeamsDirective(const OMPTeamsDirective * S)587 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
588 VisitOMPExecutableDirective(S);
589 }
590
VisitOMPCancellationPointDirective(const OMPCancellationPointDirective * S)591 void StmtProfiler::VisitOMPCancellationPointDirective(
592 const OMPCancellationPointDirective *S) {
593 VisitOMPExecutableDirective(S);
594 }
595
VisitOMPCancelDirective(const OMPCancelDirective * S)596 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
597 VisitOMPExecutableDirective(S);
598 }
599
VisitOMPTaskLoopDirective(const OMPTaskLoopDirective * S)600 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
601 VisitOMPLoopDirective(S);
602 }
603
VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective * S)604 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
605 const OMPTaskLoopSimdDirective *S) {
606 VisitOMPLoopDirective(S);
607 }
608
VisitOMPDistributeDirective(const OMPDistributeDirective * S)609 void StmtProfiler::VisitOMPDistributeDirective(
610 const OMPDistributeDirective *S) {
611 VisitOMPLoopDirective(S);
612 }
613
VisitExpr(const Expr * S)614 void StmtProfiler::VisitExpr(const Expr *S) {
615 VisitStmt(S);
616 }
617
VisitDeclRefExpr(const DeclRefExpr * S)618 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
619 VisitExpr(S);
620 if (!Canonical)
621 VisitNestedNameSpecifier(S->getQualifier());
622 VisitDecl(S->getDecl());
623 if (!Canonical)
624 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
625 }
626
VisitPredefinedExpr(const PredefinedExpr * S)627 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
628 VisitExpr(S);
629 ID.AddInteger(S->getIdentType());
630 }
631
VisitIntegerLiteral(const IntegerLiteral * S)632 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
633 VisitExpr(S);
634 S->getValue().Profile(ID);
635 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
636 }
637
VisitCharacterLiteral(const CharacterLiteral * S)638 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
639 VisitExpr(S);
640 ID.AddInteger(S->getKind());
641 ID.AddInteger(S->getValue());
642 }
643
VisitFloatingLiteral(const FloatingLiteral * S)644 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
645 VisitExpr(S);
646 S->getValue().Profile(ID);
647 ID.AddBoolean(S->isExact());
648 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
649 }
650
VisitImaginaryLiteral(const ImaginaryLiteral * S)651 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
652 VisitExpr(S);
653 }
654
VisitStringLiteral(const StringLiteral * S)655 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
656 VisitExpr(S);
657 ID.AddString(S->getBytes());
658 ID.AddInteger(S->getKind());
659 }
660
VisitParenExpr(const ParenExpr * S)661 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
662 VisitExpr(S);
663 }
664
VisitParenListExpr(const ParenListExpr * S)665 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
666 VisitExpr(S);
667 }
668
VisitUnaryOperator(const UnaryOperator * S)669 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
670 VisitExpr(S);
671 ID.AddInteger(S->getOpcode());
672 }
673
VisitOffsetOfExpr(const OffsetOfExpr * S)674 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
675 VisitType(S->getTypeSourceInfo()->getType());
676 unsigned n = S->getNumComponents();
677 for (unsigned i = 0; i < n; ++i) {
678 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
679 ID.AddInteger(ON.getKind());
680 switch (ON.getKind()) {
681 case OffsetOfExpr::OffsetOfNode::Array:
682 // Expressions handled below.
683 break;
684
685 case OffsetOfExpr::OffsetOfNode::Field:
686 VisitDecl(ON.getField());
687 break;
688
689 case OffsetOfExpr::OffsetOfNode::Identifier:
690 ID.AddPointer(ON.getFieldName());
691 break;
692
693 case OffsetOfExpr::OffsetOfNode::Base:
694 // These nodes are implicit, and therefore don't need profiling.
695 break;
696 }
697 }
698
699 VisitExpr(S);
700 }
701
702 void
VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr * S)703 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
704 VisitExpr(S);
705 ID.AddInteger(S->getKind());
706 if (S->isArgumentType())
707 VisitType(S->getArgumentType());
708 }
709
VisitArraySubscriptExpr(const ArraySubscriptExpr * S)710 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
711 VisitExpr(S);
712 }
713
VisitOMPArraySectionExpr(const OMPArraySectionExpr * S)714 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
715 VisitExpr(S);
716 }
717
VisitCallExpr(const CallExpr * S)718 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
719 VisitExpr(S);
720 }
721
VisitMemberExpr(const MemberExpr * S)722 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
723 VisitExpr(S);
724 VisitDecl(S->getMemberDecl());
725 if (!Canonical)
726 VisitNestedNameSpecifier(S->getQualifier());
727 ID.AddBoolean(S->isArrow());
728 }
729
VisitCompoundLiteralExpr(const CompoundLiteralExpr * S)730 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
731 VisitExpr(S);
732 ID.AddBoolean(S->isFileScope());
733 }
734
VisitCastExpr(const CastExpr * S)735 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
736 VisitExpr(S);
737 }
738
VisitImplicitCastExpr(const ImplicitCastExpr * S)739 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
740 VisitCastExpr(S);
741 ID.AddInteger(S->getValueKind());
742 }
743
VisitExplicitCastExpr(const ExplicitCastExpr * S)744 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
745 VisitCastExpr(S);
746 VisitType(S->getTypeAsWritten());
747 }
748
VisitCStyleCastExpr(const CStyleCastExpr * S)749 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
750 VisitExplicitCastExpr(S);
751 }
752
VisitBinaryOperator(const BinaryOperator * S)753 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
754 VisitExpr(S);
755 ID.AddInteger(S->getOpcode());
756 }
757
758 void
VisitCompoundAssignOperator(const CompoundAssignOperator * S)759 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
760 VisitBinaryOperator(S);
761 }
762
VisitConditionalOperator(const ConditionalOperator * S)763 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
764 VisitExpr(S);
765 }
766
VisitBinaryConditionalOperator(const BinaryConditionalOperator * S)767 void StmtProfiler::VisitBinaryConditionalOperator(
768 const BinaryConditionalOperator *S) {
769 VisitExpr(S);
770 }
771
VisitAddrLabelExpr(const AddrLabelExpr * S)772 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
773 VisitExpr(S);
774 VisitDecl(S->getLabel());
775 }
776
VisitStmtExpr(const StmtExpr * S)777 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
778 VisitExpr(S);
779 }
780
VisitShuffleVectorExpr(const ShuffleVectorExpr * S)781 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
782 VisitExpr(S);
783 }
784
VisitConvertVectorExpr(const ConvertVectorExpr * S)785 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
786 VisitExpr(S);
787 }
788
VisitChooseExpr(const ChooseExpr * S)789 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
790 VisitExpr(S);
791 }
792
VisitGNUNullExpr(const GNUNullExpr * S)793 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
794 VisitExpr(S);
795 }
796
VisitVAArgExpr(const VAArgExpr * S)797 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
798 VisitExpr(S);
799 }
800
VisitInitListExpr(const InitListExpr * S)801 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
802 if (S->getSyntacticForm()) {
803 VisitInitListExpr(S->getSyntacticForm());
804 return;
805 }
806
807 VisitExpr(S);
808 }
809
VisitDesignatedInitExpr(const DesignatedInitExpr * S)810 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
811 VisitExpr(S);
812 ID.AddBoolean(S->usesGNUSyntax());
813 for (DesignatedInitExpr::const_designators_iterator D =
814 S->designators_begin(), DEnd = S->designators_end();
815 D != DEnd; ++D) {
816 if (D->isFieldDesignator()) {
817 ID.AddInteger(0);
818 VisitName(D->getFieldName());
819 continue;
820 }
821
822 if (D->isArrayDesignator()) {
823 ID.AddInteger(1);
824 } else {
825 assert(D->isArrayRangeDesignator());
826 ID.AddInteger(2);
827 }
828 ID.AddInteger(D->getFirstExprIndex());
829 }
830 }
831
832 // Seems that if VisitInitListExpr() only works on the syntactic form of an
833 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr * S)834 void StmtProfiler::VisitDesignatedInitUpdateExpr(
835 const DesignatedInitUpdateExpr *S) {
836 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
837 "initializer");
838 }
839
VisitNoInitExpr(const NoInitExpr * S)840 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
841 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
842 }
843
VisitImplicitValueInitExpr(const ImplicitValueInitExpr * S)844 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
845 VisitExpr(S);
846 }
847
VisitExtVectorElementExpr(const ExtVectorElementExpr * S)848 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
849 VisitExpr(S);
850 VisitName(&S->getAccessor());
851 }
852
VisitBlockExpr(const BlockExpr * S)853 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
854 VisitExpr(S);
855 VisitDecl(S->getBlockDecl());
856 }
857
VisitGenericSelectionExpr(const GenericSelectionExpr * S)858 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
859 VisitExpr(S);
860 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
861 QualType T = S->getAssocType(i);
862 if (T.isNull())
863 ID.AddPointer(nullptr);
864 else
865 VisitType(T);
866 VisitExpr(S->getAssocExpr(i));
867 }
868 }
869
VisitPseudoObjectExpr(const PseudoObjectExpr * S)870 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
871 VisitExpr(S);
872 for (PseudoObjectExpr::const_semantics_iterator
873 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
874 // Normally, we would not profile the source expressions of OVEs.
875 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
876 Visit(OVE->getSourceExpr());
877 }
878
VisitAtomicExpr(const AtomicExpr * S)879 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
880 VisitExpr(S);
881 ID.AddInteger(S->getOp());
882 }
883
DecodeOperatorCall(const CXXOperatorCallExpr * S,UnaryOperatorKind & UnaryOp,BinaryOperatorKind & BinaryOp)884 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
885 UnaryOperatorKind &UnaryOp,
886 BinaryOperatorKind &BinaryOp) {
887 switch (S->getOperator()) {
888 case OO_None:
889 case OO_New:
890 case OO_Delete:
891 case OO_Array_New:
892 case OO_Array_Delete:
893 case OO_Arrow:
894 case OO_Call:
895 case OO_Conditional:
896 case OO_Coawait:
897 case NUM_OVERLOADED_OPERATORS:
898 llvm_unreachable("Invalid operator call kind");
899
900 case OO_Plus:
901 if (S->getNumArgs() == 1) {
902 UnaryOp = UO_Plus;
903 return Stmt::UnaryOperatorClass;
904 }
905
906 BinaryOp = BO_Add;
907 return Stmt::BinaryOperatorClass;
908
909 case OO_Minus:
910 if (S->getNumArgs() == 1) {
911 UnaryOp = UO_Minus;
912 return Stmt::UnaryOperatorClass;
913 }
914
915 BinaryOp = BO_Sub;
916 return Stmt::BinaryOperatorClass;
917
918 case OO_Star:
919 if (S->getNumArgs() == 1) {
920 UnaryOp = UO_Deref;
921 return Stmt::UnaryOperatorClass;
922 }
923
924 BinaryOp = BO_Mul;
925 return Stmt::BinaryOperatorClass;
926
927 case OO_Slash:
928 BinaryOp = BO_Div;
929 return Stmt::BinaryOperatorClass;
930
931 case OO_Percent:
932 BinaryOp = BO_Rem;
933 return Stmt::BinaryOperatorClass;
934
935 case OO_Caret:
936 BinaryOp = BO_Xor;
937 return Stmt::BinaryOperatorClass;
938
939 case OO_Amp:
940 if (S->getNumArgs() == 1) {
941 UnaryOp = UO_AddrOf;
942 return Stmt::UnaryOperatorClass;
943 }
944
945 BinaryOp = BO_And;
946 return Stmt::BinaryOperatorClass;
947
948 case OO_Pipe:
949 BinaryOp = BO_Or;
950 return Stmt::BinaryOperatorClass;
951
952 case OO_Tilde:
953 UnaryOp = UO_Not;
954 return Stmt::UnaryOperatorClass;
955
956 case OO_Exclaim:
957 UnaryOp = UO_LNot;
958 return Stmt::UnaryOperatorClass;
959
960 case OO_Equal:
961 BinaryOp = BO_Assign;
962 return Stmt::BinaryOperatorClass;
963
964 case OO_Less:
965 BinaryOp = BO_LT;
966 return Stmt::BinaryOperatorClass;
967
968 case OO_Greater:
969 BinaryOp = BO_GT;
970 return Stmt::BinaryOperatorClass;
971
972 case OO_PlusEqual:
973 BinaryOp = BO_AddAssign;
974 return Stmt::CompoundAssignOperatorClass;
975
976 case OO_MinusEqual:
977 BinaryOp = BO_SubAssign;
978 return Stmt::CompoundAssignOperatorClass;
979
980 case OO_StarEqual:
981 BinaryOp = BO_MulAssign;
982 return Stmt::CompoundAssignOperatorClass;
983
984 case OO_SlashEqual:
985 BinaryOp = BO_DivAssign;
986 return Stmt::CompoundAssignOperatorClass;
987
988 case OO_PercentEqual:
989 BinaryOp = BO_RemAssign;
990 return Stmt::CompoundAssignOperatorClass;
991
992 case OO_CaretEqual:
993 BinaryOp = BO_XorAssign;
994 return Stmt::CompoundAssignOperatorClass;
995
996 case OO_AmpEqual:
997 BinaryOp = BO_AndAssign;
998 return Stmt::CompoundAssignOperatorClass;
999
1000 case OO_PipeEqual:
1001 BinaryOp = BO_OrAssign;
1002 return Stmt::CompoundAssignOperatorClass;
1003
1004 case OO_LessLess:
1005 BinaryOp = BO_Shl;
1006 return Stmt::BinaryOperatorClass;
1007
1008 case OO_GreaterGreater:
1009 BinaryOp = BO_Shr;
1010 return Stmt::BinaryOperatorClass;
1011
1012 case OO_LessLessEqual:
1013 BinaryOp = BO_ShlAssign;
1014 return Stmt::CompoundAssignOperatorClass;
1015
1016 case OO_GreaterGreaterEqual:
1017 BinaryOp = BO_ShrAssign;
1018 return Stmt::CompoundAssignOperatorClass;
1019
1020 case OO_EqualEqual:
1021 BinaryOp = BO_EQ;
1022 return Stmt::BinaryOperatorClass;
1023
1024 case OO_ExclaimEqual:
1025 BinaryOp = BO_NE;
1026 return Stmt::BinaryOperatorClass;
1027
1028 case OO_LessEqual:
1029 BinaryOp = BO_LE;
1030 return Stmt::BinaryOperatorClass;
1031
1032 case OO_GreaterEqual:
1033 BinaryOp = BO_GE;
1034 return Stmt::BinaryOperatorClass;
1035
1036 case OO_AmpAmp:
1037 BinaryOp = BO_LAnd;
1038 return Stmt::BinaryOperatorClass;
1039
1040 case OO_PipePipe:
1041 BinaryOp = BO_LOr;
1042 return Stmt::BinaryOperatorClass;
1043
1044 case OO_PlusPlus:
1045 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1046 : UO_PostInc;
1047 return Stmt::UnaryOperatorClass;
1048
1049 case OO_MinusMinus:
1050 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1051 : UO_PostDec;
1052 return Stmt::UnaryOperatorClass;
1053
1054 case OO_Comma:
1055 BinaryOp = BO_Comma;
1056 return Stmt::BinaryOperatorClass;
1057
1058 case OO_ArrowStar:
1059 BinaryOp = BO_PtrMemI;
1060 return Stmt::BinaryOperatorClass;
1061
1062 case OO_Subscript:
1063 return Stmt::ArraySubscriptExprClass;
1064 }
1065
1066 llvm_unreachable("Invalid overloaded operator expression");
1067 }
1068
VisitCXXOperatorCallExpr(const CXXOperatorCallExpr * S)1069 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1070 if (S->isTypeDependent()) {
1071 // Type-dependent operator calls are profiled like their underlying
1072 // syntactic operator.
1073 UnaryOperatorKind UnaryOp = UO_Extension;
1074 BinaryOperatorKind BinaryOp = BO_Comma;
1075 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
1076
1077 ID.AddInteger(SC);
1078 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1079 Visit(S->getArg(I));
1080 if (SC == Stmt::UnaryOperatorClass)
1081 ID.AddInteger(UnaryOp);
1082 else if (SC == Stmt::BinaryOperatorClass ||
1083 SC == Stmt::CompoundAssignOperatorClass)
1084 ID.AddInteger(BinaryOp);
1085 else
1086 assert(SC == Stmt::ArraySubscriptExprClass);
1087
1088 return;
1089 }
1090
1091 VisitCallExpr(S);
1092 ID.AddInteger(S->getOperator());
1093 }
1094
VisitCXXMemberCallExpr(const CXXMemberCallExpr * S)1095 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1096 VisitCallExpr(S);
1097 }
1098
VisitCUDAKernelCallExpr(const CUDAKernelCallExpr * S)1099 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1100 VisitCallExpr(S);
1101 }
1102
VisitAsTypeExpr(const AsTypeExpr * S)1103 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1104 VisitExpr(S);
1105 }
1106
VisitCXXNamedCastExpr(const CXXNamedCastExpr * S)1107 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1108 VisitExplicitCastExpr(S);
1109 }
1110
VisitCXXStaticCastExpr(const CXXStaticCastExpr * S)1111 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1112 VisitCXXNamedCastExpr(S);
1113 }
1114
VisitCXXDynamicCastExpr(const CXXDynamicCastExpr * S)1115 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1116 VisitCXXNamedCastExpr(S);
1117 }
1118
1119 void
VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr * S)1120 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1121 VisitCXXNamedCastExpr(S);
1122 }
1123
VisitCXXConstCastExpr(const CXXConstCastExpr * S)1124 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1125 VisitCXXNamedCastExpr(S);
1126 }
1127
VisitUserDefinedLiteral(const UserDefinedLiteral * S)1128 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1129 VisitCallExpr(S);
1130 }
1131
VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr * S)1132 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1133 VisitExpr(S);
1134 ID.AddBoolean(S->getValue());
1135 }
1136
VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr * S)1137 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1138 VisitExpr(S);
1139 }
1140
VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr * S)1141 void StmtProfiler::VisitCXXStdInitializerListExpr(
1142 const CXXStdInitializerListExpr *S) {
1143 VisitExpr(S);
1144 }
1145
VisitCXXTypeidExpr(const CXXTypeidExpr * S)1146 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1147 VisitExpr(S);
1148 if (S->isTypeOperand())
1149 VisitType(S->getTypeOperandSourceInfo()->getType());
1150 }
1151
VisitCXXUuidofExpr(const CXXUuidofExpr * S)1152 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1153 VisitExpr(S);
1154 if (S->isTypeOperand())
1155 VisitType(S->getTypeOperandSourceInfo()->getType());
1156 }
1157
VisitMSPropertyRefExpr(const MSPropertyRefExpr * S)1158 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1159 VisitExpr(S);
1160 VisitDecl(S->getPropertyDecl());
1161 }
1162
VisitMSPropertySubscriptExpr(const MSPropertySubscriptExpr * S)1163 void StmtProfiler::VisitMSPropertySubscriptExpr(
1164 const MSPropertySubscriptExpr *S) {
1165 VisitExpr(S);
1166 }
1167
VisitCXXThisExpr(const CXXThisExpr * S)1168 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1169 VisitExpr(S);
1170 ID.AddBoolean(S->isImplicit());
1171 }
1172
VisitCXXThrowExpr(const CXXThrowExpr * S)1173 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1174 VisitExpr(S);
1175 }
1176
VisitCXXDefaultArgExpr(const CXXDefaultArgExpr * S)1177 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1178 VisitExpr(S);
1179 VisitDecl(S->getParam());
1180 }
1181
VisitCXXDefaultInitExpr(const CXXDefaultInitExpr * S)1182 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1183 VisitExpr(S);
1184 VisitDecl(S->getField());
1185 }
1186
VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr * S)1187 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1188 VisitExpr(S);
1189 VisitDecl(
1190 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1191 }
1192
VisitCXXConstructExpr(const CXXConstructExpr * S)1193 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1194 VisitExpr(S);
1195 VisitDecl(S->getConstructor());
1196 ID.AddBoolean(S->isElidable());
1197 }
1198
VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr * S)1199 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1200 VisitExplicitCastExpr(S);
1201 }
1202
1203 void
VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr * S)1204 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1205 VisitCXXConstructExpr(S);
1206 }
1207
1208 void
VisitLambdaExpr(const LambdaExpr * S)1209 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1210 VisitExpr(S);
1211 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1212 CEnd = S->explicit_capture_end();
1213 C != CEnd; ++C) {
1214 ID.AddInteger(C->getCaptureKind());
1215 switch (C->getCaptureKind()) {
1216 case LCK_This:
1217 break;
1218 case LCK_ByRef:
1219 case LCK_ByCopy:
1220 VisitDecl(C->getCapturedVar());
1221 ID.AddBoolean(C->isPackExpansion());
1222 break;
1223 case LCK_VLAType:
1224 llvm_unreachable("VLA type in explicit captures.");
1225 }
1226 }
1227 // Note: If we actually needed to be able to match lambda
1228 // expressions, we would have to consider parameters and return type
1229 // here, among other things.
1230 VisitStmt(S->getBody());
1231 }
1232
1233 void
VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr * S)1234 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1235 VisitExpr(S);
1236 }
1237
VisitCXXDeleteExpr(const CXXDeleteExpr * S)1238 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1239 VisitExpr(S);
1240 ID.AddBoolean(S->isGlobalDelete());
1241 ID.AddBoolean(S->isArrayForm());
1242 VisitDecl(S->getOperatorDelete());
1243 }
1244
VisitCXXNewExpr(const CXXNewExpr * S)1245 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
1246 VisitExpr(S);
1247 VisitType(S->getAllocatedType());
1248 VisitDecl(S->getOperatorNew());
1249 VisitDecl(S->getOperatorDelete());
1250 ID.AddBoolean(S->isArray());
1251 ID.AddInteger(S->getNumPlacementArgs());
1252 ID.AddBoolean(S->isGlobalNew());
1253 ID.AddBoolean(S->isParenTypeId());
1254 ID.AddInteger(S->getInitializationStyle());
1255 }
1256
1257 void
VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr * S)1258 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
1259 VisitExpr(S);
1260 ID.AddBoolean(S->isArrow());
1261 VisitNestedNameSpecifier(S->getQualifier());
1262 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
1263 if (S->getScopeTypeInfo())
1264 VisitType(S->getScopeTypeInfo()->getType());
1265 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
1266 if (S->getDestroyedTypeInfo())
1267 VisitType(S->getDestroyedType());
1268 else
1269 ID.AddPointer(S->getDestroyedTypeIdentifier());
1270 }
1271
VisitOverloadExpr(const OverloadExpr * S)1272 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1273 VisitExpr(S);
1274 VisitNestedNameSpecifier(S->getQualifier());
1275 VisitName(S->getName());
1276 ID.AddBoolean(S->hasExplicitTemplateArgs());
1277 if (S->hasExplicitTemplateArgs())
1278 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1279 S->getExplicitTemplateArgs().NumTemplateArgs);
1280 }
1281
1282 void
VisitUnresolvedLookupExpr(const UnresolvedLookupExpr * S)1283 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1284 VisitOverloadExpr(S);
1285 }
1286
VisitTypeTraitExpr(const TypeTraitExpr * S)1287 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1288 VisitExpr(S);
1289 ID.AddInteger(S->getTrait());
1290 ID.AddInteger(S->getNumArgs());
1291 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1292 VisitType(S->getArg(I)->getType());
1293 }
1294
VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr * S)1295 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1296 VisitExpr(S);
1297 ID.AddInteger(S->getTrait());
1298 VisitType(S->getQueriedType());
1299 }
1300
VisitExpressionTraitExpr(const ExpressionTraitExpr * S)1301 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1302 VisitExpr(S);
1303 ID.AddInteger(S->getTrait());
1304 VisitExpr(S->getQueriedExpression());
1305 }
1306
VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr * S)1307 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1308 const DependentScopeDeclRefExpr *S) {
1309 VisitExpr(S);
1310 VisitName(S->getDeclName());
1311 VisitNestedNameSpecifier(S->getQualifier());
1312 ID.AddBoolean(S->hasExplicitTemplateArgs());
1313 if (S->hasExplicitTemplateArgs())
1314 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1315 }
1316
VisitExprWithCleanups(const ExprWithCleanups * S)1317 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1318 VisitExpr(S);
1319 }
1320
VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr * S)1321 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1322 const CXXUnresolvedConstructExpr *S) {
1323 VisitExpr(S);
1324 VisitType(S->getTypeAsWritten());
1325 }
1326
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr * S)1327 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1328 const CXXDependentScopeMemberExpr *S) {
1329 ID.AddBoolean(S->isImplicitAccess());
1330 if (!S->isImplicitAccess()) {
1331 VisitExpr(S);
1332 ID.AddBoolean(S->isArrow());
1333 }
1334 VisitNestedNameSpecifier(S->getQualifier());
1335 VisitName(S->getMember());
1336 ID.AddBoolean(S->hasExplicitTemplateArgs());
1337 if (S->hasExplicitTemplateArgs())
1338 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1339 }
1340
VisitUnresolvedMemberExpr(const UnresolvedMemberExpr * S)1341 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1342 ID.AddBoolean(S->isImplicitAccess());
1343 if (!S->isImplicitAccess()) {
1344 VisitExpr(S);
1345 ID.AddBoolean(S->isArrow());
1346 }
1347 VisitNestedNameSpecifier(S->getQualifier());
1348 VisitName(S->getMemberName());
1349 ID.AddBoolean(S->hasExplicitTemplateArgs());
1350 if (S->hasExplicitTemplateArgs())
1351 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1352 }
1353
VisitCXXNoexceptExpr(const CXXNoexceptExpr * S)1354 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1355 VisitExpr(S);
1356 }
1357
VisitPackExpansionExpr(const PackExpansionExpr * S)1358 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1359 VisitExpr(S);
1360 }
1361
VisitSizeOfPackExpr(const SizeOfPackExpr * S)1362 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
1363 VisitExpr(S);
1364 VisitDecl(S->getPack());
1365 if (S->isPartiallySubstituted()) {
1366 auto Args = S->getPartialArguments();
1367 ID.AddInteger(Args.size());
1368 for (const auto &TA : Args)
1369 VisitTemplateArgument(TA);
1370 } else {
1371 ID.AddInteger(0);
1372 }
1373 }
1374
VisitSubstNonTypeTemplateParmPackExpr(const SubstNonTypeTemplateParmPackExpr * S)1375 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1376 const SubstNonTypeTemplateParmPackExpr *S) {
1377 VisitExpr(S);
1378 VisitDecl(S->getParameterPack());
1379 VisitTemplateArgument(S->getArgumentPack());
1380 }
1381
VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr * E)1382 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1383 const SubstNonTypeTemplateParmExpr *E) {
1384 // Profile exactly as the replacement expression.
1385 Visit(E->getReplacement());
1386 }
1387
VisitFunctionParmPackExpr(const FunctionParmPackExpr * S)1388 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1389 VisitExpr(S);
1390 VisitDecl(S->getParameterPack());
1391 ID.AddInteger(S->getNumExpansions());
1392 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1393 VisitDecl(*I);
1394 }
1395
VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr * S)1396 void StmtProfiler::VisitMaterializeTemporaryExpr(
1397 const MaterializeTemporaryExpr *S) {
1398 VisitExpr(S);
1399 }
1400
VisitCXXFoldExpr(const CXXFoldExpr * S)1401 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1402 VisitExpr(S);
1403 ID.AddInteger(S->getOperator());
1404 }
1405
VisitCoroutineBodyStmt(const CoroutineBodyStmt * S)1406 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1407 VisitStmt(S);
1408 }
1409
VisitCoreturnStmt(const CoreturnStmt * S)1410 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1411 VisitStmt(S);
1412 }
1413
VisitCoawaitExpr(const CoawaitExpr * S)1414 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1415 VisitExpr(S);
1416 }
1417
VisitCoyieldExpr(const CoyieldExpr * S)1418 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1419 VisitExpr(S);
1420 }
1421
VisitOpaqueValueExpr(const OpaqueValueExpr * E)1422 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1423 VisitExpr(E);
1424 }
1425
VisitTypoExpr(const TypoExpr * E)1426 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1427 VisitExpr(E);
1428 }
1429
VisitObjCStringLiteral(const ObjCStringLiteral * S)1430 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1431 VisitExpr(S);
1432 }
1433
VisitObjCBoxedExpr(const ObjCBoxedExpr * E)1434 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1435 VisitExpr(E);
1436 }
1437
VisitObjCArrayLiteral(const ObjCArrayLiteral * E)1438 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1439 VisitExpr(E);
1440 }
1441
VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral * E)1442 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1443 VisitExpr(E);
1444 }
1445
VisitObjCEncodeExpr(const ObjCEncodeExpr * S)1446 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1447 VisitExpr(S);
1448 VisitType(S->getEncodedType());
1449 }
1450
VisitObjCSelectorExpr(const ObjCSelectorExpr * S)1451 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1452 VisitExpr(S);
1453 VisitName(S->getSelector());
1454 }
1455
VisitObjCProtocolExpr(const ObjCProtocolExpr * S)1456 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1457 VisitExpr(S);
1458 VisitDecl(S->getProtocol());
1459 }
1460
VisitObjCIvarRefExpr(const ObjCIvarRefExpr * S)1461 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1462 VisitExpr(S);
1463 VisitDecl(S->getDecl());
1464 ID.AddBoolean(S->isArrow());
1465 ID.AddBoolean(S->isFreeIvar());
1466 }
1467
VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr * S)1468 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1469 VisitExpr(S);
1470 if (S->isImplicitProperty()) {
1471 VisitDecl(S->getImplicitPropertyGetter());
1472 VisitDecl(S->getImplicitPropertySetter());
1473 } else {
1474 VisitDecl(S->getExplicitProperty());
1475 }
1476 if (S->isSuperReceiver()) {
1477 ID.AddBoolean(S->isSuperReceiver());
1478 VisitType(S->getSuperReceiverType());
1479 }
1480 }
1481
VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr * S)1482 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1483 VisitExpr(S);
1484 VisitDecl(S->getAtIndexMethodDecl());
1485 VisitDecl(S->setAtIndexMethodDecl());
1486 }
1487
VisitObjCMessageExpr(const ObjCMessageExpr * S)1488 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1489 VisitExpr(S);
1490 VisitName(S->getSelector());
1491 VisitDecl(S->getMethodDecl());
1492 }
1493
VisitObjCIsaExpr(const ObjCIsaExpr * S)1494 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1495 VisitExpr(S);
1496 ID.AddBoolean(S->isArrow());
1497 }
1498
VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr * S)1499 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1500 VisitExpr(S);
1501 ID.AddBoolean(S->getValue());
1502 }
1503
VisitObjCIndirectCopyRestoreExpr(const ObjCIndirectCopyRestoreExpr * S)1504 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1505 const ObjCIndirectCopyRestoreExpr *S) {
1506 VisitExpr(S);
1507 ID.AddBoolean(S->shouldCopy());
1508 }
1509
VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr * S)1510 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1511 VisitExplicitCastExpr(S);
1512 ID.AddBoolean(S->getBridgeKind());
1513 }
1514
VisitDecl(const Decl * D)1515 void StmtProfiler::VisitDecl(const Decl *D) {
1516 ID.AddInteger(D? D->getKind() : 0);
1517
1518 if (Canonical && D) {
1519 if (const NonTypeTemplateParmDecl *NTTP =
1520 dyn_cast<NonTypeTemplateParmDecl>(D)) {
1521 ID.AddInteger(NTTP->getDepth());
1522 ID.AddInteger(NTTP->getIndex());
1523 ID.AddBoolean(NTTP->isParameterPack());
1524 VisitType(NTTP->getType());
1525 return;
1526 }
1527
1528 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
1529 // The Itanium C++ ABI uses the type, scope depth, and scope
1530 // index of a parameter when mangling expressions that involve
1531 // function parameters, so we will use the parameter's type for
1532 // establishing function parameter identity. That way, our
1533 // definition of "equivalent" (per C++ [temp.over.link]) is at
1534 // least as strong as the definition of "equivalent" used for
1535 // name mangling.
1536 VisitType(Parm->getType());
1537 ID.AddInteger(Parm->getFunctionScopeDepth());
1538 ID.AddInteger(Parm->getFunctionScopeIndex());
1539 return;
1540 }
1541
1542 if (const TemplateTypeParmDecl *TTP =
1543 dyn_cast<TemplateTypeParmDecl>(D)) {
1544 ID.AddInteger(TTP->getDepth());
1545 ID.AddInteger(TTP->getIndex());
1546 ID.AddBoolean(TTP->isParameterPack());
1547 return;
1548 }
1549
1550 if (const TemplateTemplateParmDecl *TTP =
1551 dyn_cast<TemplateTemplateParmDecl>(D)) {
1552 ID.AddInteger(TTP->getDepth());
1553 ID.AddInteger(TTP->getIndex());
1554 ID.AddBoolean(TTP->isParameterPack());
1555 return;
1556 }
1557 }
1558
1559 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
1560 }
1561
VisitType(QualType T)1562 void StmtProfiler::VisitType(QualType T) {
1563 if (Canonical)
1564 T = Context.getCanonicalType(T);
1565
1566 ID.AddPointer(T.getAsOpaquePtr());
1567 }
1568
VisitName(DeclarationName Name)1569 void StmtProfiler::VisitName(DeclarationName Name) {
1570 ID.AddPointer(Name.getAsOpaquePtr());
1571 }
1572
VisitNestedNameSpecifier(NestedNameSpecifier * NNS)1573 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1574 if (Canonical)
1575 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1576 ID.AddPointer(NNS);
1577 }
1578
VisitTemplateName(TemplateName Name)1579 void StmtProfiler::VisitTemplateName(TemplateName Name) {
1580 if (Canonical)
1581 Name = Context.getCanonicalTemplateName(Name);
1582
1583 Name.Profile(ID);
1584 }
1585
VisitTemplateArguments(const TemplateArgumentLoc * Args,unsigned NumArgs)1586 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1587 unsigned NumArgs) {
1588 ID.AddInteger(NumArgs);
1589 for (unsigned I = 0; I != NumArgs; ++I)
1590 VisitTemplateArgument(Args[I].getArgument());
1591 }
1592
VisitTemplateArgument(const TemplateArgument & Arg)1593 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1594 // Mostly repetitive with TemplateArgument::Profile!
1595 ID.AddInteger(Arg.getKind());
1596 switch (Arg.getKind()) {
1597 case TemplateArgument::Null:
1598 break;
1599
1600 case TemplateArgument::Type:
1601 VisitType(Arg.getAsType());
1602 break;
1603
1604 case TemplateArgument::Template:
1605 case TemplateArgument::TemplateExpansion:
1606 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1607 break;
1608
1609 case TemplateArgument::Declaration:
1610 VisitDecl(Arg.getAsDecl());
1611 break;
1612
1613 case TemplateArgument::NullPtr:
1614 VisitType(Arg.getNullPtrType());
1615 break;
1616
1617 case TemplateArgument::Integral:
1618 Arg.getAsIntegral().Profile(ID);
1619 VisitType(Arg.getIntegralType());
1620 break;
1621
1622 case TemplateArgument::Expression:
1623 Visit(Arg.getAsExpr());
1624 break;
1625
1626 case TemplateArgument::Pack:
1627 for (const auto &P : Arg.pack_elements())
1628 VisitTemplateArgument(P);
1629 break;
1630 }
1631 }
1632
Profile(llvm::FoldingSetNodeID & ID,const ASTContext & Context,bool Canonical) const1633 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1634 bool Canonical) const {
1635 StmtProfiler Profiler(ID, Context, Canonical);
1636 Profiler.Visit(this);
1637 }
1638