Skip to content

Commit 51946b1

Browse files
committed
[Profiler] Use proper SILDeclRef for top-level code
Use a main entry-point instead of a null SILDeclRef. Eventually we'll want to unify the emission here such that we visit all the TopLevelDecls in one shot (and just use a single profiler), but for now we can just hand the SILProfiler the expected SILDeclRef.
1 parent e51f1ff commit 51946b1

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/SIL/IR/SILFunction.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,11 @@ void SILFunction::deleteSnapshot(int ID) {
334334

335335
void SILFunction::createProfiler(ASTNode Root, SILDeclRef Ref) {
336336
assert(!Profiler && "Function already has a profiler");
337+
assert(Root && "Cannot profile a null ASTNode");
338+
assert(Ref && "Must have non-null SILDeclRef");
339+
337340
Profiler = SILProfiler::create(Module, Root, Ref);
338-
if (!Profiler || Ref.isNull())
341+
if (!Profiler)
339342
return;
340343

341344
// If we loaded a profile, set the entry counts for functions and closures

lib/SIL/IR/SILProfiler.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ static bool shouldProfile(ASTNode N, SILDeclRef Constant) {
4040
<< "Skipping ASTNode: invalid start/end locations\n");
4141
return false;
4242
}
43-
if (!Constant) {
44-
// We should only ever have a null SILDeclRef for top-level code, which is
45-
// always user-written, and should always be profiled.
46-
// FIXME: Once top-level code is unified under a single SILProfiler, this
47-
// case can be eliminated.
48-
assert(isa<TopLevelCodeDecl>(N.get<Decl *>()));
49-
return true;
50-
}
5143

5244
// Do not profile AST nodes in unavailable contexts.
5345
auto *DC = Constant.getInnermostDeclContext();

lib/SILGen/SILGen.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,10 +1946,20 @@ void SILGenModule::visitTopLevelCodeDecl(TopLevelCodeDecl *td) {
19461946
if (!TopLevelSGF->B.hasValidInsertionPoint())
19471947
return;
19481948

1949+
// Retrieve the entry point constant we're emitting for.
1950+
// FIXME: This won't be necessary once we unify emission of the entry point
1951+
// such that we walk all of the TopLevelCodeDecls in one shot. This will be
1952+
// needed in order to requestify entry point emission.
1953+
auto *SF = td->getParentSourceFile();
1954+
assert(SF && "TopLevelDecl outside of a SourceFile?");
1955+
auto entryPoint = TopLevelSGF->F.isAsync()
1956+
? SILDeclRef::getAsyncMainFileEntryPoint(SF)
1957+
: SILDeclRef::getMainFileEntryPoint(SF);
1958+
19491959
// A single SILFunction may be used to lower multiple top-level decls. When
19501960
// this happens, fresh profile counters must be assigned to the new decl.
19511961
TopLevelSGF->F.discardProfiler();
1952-
TopLevelSGF->F.createProfiler(td, SILDeclRef());
1962+
TopLevelSGF->F.createProfiler(td, entryPoint);
19531963

19541964
TopLevelSGF->emitProfilerIncrement(td->getBody());
19551965

0 commit comments

Comments
 (0)