summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-09-26 15:03:27 -0700
committerGitHub <noreply@github.com>2023-09-26 15:03:27 -0700
commit3dd65a9a2231cb85b3a92a528a08213ce50c2bd8 (patch)
tree8d0b5e68be6f06eb01df57bbf39c39b0e37359c9 /src
parentd294627af51d7ca4f0d50ccdbd194b60651a76e6 (diff)
downloadbinaryen-3dd65a9a2231cb85b3a92a528a08213ce50c2bd8.tar.gz
binaryen-3dd65a9a2231cb85b3a92a528a08213ce50c2bd8.tar.bz2
binaryen-3dd65a9a2231cb85b3a92a528a08213ce50c2bd8.zip
[NFC] Refactor StackIR code to clarify local variable meanings (#5975)
Diffstat (limited to 'src')
-rw-r--r--src/passes/StackIR.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/passes/StackIR.cpp b/src/passes/StackIR.cpp
index 3d5426a17..4d5b867bd 100644
--- a/src/passes/StackIR.cpp
+++ b/src/passes/StackIR.cpp
@@ -148,15 +148,15 @@ private:
#ifdef STACK_OPT_DEBUG
std::cout << "func: " << func->name << '\n' << insts << '\n';
#endif
- for (Index i = 0; i < insts.size(); i++) {
- auto* inst = insts[i];
+ for (Index instIndex = 0; instIndex < insts.size(); instIndex++) {
+ auto* inst = insts[instIndex];
if (!inst) {
continue;
}
// First, consume values from the stack as required.
auto consumed = getNumConsumedValues(inst);
#ifdef STACK_OPT_DEBUG
- std::cout << " " << i << " : " << *inst << ", " << values.size()
+ std::cout << " " << instIndex << " : " << *inst << ", " << values.size()
<< " on stack, will consume " << consumed << "\n ";
for (auto s : values)
std::cout << s << ' ';
@@ -199,17 +199,20 @@ private:
// optimization would intefere with that one.
if (auto* get = inst->origin->dynCast<LocalGet>();
get && inst->type.isSingle()) {
+ // Use another local to clarify what instIndex means in this scope.
+ auto getIndex = instIndex;
+
// This is a potential optimization opportunity! See if we
// can reach the set.
if (values.size() > 0) {
Index j = values.size() - 1;
while (1) {
// If there's an actual value in the way, we've failed.
- auto index = values[j];
- if (index == null) {
+ auto setIndex = values[j];
+ if (setIndex == null) {
break;
}
- auto* set = insts[index]->origin->cast<LocalSet>();
+ auto* set = insts[setIndex]->origin->cast<LocalSet>();
if (set->index == get->index) {
// This might be a proper set-get pair, where the set is
// used by this get and nothing else, check that.
@@ -219,15 +222,15 @@ private:
// If this has the proper value of 1, also do the potentially-
// expensive check of whether we can remove this pair at all.
if (setInfluences.size() == 1 &&
- canRemoveSetGetPair(index, i)) {
+ canRemoveSetGetPair(setIndex, getIndex)) {
assert(*setInfluences.begin() == get);
// Do it! The set and the get can go away, the proper
// value is on the stack.
#ifdef STACK_OPT_DEBUG
std::cout << " stackify the get\n";
#endif
- insts[index] = nullptr;
- insts[i] = nullptr;
+ insts[setIndex] = nullptr;
+ insts[getIndex] = nullptr;
// Continuing on from here, replace this on the stack
// with a null, representing a regular value. We
// keep possible values above us active - they may
@@ -253,7 +256,7 @@ private:
}
} else if (inst->origin->is<LocalSet>() && inst->type == Type::none) {
// This set is potentially optimizable later, add to stack.
- values.push_back(i);
+ values.push_back(instIndex);
}
}
}