Skip to content

Commit 5b1ca3f

Browse files
committed
[SILGen] Avoid forcing function bodies for profiling
This is no longer necessary now that we ensure we always SILGen functions that contain user code.
1 parent bd18c37 commit 5b1ca3f

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

include/swift/SIL/SILProfiler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class SILCoverageMap;
3131
class SILFunction;
3232
class SILModule;
3333

34-
/// Returns whether the given AST node requires profiling instrumentation.
35-
bool doesASTRequireProfiling(SILModule &M, ASTNode N, SILDeclRef Constant);
36-
3734
/// SILProfiler - Maps AST nodes to profile counters.
3835
class SILProfiler : public SILAllocated<SILProfiler> {
3936
private:

lib/SIL/IR/SILProfiler.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
9898
return true;
9999
}
100100

101-
namespace swift {
102-
bool doesASTRequireProfiling(SILModule &M, ASTNode N, SILDeclRef Constant) {
103-
// If profiling isn't enabled, don't profile anything.
104-
auto &Opts = M.getOptions();
105-
if (Opts.UseProfile.empty() && !Opts.GenerateProfile)
106-
return false;
107-
108-
return shouldProfile(N, Constant);
109-
}
110-
} // namespace swift
111-
112101
/// Get the DeclContext for the decl referenced by \p forDecl.
113102
DeclContext *getProfilerContextForDecl(ASTNode N, SILDeclRef forDecl) {
114103
if (auto *D = N.dyn_cast<Decl *>())
@@ -159,8 +148,12 @@ static bool canCreateProfilerForAST(ASTNode N, SILDeclRef forDecl) {
159148
}
160149

161150
SILProfiler *SILProfiler::create(SILModule &M, ASTNode N, SILDeclRef Ref) {
151+
// If profiling isn't enabled, don't profile anything.
162152
const auto &Opts = M.getOptions();
163-
if (!doesASTRequireProfiling(M, N, Ref))
153+
if (!Opts.GenerateProfile && Opts.UseProfile.empty())
154+
return nullptr;
155+
156+
if (!shouldProfile(N, Ref))
164157
return nullptr;
165158

166159
if (!canCreateProfilerForAST(N, Ref)) {

lib/SILGen/SILGen.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,24 +1173,20 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
11731173

11741174
/// Emit a function now, if it's externally usable or has been referenced in
11751175
/// the current TU, or remember how to emit it later if not.
1176-
static void emitOrDelayFunction(SILGenModule &SGM,
1177-
SILDeclRef constant,
1178-
bool forceEmission = false) {
1176+
static void emitOrDelayFunction(SILGenModule &SGM, SILDeclRef constant) {
11791177
assert(!constant.isThunk());
11801178
assert(!constant.isClangImported());
11811179

11821180
auto emitAfter = SGM.lastEmittedFunction;
11831181

1184-
SILFunction *f = nullptr;
1185-
11861182
// Implicit decls may be delayed if they can't be used externally.
11871183
auto linkage = constant.getLinkage(ForDefinition);
1188-
bool mayDelay = !forceEmission &&
1189-
(!constant.hasUserWrittenCode() &&
1190-
!constant.isDynamicallyReplaceable() &&
1191-
!isPossiblyUsedExternally(linkage, SGM.M.isWholeModule()));
1184+
bool mayDelay = !constant.hasUserWrittenCode() &&
1185+
!constant.isDynamicallyReplaceable() &&
1186+
!isPossiblyUsedExternally(linkage, SGM.M.isWholeModule());
11921187

11931188
// Avoid emitting a delayable definition if it hasn't already been referenced.
1189+
SILFunction *f = nullptr;
11941190
if (mayDelay)
11951191
f = SGM.getEmittedFunction(constant, ForDefinition);
11961192
else
@@ -1444,12 +1440,8 @@ void SILGenModule::emitFunction(FuncDecl *fd) {
14441440

14451441
emitAbstractFuncDecl(fd);
14461442

1447-
if (fd->hasBody()) {
1448-
SILDeclRef constant(decl);
1449-
bool ForCoverageMapping = doesASTRequireProfiling(M, fd, constant);
1450-
emitOrDelayFunction(*this, constant,
1451-
/*forceEmission=*/ForCoverageMapping);
1452-
}
1443+
if (fd->hasBody())
1444+
emitOrDelayFunction(*this, SILDeclRef(decl));
14531445
}
14541446

14551447
void SILGenModule::addGlobalVariable(VarDecl *global) {

0 commit comments

Comments
 (0)