|
32 | 32 |
|
33 | 33 | using namespace swift;
|
34 | 34 |
|
35 |
| -/// Check if a closure has a body. |
36 |
| -static bool doesClosureHaveBody(AbstractClosureExpr *ACE) { |
37 |
| - if (auto *CE = dyn_cast<ClosureExpr>(ACE)) |
38 |
| - return CE->getBody(); |
39 |
| - if (auto *autoCE = dyn_cast<AutoClosureExpr>(ACE)) |
40 |
| - return autoCE->getBody(); |
41 |
| - return false; |
42 |
| -} |
43 |
| - |
44 | 35 | /// Check whether a root AST node should be profiled.
|
45 | 36 | static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
|
46 | 37 | // Do not profile AST nodes with invalid source locations.
|
@@ -73,28 +64,6 @@ static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
|
73 | 64 | return false;
|
74 | 65 | }
|
75 | 66 |
|
76 |
| - if (auto *E = N.dyn_cast<Expr *>()) { |
77 |
| - if (auto *CE = dyn_cast<AbstractClosureExpr>(E)) { |
78 |
| - // Only profile closure expressions with bodies. |
79 |
| - if (!doesClosureHaveBody(CE)) { |
80 |
| - LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: closure without body\n"); |
81 |
| - return false; |
82 |
| - } |
83 |
| - } |
84 |
| - |
85 |
| - // Profile all other kinds of expressions. |
86 |
| - return true; |
87 |
| - } |
88 |
| - |
89 |
| - auto *D = N.get<Decl *>(); |
90 |
| - if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) { |
91 |
| - // Don't profile functions without bodies. |
92 |
| - if (!AFD->hasBody()) { |
93 |
| - LLVM_DEBUG(llvm::dbgs() << "Skipping ASTNode: function without body\n"); |
94 |
| - return false; |
95 |
| - } |
96 |
| - } |
97 |
| - |
98 | 67 | return true;
|
99 | 68 | }
|
100 | 69 |
|
@@ -127,21 +96,22 @@ static bool hasASTBeenTypeChecked(ASTNode N, SILDeclRef forDecl) {
|
127 | 96 | return !SF || SF->ASTStage >= SourceFile::TypeChecked;
|
128 | 97 | }
|
129 | 98 |
|
130 |
| -/// Check whether a mapped AST node requires a new profiler. |
| 99 | +/// Check whether a mapped AST node is valid for profiling. |
131 | 100 | static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
|
132 | 101 | assert(hasASTBeenTypeChecked(N, forDecl) &&
|
133 | 102 | "Cannot use this AST for profiling");
|
134 | 103 |
|
135 | 104 | if (auto *D = N.dyn_cast<Decl *>()) {
|
136 |
| - if (isa<AbstractFunctionDecl>(D)) |
137 |
| - return true; |
| 105 | + if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D)) |
| 106 | + return AFD->hasBody(); |
138 | 107 |
|
139 | 108 | if (isa<TopLevelCodeDecl>(D))
|
140 | 109 | return true;
|
141 | 110 | } else if (N.get<Expr *>()) {
|
| 111 | + if (auto *closure = forDecl.getAbstractClosureExpr()) |
| 112 | + return closure->hasBody(); |
142 | 113 | if (forDecl.isStoredPropertyInitializer() ||
|
143 |
| - forDecl.isPropertyWrapperBackingInitializer() || |
144 |
| - forDecl.getAbstractClosureExpr()) |
| 114 | + forDecl.isPropertyWrapperBackingInitializer()) |
145 | 115 | return true;
|
146 | 116 | }
|
147 | 117 | return false;
|
|
0 commit comments