From b80ff5c73351d0e6762d8122914bb6c10bcd8d9f Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Sat, 7 May 2016 10:41:41 -0700 Subject: Use more static libraries in the CMake build (#451) * Factor passes and emscripten-optimizer into static libs This removes the redundancies from the source sets in the main CMakeLists.txt. * Make passes an object lib * Use static libs with --whole-archive because Travis has old cmake --- src/emscripten-optimizer/CMakeLists.txt | 6 ++ src/pass.cpp | 126 -------------------------------- src/passes/CMakeLists.txt | 17 +++++ src/passes/pass.cpp | 126 ++++++++++++++++++++++++++++++++ src/support/CMakeLists.txt | 10 +++ 5 files changed, 159 insertions(+), 126 deletions(-) create mode 100644 src/emscripten-optimizer/CMakeLists.txt delete mode 100644 src/pass.cpp create mode 100644 src/passes/CMakeLists.txt create mode 100644 src/passes/pass.cpp create mode 100644 src/support/CMakeLists.txt (limited to 'src') diff --git a/src/emscripten-optimizer/CMakeLists.txt b/src/emscripten-optimizer/CMakeLists.txt new file mode 100644 index 000000000..6c302b991 --- /dev/null +++ b/src/emscripten-optimizer/CMakeLists.txt @@ -0,0 +1,6 @@ +SET(emscripten-optimizer_SOURCES + optimizer-shared.cpp + parser.cpp + simple_ast.cpp +) +ADD_LIBRARY(emscripten-optimizer STATIC ${emscripten-optimizer_SOURCES}) diff --git a/src/pass.cpp b/src/pass.cpp deleted file mode 100644 index e4cc35554..000000000 --- a/src/pass.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2015 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include - -namespace wasm { - -// PassRegistry - -PassRegistry* PassRegistry::get() { - static PassRegistry* manager = nullptr; - if (!manager) { - manager = new PassRegistry(); - } - return manager; -} - -void PassRegistry::registerPass(const char* name, const char *description, Creator create) { - assert(passInfos.find(name) == passInfos.end()); - passInfos[name] = PassInfo(description, create); -} - -Pass* PassRegistry::createPass(std::string name) { - if (passInfos.find(name) == passInfos.end()) return nullptr; - auto ret = passInfos[name].create(); - ret->name = name; - return ret; -} - -std::vector PassRegistry::getRegisteredNames() { - std::vector ret; - for (auto pair : passInfos) { - ret.push_back(pair.first); - } - return ret; -} - -std::string PassRegistry::getPassDescription(std::string name) { - assert(passInfos.find(name) != passInfos.end()); - return passInfos[name].description; -} - -// PassRunner - -void PassRunner::addDefaultOptimizationPasses() { - add("remove-unused-brs"); - add("remove-unused-names"); - add("optimize-instructions"); - add("simplify-locals"); - add("merge-blocks"); - add("reorder-locals"); - add("vacuum"); - add("optimize-instructions"); -} - -void PassRunner::run() { - std::chrono::high_resolution_clock::time_point beforeEverything; - size_t padding = 0; - if (debug) { - std::cerr << "[PassRunner] running passes..." << std::endl; - beforeEverything = std::chrono::high_resolution_clock::now(); - for (auto pass : passes) { - padding = std::max(padding, pass->name.size()); - } - } - for (auto pass : passes) { - currPass = pass; - std::chrono::high_resolution_clock::time_point before; - if (debug) { - std::cerr << "[PassRunner] running pass: " << pass->name << "... "; - for (size_t i = 0; i < padding - pass->name.size(); i++) { - std::cerr << ' '; - } - before = std::chrono::high_resolution_clock::now(); - } - pass->run(this, wasm); - if (debug) { - auto after = std::chrono::high_resolution_clock::now(); - std::chrono::duration diff = after - before; - std::cerr << diff.count() << " seconds." << std::endl; - } - } - if (debug) { - auto after = std::chrono::high_resolution_clock::now(); - std::chrono::duration diff = after - beforeEverything; - std::cerr << "[PassRunner] passes took " << diff.count() << " seconds." << std::endl; - } -} - -template -P* PassRunner::getLast() { - bool found = false; - P* ret; - for (int i = passes.size() - 1; i >= 0; i--) { - if (found && (ret = dynamic_cast(passes[i]))) { - return ret; - } - if (passes[i] == currPass) { - found = true; - } - } - return nullptr; -} - -PassRunner::~PassRunner() { - for (auto pass : passes) { - delete pass; - } -} - -} // namespace wasm diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt new file mode 100644 index 000000000..460910978 --- /dev/null +++ b/src/passes/CMakeLists.txt @@ -0,0 +1,17 @@ +SET(passes_SOURCES + pass.cpp + LowerIfElse.cpp + MergeBlocks.cpp + Metrics.cpp + NameManager.cpp + OptimizeInstructions.cpp + PostEmscripten.cpp + Print.cpp + RemoveImports.cpp + RemoveUnusedBrs.cpp + RemoveUnusedNames.cpp + ReorderLocals.cpp + SimplifyLocals.cpp + Vacuum.cpp +) +ADD_LIBRARY(passes STATIC ${passes_SOURCES}) diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp new file mode 100644 index 000000000..e4cc35554 --- /dev/null +++ b/src/passes/pass.cpp @@ -0,0 +1,126 @@ +/* + * Copyright 2015 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +namespace wasm { + +// PassRegistry + +PassRegistry* PassRegistry::get() { + static PassRegistry* manager = nullptr; + if (!manager) { + manager = new PassRegistry(); + } + return manager; +} + +void PassRegistry::registerPass(const char* name, const char *description, Creator create) { + assert(passInfos.find(name) == passInfos.end()); + passInfos[name] = PassInfo(description, create); +} + +Pass* PassRegistry::createPass(std::string name) { + if (passInfos.find(name) == passInfos.end()) return nullptr; + auto ret = passInfos[name].create(); + ret->name = name; + return ret; +} + +std::vector PassRegistry::getRegisteredNames() { + std::vector ret; + for (auto pair : passInfos) { + ret.push_back(pair.first); + } + return ret; +} + +std::string PassRegistry::getPassDescription(std::string name) { + assert(passInfos.find(name) != passInfos.end()); + return passInfos[name].description; +} + +// PassRunner + +void PassRunner::addDefaultOptimizationPasses() { + add("remove-unused-brs"); + add("remove-unused-names"); + add("optimize-instructions"); + add("simplify-locals"); + add("merge-blocks"); + add("reorder-locals"); + add("vacuum"); + add("optimize-instructions"); +} + +void PassRunner::run() { + std::chrono::high_resolution_clock::time_point beforeEverything; + size_t padding = 0; + if (debug) { + std::cerr << "[PassRunner] running passes..." << std::endl; + beforeEverything = std::chrono::high_resolution_clock::now(); + for (auto pass : passes) { + padding = std::max(padding, pass->name.size()); + } + } + for (auto pass : passes) { + currPass = pass; + std::chrono::high_resolution_clock::time_point before; + if (debug) { + std::cerr << "[PassRunner] running pass: " << pass->name << "... "; + for (size_t i = 0; i < padding - pass->name.size(); i++) { + std::cerr << ' '; + } + before = std::chrono::high_resolution_clock::now(); + } + pass->run(this, wasm); + if (debug) { + auto after = std::chrono::high_resolution_clock::now(); + std::chrono::duration diff = after - before; + std::cerr << diff.count() << " seconds." << std::endl; + } + } + if (debug) { + auto after = std::chrono::high_resolution_clock::now(); + std::chrono::duration diff = after - beforeEverything; + std::cerr << "[PassRunner] passes took " << diff.count() << " seconds." << std::endl; + } +} + +template +P* PassRunner::getLast() { + bool found = false; + P* ret; + for (int i = passes.size() - 1; i >= 0; i--) { + if (found && (ret = dynamic_cast(passes[i]))) { + return ret; + } + if (passes[i] == currPass) { + found = true; + } + } + return nullptr; +} + +PassRunner::~PassRunner() { + for (auto pass : passes) { + delete pass; + } +} + +} // namespace wasm diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt new file mode 100644 index 000000000..08546e3ee --- /dev/null +++ b/src/support/CMakeLists.txt @@ -0,0 +1,10 @@ +SET(support_SOURCES + archive.cpp + bits.cpp + colors.cpp + command-line.cpp + file.cpp + safe_integer.cpp + threads.cpp +) +ADD_LIBRARY(support STATIC ${support_SOURCES}) -- cgit v1.2.3