@@ -1223,29 +1223,6 @@ void SILGenModule::visitTopLevelCodeDecl(TopLevelCodeDecl *td) {
12231223 }
12241224}
12251225
1226- static void emitTopLevelProlog (SILGenFunction &gen, SILLocation loc) {
1227- assert (gen.B .getInsertionBB ()->getIterator () == gen.F .begin ()
1228- && " not at entry point?!" );
1229-
1230- SILBasicBlock *entry = gen.B .getInsertionBB ();
1231- // Create the argc and argv arguments.
1232- auto &C = gen.getASTContext ();
1233- auto FnTy = gen.F .getLoweredFunctionType ();
1234- auto *argc = entry->createArgument (FnTy->getParameters ()[0 ].getSILType ());
1235- auto *argv = entry->createArgument (FnTy->getParameters ()[1 ].getSILType ());
1236-
1237- // If the standard library provides a _stdlib_didEnterMain intrinsic, call it
1238- // first thing.
1239- if (auto didEnterMain = C.getDidEnterMain (nullptr )) {
1240- ManagedValue params[] = {
1241- ManagedValue::forUnmanaged (argc),
1242- ManagedValue::forUnmanaged (argv),
1243- };
1244- (void ) gen.emitApplyOfLibraryIntrinsic (loc, didEnterMain, {}, params,
1245- SGFContext ());
1246- }
1247- }
1248-
12491226void SILGenModule::useConformance (ProtocolConformanceRef conformanceRef) {
12501227 // We don't need to emit dependent conformances.
12511228 if (conformanceRef.isAbstract ())
@@ -1308,9 +1285,13 @@ class SourceFileScope {
13081285 sgm.TopLevelSGF ->prepareRethrowEpilog (
13091286 CleanupLocation::getModuleCleanupLocation ());
13101287
1288+ // Create the argc and argv arguments.
13111289 auto PrologueLoc = RegularLocation::getModuleLocation ();
13121290 PrologueLoc.markAsPrologue ();
1313- emitTopLevelProlog (*sgm.TopLevelSGF , PrologueLoc);
1291+ auto entry = sgm.TopLevelSGF ->B .getInsertionBB ();
1292+ auto FnTy = sgm.TopLevelSGF ->F .getLoweredFunctionType ();
1293+ entry->createArgument (FnTy->getParameters ()[0 ].getSILType ());
1294+ entry->createArgument (FnTy->getParameters ()[1 ].getSILType ());
13141295
13151296 scope.emplace (sgm.TopLevelSGF ->Cleanups ,
13161297 CleanupLocation::getModuleCleanupLocation ());
@@ -1409,8 +1390,12 @@ class SourceFileScope {
14091390 // Assign a debug scope pointing into the void to the top level function.
14101391 toplevel->setDebugScope (new (sgm.M ) SILDebugScope (TopLevelLoc, toplevel));
14111392
1393+ // Create the argc and argv arguments.
14121394 SILGenFunction gen (sgm, *toplevel);
1413- emitTopLevelProlog (gen, mainClass);
1395+ auto entry = gen.B .getInsertionBB ();
1396+ auto FnTy = gen.F .getLoweredFunctionType ();
1397+ entry->createArgument (FnTy->getParameters ()[0 ].getSILType ());
1398+ entry->createArgument (FnTy->getParameters ()[1 ].getSILType ());
14141399 gen.emitArtificialTopLevel (mainClass);
14151400 }
14161401 }
0 commit comments