@@ -87,13 +87,6 @@ void BinaryInstWriter::visitCallIndirect(CallIndirect* curr) {
8787}
8888
8989void BinaryInstWriter::visitLocalGet (LocalGet* curr) {
90- if (auto it = extractedGets.find (curr); it != extractedGets.end ()) {
91- // We have a tuple of locals to get, but we will only end up using one of
92- // them, so we can just emit that one.
93- o << int8_t (BinaryConsts::LocalGet)
94- << U32LEB (mappedLocals[std::make_pair (curr->index , it->second )]);
95- return ;
96- }
9790 size_t numValues = func->getLocalType (curr->index ).size ();
9891 for (Index i = 0 ; i < numValues; ++i) {
9992 o << int8_t (BinaryConsts::LocalGet)
@@ -103,28 +96,14 @@ void BinaryInstWriter::visitLocalGet(LocalGet* curr) {
10396
10497void BinaryInstWriter::visitLocalSet (LocalSet* curr) {
10598 size_t numValues = func->getLocalType (curr->index ).size ();
106- // If this is a tuple, set all the elements with nonzero index.
10799 for (Index i = numValues - 1 ; i >= 1 ; --i) {
108100 o << int8_t (BinaryConsts::LocalSet)
109101 << U32LEB (mappedLocals[std::make_pair (curr->index , i)]);
110102 }
111103 if (!curr->isTee ()) {
112- // This is not a tee, so just finish setting the values.
113104 o << int8_t (BinaryConsts::LocalSet)
114105 << U32LEB (mappedLocals[std::make_pair (curr->index , 0 )]);
115- } else if (auto it = extractedGets.find (curr); it != extractedGets.end ()) {
116- // We only need to get the single extracted value.
117- if (it->second == 0 ) {
118- o << int8_t (BinaryConsts::LocalTee)
119- << U32LEB (mappedLocals[std::make_pair (curr->index , 0 )]);
120- } else {
121- o << int8_t (BinaryConsts::LocalSet)
122- << U32LEB (mappedLocals[std::make_pair (curr->index , 0 )]);
123- o << int8_t (BinaryConsts::LocalGet)
124- << U32LEB (mappedLocals[std::make_pair (curr->index , it->second )]);
125- }
126106 } else {
127- // We need to get all the values.
128107 o << int8_t (BinaryConsts::LocalTee)
129108 << U32LEB (mappedLocals[std::make_pair (curr->index , 0 )]);
130109 for (Index i = 1 ; i < numValues; ++i) {
@@ -135,14 +114,8 @@ void BinaryInstWriter::visitLocalSet(LocalSet* curr) {
135114}
136115
137116void BinaryInstWriter::visitGlobalGet (GlobalGet* curr) {
138- Index index = parent.getGlobalIndex (curr->name );
139- if (auto it = extractedGets.find (curr); it != extractedGets.end ()) {
140- // We have a tuple of globals to get, but we will only end up using one of
141- // them, so we can just emit that one.
142- o << int8_t (BinaryConsts::GlobalGet) << U32LEB (index + it->second );
143- return ;
144- }
145117 // Emit a global.get for each element if this is a tuple global
118+ Index index = parent.getGlobalIndex (curr->name );
146119 size_t numValues = curr->type .size ();
147120 for (Index i = 0 ; i < numValues; ++i) {
148121 o << int8_t (BinaryConsts::GlobalGet) << U32LEB (index + i);
@@ -1997,10 +1970,6 @@ void BinaryInstWriter::visitTupleMake(TupleMake* curr) {
19971970}
19981971
19991972void BinaryInstWriter::visitTupleExtract (TupleExtract* curr) {
2000- if (extractedGets.count (curr->tuple )) {
2001- // We already have just the extracted value on the stack.
2002- return ;
2003- }
20041973 size_t numVals = curr->tuple ->type .size ();
20051974 // Drop all values after the one we want
20061975 for (size_t i = curr->index + 1 ; i < numVals; ++i) {
@@ -2537,7 +2506,6 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() {
25372506 }
25382507 }
25392508 setScratchLocals ();
2540-
25412509 o << U32LEB (numLocalsByType.size ());
25422510 for (auto & localType : localTypes) {
25432511 o << U32LEB (numLocalsByType.at (localType));
@@ -2564,15 +2532,6 @@ void BinaryInstWriter::countScratchLocals() {
25642532 for (auto & [type, _] : scratchLocals) {
25652533 noteLocalType (type);
25662534 }
2567- // While we have all the tuple.extracts, also find extracts of local.gets,
2568- // local.tees, and global.gets that we can optimize.
2569- for (auto * extract : extracts.list ) {
2570- auto * tuple = extract->tuple ;
2571- if (tuple->is <LocalGet>() || tuple->is <LocalSet>() ||
2572- tuple->is <GlobalGet>()) {
2573- extractedGets.insert ({tuple, extract->index });
2574- }
2575- }
25762535}
25772536
25782537void BinaryInstWriter::setScratchLocals () {
0 commit comments