diff options
Diffstat (limited to 'src/passes/StackIR.cpp')
-rw-r--r-- | src/passes/StackIR.cpp | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/src/passes/StackIR.cpp b/src/passes/StackIR.cpp index a8d66ae42..2506eca27 100644 --- a/src/passes/StackIR.cpp +++ b/src/passes/StackIR.cpp @@ -18,11 +18,11 @@ // Operations on Stack IR. // -#include "wasm.h" -#include "pass.h" -#include "wasm-stack.h" #include "ir/iteration.h" #include "ir/local-graph.h" +#include "pass.h" +#include "wasm-stack.h" +#include "wasm.h" namespace wasm { @@ -43,23 +43,16 @@ struct GenerateStackIR : public WalkerPass<PostWalker<GenerateStackIR>> { Module* module; Parent(Module* module) : module(module) {} - Module* getModule() { - return module; - } + Module* getModule() { return module; } void writeDebugLocation(Expression* curr, Function* func) { WASM_UNREACHABLE(); } - Index getFunctionIndex(Name name) { - WASM_UNREACHABLE(); - } - Index getFunctionTypeIndex(Name name) { - WASM_UNREACHABLE(); - } - Index getGlobalIndex(Name name) { - WASM_UNREACHABLE(); - } + Index getFunctionIndex(Name name) { WASM_UNREACHABLE(); } + Index getFunctionTypeIndex(Name name) { WASM_UNREACHABLE(); } + Index getGlobalIndex(Name name) { WASM_UNREACHABLE(); } } parent(getModule()); - StackWriter<StackWriterMode::Binaryen2Stack, Parent> stackWriter(parent, buffer, false); + StackWriter<StackWriterMode::Binaryen2Stack, Parent> stackWriter( + parent, buffer, false); stackWriter.setFunction(func); stackWriter.visitPossibleBlockContents(func->body); func->stackIR = make_unique<StackIR>(); @@ -67,9 +60,7 @@ struct GenerateStackIR : public WalkerPass<PostWalker<GenerateStackIR>> { } }; -Pass* createGenerateStackIRPass() { - return new GenerateStackIR(); -} +Pass* createGenerateStackIRPass() { return new GenerateStackIR(); } // Optimize @@ -79,8 +70,8 @@ class StackIROptimizer { StackIR& insts; public: - StackIROptimizer(Function* func, PassOptions& passOptions) : - func(func), passOptions(passOptions), insts(*func->stackIR.get()) { + StackIROptimizer(Function* func, PassOptions& passOptions) + : func(func), passOptions(passOptions), insts(*func->stackIR.get()) { assert(func->stackIR); } @@ -103,7 +94,8 @@ private: bool inUnreachableCode = false; for (Index i = 0; i < insts.size(); i++) { auto* inst = insts[i]; - if (!inst) continue; + if (!inst) + continue; if (inUnreachableCode) { // Does the unreachable code end here? if (isControlFlowBarrier(inst)) { @@ -151,12 +143,15 @@ private: #endif for (Index i = 0; i < insts.size(); i++) { auto* inst = insts[i]; - if (!inst) continue; + 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() << " on stack, will consume " << consumed << "\n "; - for (auto s : values) std::cout << s << ' '; + std::cout << " " << i << " : " << *inst << ", " << values.size() + << " on stack, will consume " << consumed << "\n "; + for (auto s : values) + std::cout << s << ' '; std::cout << '\n'; #endif // TODO: currently we run dce before this, but if we didn't, we'd need @@ -199,7 +194,8 @@ private: while (1) { // If there's an actual value in the way, we've failed. auto index = values[j]; - if (index == null) break; + if (index == null) + break; auto* set = insts[index]->origin->cast<SetLocal>(); if (set->index == get->index) { // This might be a proper set-get pair, where the set is @@ -228,7 +224,8 @@ private: } } // We failed here. Can we look some more? - if (j == 0) break; + if (j == 0) + break; j--; } } @@ -250,7 +247,8 @@ private: // a branch to that if body void removeUnneededBlocks() { for (auto*& inst : insts) { - if (!inst) continue; + if (!inst) + continue; if (auto* block = inst->origin->dynCast<Block>()) { if (!BranchUtils::BranchSeeker::hasNamed(block, block->name)) { // TODO optimize, maybe run remove-unused-names @@ -272,9 +270,7 @@ private: case StackInst::LoopEnd: { return true; } - default: { - return false; - } + default: { return false; } } } @@ -286,9 +282,7 @@ private: case StackInst::LoopBegin: { return true; } - default: { - return false; - } + default: { return false; } } } @@ -300,15 +294,11 @@ private: case StackInst::LoopEnd: { return true; } - default: { - return false; - } + default: { return false; } } } - bool isControlFlow(StackInst* inst) { - return inst->op != StackInst::Basic; - } + bool isControlFlow(StackInst* inst) { return inst->op != StackInst::Basic; } // Remove the instruction at index i. If the instruction // is control flow, and so has been expanded to multiple @@ -359,9 +349,6 @@ struct OptimizeStackIR : public WalkerPass<PostWalker<OptimizeStackIR>> { } }; -Pass* createOptimizeStackIRPass() { - return new OptimizeStackIR(); -} +Pass* createOptimizeStackIRPass() { return new OptimizeStackIR(); } } // namespace wasm - |