diff options
author | Alon Zakai <azakai@google.com> | 2023-05-04 17:20:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-05 00:20:13 +0000 |
commit | 879d7bfb0fcd8335892677fd6d24a2f02218a6c2 (patch) | |
tree | c32785d40ba673d96ffb32a23e3ccc437b277503 /src/passes/MemoryPacking.cpp | |
parent | 7f8e4cbf6273c9b13b3a1a42f5e2833ea0d0f686 (diff) | |
download | binaryen-879d7bfb0fcd8335892677fd6d24a2f02218a6c2.tar.gz binaryen-879d7bfb0fcd8335892677fd6d24a2f02218a6c2.tar.bz2 binaryen-879d7bfb0fcd8335892677fd6d24a2f02218a6c2.zip |
[NFC] Track the kinds of items that names refer to in wasm-delegations-fields (#5690)
This makes delegations-fields track Kinds. That is, rather than say a field is
just a Name, we can say it is a name of kind Function. This allows users to
track references to functions, tables, memories, etc., in a simple and generic
way, avoiding duplicated code which we have atm. (In particular this will help
wasm-merge in the future.)
This also uses that functionality in two small places to show the benefits
(see memory-utils.cpp and MemoryPacking.cpp).
Diffstat (limited to 'src/passes/MemoryPacking.cpp')
-rw-r--r-- | src/passes/MemoryPacking.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp index 08d1407f4..5f72a916d 100644 --- a/src/passes/MemoryPacking.cpp +++ b/src/passes/MemoryPacking.cpp @@ -464,21 +464,38 @@ void MemoryPacking::getSegmentReferrers(Module* module, if (func->imported()) { return; } - struct Collector : WalkerPass<PostWalker<Collector>> { + struct Collector + : WalkerPass<PostWalker<Collector, UnifiedExpressionVisitor<Collector>>> { ReferrersMap& referrers; Collector(ReferrersMap& referrers) : referrers(referrers) {} - void visitMemoryInit(MemoryInit* curr) { - referrers[curr->segment].push_back(curr); - } - void visitDataDrop(DataDrop* curr) { - referrers[curr->segment].push_back(curr); - } - void visitArrayNewData(ArrayNewData* curr) { - referrers[curr->segment].push_back(curr); - } - void visitArrayInitData(ArrayInitData* curr) { - referrers[curr->segment].push_back(curr); + void visitExpression(Expression* curr) { +#define DELEGATE_ID curr->_id + +#define DELEGATE_START(id) [[maybe_unused]] auto* cast = curr->cast<id>(); + +#define DELEGATE_GET_FIELD(id, field) cast->field + +#define DELEGATE_FIELD_TYPE(id, field) +#define DELEGATE_FIELD_HEAPTYPE(id, field) +#define DELEGATE_FIELD_CHILD(id, field) +#define DELEGATE_FIELD_OPTIONAL_CHILD(id, field) +#define DELEGATE_FIELD_INT(id, field) +#define DELEGATE_FIELD_INT_ARRAY(id, field) +#define DELEGATE_FIELD_LITERAL(id, field) +#define DELEGATE_FIELD_NAME(id, field) +#define DELEGATE_FIELD_NAME_VECTOR(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_DEF(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_USE(id, field) +#define DELEGATE_FIELD_SCOPE_NAME_USE_VECTOR(id, field) +#define DELEGATE_FIELD_ADDRESS(id, field) + +#define DELEGATE_FIELD_NAME_KIND(id, field, kind) \ + if (kind == ModuleItemKind::DataSegment) { \ + referrers[cast->field].push_back(curr); \ + } + +#include "wasm-delegations-fields.def" } } collector(referrers); collector.walkFunctionInModule(func, module); |