@@ -716,69 +716,64 @@ class EffectAnalyzer {
716716 }
717717
718718 void visitCall (Call* curr) {
719+ if (curr->isReturn ) {
720+ parent.branchesOut = true ;
721+ }
722+
719723 // call.without.effects has no effects.
720724 if (Intrinsics (parent.module ).isCallWithoutEffects (curr)) {
721725 return ;
722726 }
723727
724- // Get the target's effects, if they exist. Note that we must handle the
725- // case of the function not yet existing (we may be executed in the middle
726- // of a pass, which may have built up calls but not the targets of those
727- // calls; in such a case, we do not find the targets and therefore assume
728- // we know nothing about the effects, which is safe).
729- const EffectAnalyzer* targetEffects = nullptr ;
730- if (auto * target = parent.module .getFunctionOrNull (curr->target )) {
731- targetEffects = target->effects .get ();
732- }
733- if (targetEffects) {
734- populateEffectsFromGlobalEffects (*targetEffects, curr);
728+ if (auto * target = parent.module .getFunctionOrNull (curr->target );
729+ target && target->effects ) {
730+ populateEffectsFromGlobalEffects (*target->effects , curr);
735731 return ;
736732 }
737733
738- if (curr->isReturn ) {
739- parent.branchesOut = true ;
740- // When EH is enabled, any call can throw.
741- if (parent.features .hasExceptionHandling ()) {
734+ parent.calls = true ;
735+ // If EH is enabled and we don't have global effects information,
736+ // assume that the call body may throw.
737+ if (parent.features .hasExceptionHandling ()) {
738+ if (curr->isReturn ) {
742739 parent.hasReturnCallThrow = true ;
743740 }
744- }
745741
746- parent.calls = true ;
747- // When EH is enabled, any call can throw. Skip this for return calls
748- // because the throw is already more precisely captured by the combination
749- // of `hasReturnCallThrow` and `branchesOut`.
750- if (parent.features .hasExceptionHandling () && parent.tryDepth == 0 &&
751- !curr->isReturn ) {
752- parent.throws_ = true ;
742+ if (parent.tryDepth == 0 && !curr->isReturn ) {
743+ parent.throws_ = true ;
744+ }
753745 }
754746 }
755747 void visitCallIndirect (CallIndirect* curr) {
756- auto * table = getModule ()->getTable (curr->table );
757- if (!Type::isSubType (Type (curr->heapType , Nullability::Nullable), table->type )) {
748+ auto * table = parent.module .getTable (curr->table );
749+ if (!Type::isSubType (Type (curr->heapType , Nullability::Nullable),
750+ table->type )) {
758751 parent.trap = true ;
759752 return ;
760753 }
754+ if (table->type .isNullable ()) {
755+ parent.implicitTrap = true ;
756+ }
757+ if (curr->isReturn ) {
758+ parent.branchesOut = true ;
759+ }
761760
762761 if (auto it = parent.module .typeEffects .find (curr->heapType );
763- it != parent.module .typeEffects .end ()) {
764- parent.mergeIn (*it->second );
765-
766- if (table->type .isNullable ()) {
767- parent.implicitTrap = true ;
768- }
762+ it != parent.module .typeEffects .end () && it->second ) {
763+ populateEffectsFromGlobalEffects (*it->second , curr);
769764 return ;
770765 }
771766
772767 parent.calls = true ;
773- if (curr->isReturn ) {
774- parent.branchesOut = true ;
775- if (parent.features .hasExceptionHandling ()) {
768+ // If EH is enabled and we don't have global effects information,
769+ // assume that the call body may throw.
770+ if (parent.features .hasExceptionHandling ()) {
771+ if (curr->isReturn ) {
776772 parent.hasReturnCallThrow = true ;
777773 }
778- }
779- if (parent.features .hasExceptionHandling () &&
780- (parent.tryDepth == 0 && !curr->isReturn )) {
781- parent.throws_ = true ;
774+ if (parent.tryDepth == 0 && !curr->isReturn ) {
775+ parent.throws_ = true ;
776+ }
782777 }
783778 }
784779 void visitLocalGet (LocalGet* curr) {
@@ -1042,37 +1037,28 @@ class EffectAnalyzer {
10421037 return ;
10431038 }
10441039
1045- const EffectAnalyzer* targetEffects = nullptr ;
1046- if (auto it =
1047- parent.module .typeEffects .find (curr->target ->type .getHeapType ());
1048- it != parent.module .typeEffects .end ()) {
1049- targetEffects = it->second .get ();
1050- parent.mergeIn (*it->second );
1051- }
1052-
10531040 if (curr->isReturn ) {
10541041 parent.branchesOut = true ;
1055- // When EH is enabled, any call can throw.
1056- if (parent.features .hasExceptionHandling () &&
1057- (!targetEffects || targetEffects->throws ())) {
1058- parent.hasReturnCallThrow = true ;
1059- }
10601042 }
10611043
1062- if (targetEffects) {
1044+ if (auto it =
1045+ parent.module .typeEffects .find (curr->target ->type .getHeapType ());
1046+ it != parent.module .typeEffects .end () && it->second ) {
1047+ populateEffectsFromGlobalEffects (*it->second , curr);
10631048 return ;
10641049 }
1050+ parent.calls = true ;
10651051
1066- if (curr->isReturn ) {
1067- parent.branchesOut = true ;
1068- if (parent.features .hasExceptionHandling ()) {
1052+ // If EH is enabled and we don't have global effects information,
1053+ // assume that the call body may throw.
1054+ if (parent.features .hasExceptionHandling ()) {
1055+ if (curr->isReturn ) {
10691056 parent.hasReturnCallThrow = true ;
10701057 }
1071- }
1072- parent.calls = true ;
1073- if (parent.features .hasExceptionHandling () &&
1074- (parent.tryDepth == 0 && !curr->isReturn )) {
1075- parent.throws_ = true ;
1058+
1059+ if (parent.tryDepth == 0 && !curr->isReturn ) {
1060+ parent.throws_ = true ;
1061+ }
10761062 }
10771063 }
10781064 void visitRefTest (RefTest* curr) {}
@@ -1357,11 +1343,11 @@ class EffectAnalyzer {
13571343 }
13581344 }
13591345
1360- private:
1361- template <typename Call>
1362- bool populateEffectsFromGlobalEffects (const EffectAnalyzer& effects, const Call* curr) {
1346+ private:
1347+ template <typename CallType>
1348+ void populateEffectsFromGlobalEffects (const EffectAnalyzer& effects,
1349+ const CallType* curr) {
13631350 if (curr->isReturn ) {
1364- parent.branchesOut = true ;
13651351 if (effects.throws ()) {
13661352 parent.hasReturnCallThrow = true ;
13671353 }
@@ -1372,7 +1358,6 @@ class EffectAnalyzer {
13721358 filteredEffects.throws_ = false ;
13731359 parent.mergeIn (filteredEffects);
13741360 } else {
1375- // Just merge in all the effects.
13761361 parent.mergeIn (effects);
13771362 }
13781363 }
0 commit comments