|
69 | 69 |
|
70 | 70 | #include "ir/module-splitting.h"
|
71 | 71 | #include "asmjs/shared-constants.h"
|
72 |
| -#include "ir/element-utils.h" |
73 | 72 | #include "ir/export-utils.h"
|
74 | 73 | #include "ir/manipulation.h"
|
75 | 74 | #include "ir/module-utils.h"
|
@@ -709,33 +708,36 @@ void ModuleSplitter::setupTablePatching() {
|
709 | 708 | // Replace table references to secondary functions with an imported
|
710 | 709 | // placeholder that encodes the table index in its name:
|
711 | 710 | // `importNamespace`.`index`.
|
712 |
| - forEachElement(primary, [&](Name, Name, Index index, Expression*& elem) { |
713 |
| - auto* ref = elem->dynCast<RefFunc>(); |
714 |
| - if (!ref) { |
715 |
| - return; |
716 |
| - } |
717 |
| - if (!secondaryFuncs.count(ref->func)) { |
718 |
| - return; |
719 |
| - } |
720 |
| - placeholderMap[index] = ref->func; |
721 |
| - auto* secondaryFunc = secondary.getFunction(ref->func); |
722 |
| - replacedElems[index] = secondaryFunc; |
723 |
| - if (!config.usePlaceholders) { |
724 |
| - // TODO: This can create active element segments with lots of nulls. We |
725 |
| - // should optimize them like we do data segments with zeros. |
726 |
| - elem = Builder(primary).makeRefNull(HeapType::nofunc); |
727 |
| - return; |
728 |
| - } |
729 |
| - auto placeholder = std::make_unique<Function>(); |
730 |
| - placeholder->module = config.placeholderNamespace; |
731 |
| - placeholder->base = std::to_string(index); |
732 |
| - placeholder->name = Names::getValidFunctionName( |
733 |
| - primary, std::string("placeholder_") + placeholder->base.toString()); |
734 |
| - placeholder->hasExplicitName = true; |
735 |
| - placeholder->type = secondaryFunc->type; |
736 |
| - elem = Builder(primary).makeRefFunc(placeholder->name, placeholder->type); |
737 |
| - primary.addFunction(std::move(placeholder)); |
738 |
| - }); |
| 711 | + forEachElement( |
| 712 | + primary, [&](Name table, Name, Index index, Expression*& elem) { |
| 713 | + auto* ref = elem->dynCast<RefFunc>(); |
| 714 | + if (!ref) { |
| 715 | + return; |
| 716 | + } |
| 717 | + if (!secondaryFuncs.count(ref->func)) { |
| 718 | + return; |
| 719 | + } |
| 720 | + assert(table == tableManager.activeTable->name); |
| 721 | + |
| 722 | + placeholderMap[index] = ref->func; |
| 723 | + auto* secondaryFunc = secondary.getFunction(ref->func); |
| 724 | + replacedElems[index] = secondaryFunc; |
| 725 | + if (!config.usePlaceholders) { |
| 726 | + // TODO: This can create active element segments with lots of nulls. We |
| 727 | + // should optimize them like we do data segments with zeros. |
| 728 | + elem = Builder(primary).makeRefNull(HeapType::nofunc); |
| 729 | + return; |
| 730 | + } |
| 731 | + auto placeholder = std::make_unique<Function>(); |
| 732 | + placeholder->module = config.placeholderNamespace; |
| 733 | + placeholder->base = std::to_string(index); |
| 734 | + placeholder->name = Names::getValidFunctionName( |
| 735 | + primary, std::string("placeholder_") + placeholder->base.toString()); |
| 736 | + placeholder->hasExplicitName = true; |
| 737 | + placeholder->type = secondaryFunc->type; |
| 738 | + elem = Builder(primary).makeRefFunc(placeholder->name, placeholder->type); |
| 739 | + primary.addFunction(std::move(placeholder)); |
| 740 | + }); |
739 | 741 |
|
740 | 742 | if (replacedElems.size() == 0) {
|
741 | 743 | // No placeholders to patch out of the table
|
|
0 commit comments