diff options
Diffstat (limited to 'src/passes/PickLoadSigns.cpp')
-rw-r--r-- | src/passes/PickLoadSigns.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/passes/PickLoadSigns.cpp b/src/passes/PickLoadSigns.cpp index fce50b4bb..f494159a1 100644 --- a/src/passes/PickLoadSigns.cpp +++ b/src/passes/PickLoadSigns.cpp @@ -14,9 +14,9 @@ * limitations under the License. */ -#include <wasm.h> -#include <pass.h> #include <ir/properties.h> +#include <pass.h> +#include <wasm.h> namespace wasm { @@ -39,7 +39,8 @@ struct PickLoadSigns : public WalkerPass<ExpressionStackWalker<PickLoadSigns>> { }; std::vector<Usage> usages; // local index => usage - std::unordered_map<Load*, Index> loads; // loads that write to a local => the local + // loads that write to a local => the local + std::unordered_map<Load*, Index> loads; void doWalkFunction(Function* func) { // prepare @@ -51,7 +52,8 @@ struct PickLoadSigns : public WalkerPass<ExpressionStackWalker<PickLoadSigns>> { } void visitGetLocal(GetLocal* curr) { - // this is a use. check from the context what it is, signed or unsigned, etc. + // this is a use. check from the context what it is, signed or unsigned, + // etc. auto& usage = usages[curr->index]; usage.totalUsages++; if (expressionStack.size() >= 2) { @@ -97,9 +99,14 @@ struct PickLoadSigns : public WalkerPass<ExpressionStackWalker<PickLoadSigns>> { auto& usage = usages[index]; // if we can't optimize, give up if (usage.totalUsages == 0 || // no usages, so no idea - usage.signedUsages + usage.unsignedUsages != usage.totalUsages || // non-sign/unsigned usages, so cannot change - (usage.signedUsages != 0 && usage.signedBits != load->bytes * 8) || // sign usages exist but the wrong size - (usage.unsignedUsages != 0 && usage.unsignedBits != load->bytes * 8)) { // unsigned usages exist but the wrong size + usage.signedUsages + usage.unsignedUsages != + usage.totalUsages || // non-sign/unsigned usages, so cannot change + (usage.signedUsages != 0 && + usage.signedBits != + load->bytes * 8) || // sign usages exist but the wrong size + (usage.unsignedUsages != 0 && + usage.unsignedBits != + load->bytes * 8)) { // unsigned usages exist but the wrong size continue; } // we can pick the optimal one. our hope is to remove 2 items per @@ -107,11 +114,8 @@ struct PickLoadSigns : public WalkerPass<ExpressionStackWalker<PickLoadSigns>> { load->signed_ = usage.signedUsages * 2 >= usage.unsignedUsages; } } - }; -Pass *createPickLoadSignsPass() { - return new PickLoadSigns(); -} +Pass* createPickLoadSignsPass() { return new PickLoadSigns(); } } // namespace wasm |