Skip to content

Commit 337cbef

Browse files
committed
[Profiler] Remove canCreateProfilerForAST
Preserve the assertions to make sure functions and closures have bodies, but the other checks seem redundant. SILGen already asserts that we have a type-checked SourceFile, and we already control what nodes we call `createProfiler` for.
1 parent 7529346 commit 337cbef

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

lib/SIL/IR/SILProfiler.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,6 @@ static Stmt *getProfilerStmtForCase(CaseStmt *caseStmt) {
6262
llvm_unreachable("invalid parent kind");
6363
}
6464

65-
/// Check that the input AST has at least been type-checked.
66-
LLVM_ATTRIBUTE_UNUSED
67-
static bool hasFileBeenTypeChecked(SILDeclRef forDecl) {
68-
auto *SF = forDecl.getInnermostDeclContext()->getParentSourceFile();
69-
return SF && SF->ASTStage >= SourceFile::TypeChecked;
70-
}
71-
72-
/// Check whether a mapped AST node is valid for profiling.
73-
static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
74-
assert(hasFileBeenTypeChecked(forDecl) &&
75-
"Cannot use this AST for profiling");
76-
77-
if (auto *D = N.dyn_cast<Decl *>()) {
78-
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D))
79-
return AFD->hasBody();
80-
81-
if (isa<TopLevelCodeDecl>(D))
82-
return true;
83-
} else if (N.get<Expr *>()) {
84-
if (auto *closure = forDecl.getAbstractClosureExpr())
85-
return closure->hasBody();
86-
if (forDecl.isStoredPropertyInitializer() ||
87-
forDecl.isPropertyWrapperBackingInitializer())
88-
return true;
89-
}
90-
return false;
91-
}
92-
9365
SILProfiler *SILProfiler::create(SILModule &M, ASTNode N, SILDeclRef Ref) {
9466
// If profiling isn't enabled, don't profile anything.
9567
const auto &Opts = M.getOptions();
@@ -99,11 +71,6 @@ SILProfiler *SILProfiler::create(SILModule &M, ASTNode N, SILDeclRef Ref) {
9971
if (!shouldProfile(N, Ref))
10072
return nullptr;
10173

102-
if (!canCreateProfilerForAST(N, Ref)) {
103-
N.dump(llvm::errs());
104-
llvm_unreachable("Invalid AST node for profiling");
105-
}
106-
10774
auto *Buf = M.allocate<SILProfiler>(1);
10875
auto *SP =
10976
::new (Buf) SILProfiler(M, N, Ref, Opts.EmitProfileCoverageMapping);
@@ -163,6 +130,7 @@ namespace {
163130
template <typename F>
164131
ASTWalker::PreWalkAction
165132
visitFunctionDecl(ASTWalker &Walker, AbstractFunctionDecl *AFD, F Func) {
133+
assert(AFD->hasBody());
166134
if (Walker.Parent.isNull()) {
167135
Func();
168136
return ASTWalker::Action::Continue();
@@ -177,7 +145,9 @@ shouldWalkIntoExpr(Expr *E, ASTWalker::ParentTy Parent, SILDeclRef Constant) {
177145

178146
// Profiling for closures should be handled separately. Do not visit
179147
// closure expressions twice.
180-
if (isa<AbstractClosureExpr>(E)) {
148+
if (auto *CE = dyn_cast<AbstractClosureExpr>(E)) {
149+
assert(CE->hasBody());
150+
181151
// A non-null parent means we have a closure child, which we will visit
182152
// separately. Even if the parent is null, don't walk into a closure if the
183153
// SILDeclRef is not for a closure, as it could be for a property

0 commit comments

Comments
 (0)