Skip to content

Commit 04ef945

Browse files
committed
[Profiler] Remove getProfilerContextForDecl
We can use `getInnermostDeclContext` instead. Also tighten up the condition of `hasFileBeenTypeChecked` a bit.
1 parent 89145f3 commit 04ef945

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
5959
return true;
6060
}
6161

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-
7362
static Stmt *getProfilerStmtForCase(CaseStmt *caseStmt) {
7463
switch (caseStmt->getParentKind()) {
7564
case CaseParentKind::Switch:
@@ -82,15 +71,14 @@ static Stmt *getProfilerStmtForCase(CaseStmt *caseStmt) {
8271

8372
/// Check that the input AST has at least been type-checked.
8473
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;
8977
}
9078

9179
/// Check whether a mapped AST node is valid for profiling.
9280
static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
93-
assert(hasASTBeenTypeChecked(N, forDecl) &&
81+
assert(hasFileBeenTypeChecked(forDecl) &&
9482
"Cannot use this AST for profiling");
9583

9684
if (auto *D = N.dyn_cast<Decl *>()) {
@@ -1240,17 +1228,17 @@ getEquivalentPGOLinkage(FormalLinkage Linkage) {
12401228
llvm_unreachable("Unhandled FormalLinkage in switch.");
12411229
}
12421230

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())
12461234
return ParentFile->getFilename();
12471235
return {};
12481236
}
12491237

12501238
void SILProfiler::assignRegionCounters() {
12511239
const auto &SM = M.getASTContext().SourceMgr;
12521240

1253-
CurrentFileName = getCurrentFileName(Root, forDecl);
1241+
CurrentFileName = getCurrentFileName(forDecl);
12541242

12551243
MapRegionCounters Mapper(forDecl, RegionCounterMap);
12561244

0 commit comments

Comments
 (0)