1515#include " swift/AST/SemanticAttrs.h"
1616#include " swift/SIL/BasicBlockDatastructures.h"
1717#include " swift/SIL/InstructionUtils.h"
18+ #include " swift/SIL/PrettyStackTrace.h"
1819#include " swift/SIL/ApplySite.h"
1920#include " swift/SILOptimizer/Analysis/ArraySemantic.h"
2021#include " swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
@@ -119,6 +120,9 @@ static bool isEffectFreeArraySemanticCall(SILInstruction *inst) {
119120bool PerformanceDiagnostics::visitFunction (SILFunction *function,
120121 PerformanceConstraints perfConstr,
121122 LocWithParent *parentLoc) {
123+ PrettyStackTraceSILFunction stackTrace (
124+ " Running performance diangostics on (visiting) " , function);
125+
122126 if (!function->isDefinition ())
123127 return false ;
124128
@@ -156,6 +160,8 @@ bool PerformanceDiagnostics::visitFunction(SILFunction *function,
156160 if (visitCallee (&inst, bca->getCalleeList (as), perfConstr, parentLoc))
157161 return true ;
158162 } else if (auto *bi = dyn_cast<BuiltinInst>(&inst)) {
163+ PrettyStackTraceSILNode biStackTrace (
164+ " Validating built in (once, once with context)" , bi);
159165 switch (bi->getBuiltinInfo ().ID ) {
160166 case BuiltinValueKind::Once:
161167 case BuiltinValueKind::OnceWithContext:
@@ -204,6 +210,8 @@ bool PerformanceDiagnostics::checkClosureValue(SILValue closure,
204210 SILInstruction *callInst,
205211 PerformanceConstraints perfConstr,
206212 LocWithParent *parentLoc) {
213+ PrettyStackTraceSILNode closureStackTrace (" Validating closure" , closure);
214+
207215 // Walk through the definition of the closure until we find the "underlying"
208216 // function_ref instruction.
209217 while (!isa<FunctionRefInst>(closure)) {
@@ -243,6 +251,8 @@ bool PerformanceDiagnostics::visitCallee(SILInstruction *callInst,
243251 CalleeList callees,
244252 PerformanceConstraints perfConstr,
245253 LocWithParent *parentLoc) {
254+ PrettyStackTraceSILNode callStackTrace (" Validating callee" , callInst);
255+
246256 LocWithParent asLoc (callInst->getLoc ().getSourceLoc (), parentLoc);
247257 LocWithParent *loc = &asLoc;
248258 if (parentLoc && asLoc.loc == callInst->getFunction ()->getLocation ().getSourceLoc ())
@@ -281,6 +291,8 @@ bool PerformanceDiagnostics::visitCallee(SILInstruction *callInst,
281291}
282292
283293static bool metatypeUsesAreNotRelevant (MetatypeInst *mt) {
294+ PrettyStackTraceSILNode mtStackTrace (" Validating metatype" , mt);
295+
284296 for (Operand *use : mt->getUses ()) {
285297 if (auto *bi = dyn_cast<BuiltinInst>(use->getUser ())) {
286298 switch (bi->getBuiltinInfo ().ID ) {
@@ -303,6 +315,8 @@ static bool metatypeUsesAreNotRelevant(MetatypeInst *mt) {
303315bool PerformanceDiagnostics::visitInst (SILInstruction *inst,
304316 PerformanceConstraints perfConstr,
305317 LocWithParent *parentLoc) {
318+ PrettyStackTraceSILNode stackTrace (" validating sil instruction (visiting)" , inst);
319+
306320 SILType impactType;
307321 RuntimeEffect impact = getRuntimeEffect (inst, impactType);
308322 LocWithParent loc (inst->getLoc ().getSourceLoc (), parentLoc);
0 commit comments