@@ -59,17 +59,6 @@ static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
59
59
return true ;
60
60
}
61
61
62
- // / Get the DeclContext for the decl referenced by \p forDecl.
63
- DeclContext *getProfilerContextForDecl (ASTNode N, SILDeclRef forDecl) {
64
- if (auto *D = N.dyn_cast <Decl *>())
65
- if (auto *TLCD = dyn_cast<TopLevelCodeDecl>(D))
66
- return TLCD;
67
- assert (!forDecl.isNull () && " Expected a nonnull SILDeclRef" );
68
- if (auto *ACE = forDecl.getAbstractClosureExpr ())
69
- return ACE;
70
- return forDecl.getDecl ()->getDeclContext ();
71
- }
72
-
73
62
static Stmt *getProfilerStmtForCase (CaseStmt *caseStmt) {
74
63
switch (caseStmt->getParentKind ()) {
75
64
case CaseParentKind::Switch:
@@ -82,15 +71,14 @@ static Stmt *getProfilerStmtForCase(CaseStmt *caseStmt) {
82
71
83
72
// / Check that the input AST has at least been type-checked.
84
73
LLVM_ATTRIBUTE_UNUSED
85
- static bool hasASTBeenTypeChecked (ASTNode N, SILDeclRef forDecl) {
86
- DeclContext *DC = getProfilerContextForDecl (N, forDecl);
87
- SourceFile *SF = DC->getParentSourceFile ();
88
- return !SF || SF->ASTStage >= SourceFile::TypeChecked;
74
+ static bool hasFileBeenTypeChecked (SILDeclRef forDecl) {
75
+ auto *SF = forDecl.getInnermostDeclContext ()->getParentSourceFile ();
76
+ return SF && SF->ASTStage >= SourceFile::TypeChecked;
89
77
}
90
78
91
79
// / Check whether a mapped AST node is valid for profiling.
92
80
static bool canCreateProfilerForAST (ASTNode N, SILDeclRef forDecl) {
93
- assert (hasASTBeenTypeChecked (N, forDecl) &&
81
+ assert (hasFileBeenTypeChecked ( forDecl) &&
94
82
" Cannot use this AST for profiling" );
95
83
96
84
if (auto *D = N.dyn_cast <Decl *>()) {
@@ -1240,17 +1228,17 @@ getEquivalentPGOLinkage(FormalLinkage Linkage) {
1240
1228
llvm_unreachable (" Unhandled FormalLinkage in switch." );
1241
1229
}
1242
1230
1243
- static StringRef getCurrentFileName (ASTNode N, SILDeclRef forDecl) {
1244
- DeclContext *Ctx = getProfilerContextForDecl (N, forDecl);
1245
- if (auto *ParentFile = Ctx ->getParentSourceFile ())
1231
+ static StringRef getCurrentFileName (SILDeclRef forDecl) {
1232
+ auto *DC = forDecl. getInnermostDeclContext ( );
1233
+ if (auto *ParentFile = DC ->getParentSourceFile ())
1246
1234
return ParentFile->getFilename ();
1247
1235
return {};
1248
1236
}
1249
1237
1250
1238
void SILProfiler::assignRegionCounters () {
1251
1239
const auto &SM = M.getASTContext ().SourceMgr ;
1252
1240
1253
- CurrentFileName = getCurrentFileName (Root, forDecl);
1241
+ CurrentFileName = getCurrentFileName (forDecl);
1254
1242
1255
1243
MapRegionCounters Mapper (forDecl, RegionCounterMap);
1256
1244
0 commit comments