@@ -1342,6 +1342,8 @@ struct AsyncifyAssertInNonInstrumented : public Pass {
13421342};
13431343
13441344struct AsyncifyAssertUnwindCorrectness : Pass {
1345+ bool isFunctionParallel () override { return true ; }
1346+
13451347 ModuleAnalyzer* analyzer;
13461348 Module* module ;
13471349
@@ -1354,17 +1356,14 @@ struct AsyncifyAssertUnwindCorrectness : Pass {
13541356 return std::make_unique<AsyncifyAssertUnwindCorrectness>(analyzer, module );
13551357 }
13561358
1357- bool isFunctionParallel () override { return true ; }
1358-
1359- void runOnFunction (Module*, Function* function) override {
1360- auto builder = std::make_unique<Builder>(*module );
1361-
1359+ void runOnFunction (Module* module_, Function* function) override {
13621360 struct UnwindWalker : WalkerPass<ExpressionStackWalker<UnwindWalker>> {
13631361 Function* function;
1364- Builder* builder ;
1362+ Module* module ;
13651363
13661364 // Adds a check for Call that is inside a Catch block (we do not handle unwinding there).
1367- void checkCallInsideCatch (Call* call) {
1365+ void replaceCallWithCheck (Call* call) {
1366+ auto builder = std::make_unique<Builder>(*module );
13681367 auto check = builder->makeIf (
13691368 builder->makeBinary (NeInt32,
13701369 builder->makeGlobalGet (ASYNCIFY_STATE, Type::i32 ),
@@ -1391,6 +1390,11 @@ struct AsyncifyAssertUnwindCorrectness : Pass {
13911390
13921391 void visitCall (Call* curr) {
13931392 assert (!expressionStack.empty ());
1393+ // A return_call (curr->isReturn) can be ignored here: It returns first,
1394+ // leaving the Catch, before calling.
1395+ if (curr->isReturn ) {
1396+ return ;
1397+ }
13941398 // Go up the stack and see if we are in a Catch.
13951399 Index i = expressionStack.size () - 1 ;
13961400 while (i > 0 ) {
@@ -1411,7 +1415,7 @@ struct AsyncifyAssertUnwindCorrectness : Pass {
14111415
14121416 UnwindWalker walker;
14131417 walker.function = function;
1414- walker.builder = builder. get () ;
1418+ walker.module = module_ ;
14151419 walker.walk (function->body );
14161420 }
14171421};
@@ -1855,7 +1859,6 @@ struct Asyncify : public Pass {
18551859 runner.setValidateGlobally (false );
18561860 runner.run ();
18571861 }
1858- if (asserts) {
18591862 // Add asserts in non-instrumented code. Note we do not use an
18601863 // instrumented pass runner here as we do want to run on all functions.
18611864 PassRunner runner (module );
@@ -1868,29 +1871,28 @@ struct Asyncify : public Pass {
18681871 runner.setIsNested (true );
18691872 runner.setValidateGlobally (false );
18701873 runner.run ();
1871- }
1872- // Next, add local saving/restoring logic. We optimize before doing this,
1873- // to undo the extra code generated by flattening, and to arrive at the
1874- // minimal amount of locals (which is important as we must save and
1875- // restore those locals). We also and optimize after as well to simplify
1876- // the code as much as possible.
1877- {
1878- PassUtils::FilteredPassRunner runner (module , instrumentedFuncs);
1879- if (optimize) {
1880- runner.addDefaultFunctionOptimizationPasses ();
1881- }
1882- runner.add (std::make_unique<AsyncifyLocals>(
1883- &analyzer, pointerType, asyncifyMemory));
1884- if (optimize) {
1885- runner.addDefaultFunctionOptimizationPasses ();
1874+ // Next, add local saving/restoring logic. We optimize before doing this,
1875+ // to undo the extra code generated by flattening, and to arrive at the
1876+ // minimal amount of locals (which is important as we must save and
1877+ // restore those locals). We also and optimize after as well to simplify
1878+ // the code as much as possible.
1879+ {
1880+ PassUtils::FilteredPassRunner runner (module , instrumentedFuncs);
1881+ if (optimize) {
1882+ runner.addDefaultFunctionOptimizationPasses ();
1883+ }
1884+ runner.add (std::make_unique<AsyncifyLocals>(
1885+ &analyzer, pointerType, asyncifyMemory));
1886+ if (optimize) {
1887+ runner.addDefaultFunctionOptimizationPasses ();
1888+ }
1889+ runner.setIsNested (true );
1890+ runner.setValidateGlobally (false );
1891+ runner.run ();
18861892 }
1887- runner.setIsNested (true );
1888- runner.setValidateGlobally (false );
1889- runner.run ();
1890- }
18911893 // Finally, add function support (that should not have been seen by
18921894 // the previous passes).
1893- addFunctions (module , asserts );
1895+ addFunctions (module );
18941896 }
18951897
18961898private:
@@ -1918,14 +1920,14 @@ struct Asyncify : public Pass {
19181920 module ->addGlobal (std::move (asyncifyData));
19191921 }
19201922
1921- void addFunctions (Module* module , bool asserts ) {
1923+ void addFunctions (Module* module ) {
19221924 Builder builder (*module );
19231925 auto makeFunction = [&](Name name, bool setData, State state) {
1924- auto * body = builder.makeBlock ();
19251926 std::vector<Type> params;
19261927 if (setData) {
19271928 params.push_back (pointerType);
19281929 }
1930+ auto * body = builder.makeBlock ();
19291931 body->list .push_back (builder.makeGlobalSet (
19301932 ASYNCIFY_STATE, builder.makeConst (int32_t (state))));
19311933 if (setData) {
0 commit comments