diff options
author | t4lz <12370607+t4lz@users.noreply.github.com> | 2022-02-16 19:54:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 10:54:58 -0800 |
commit | 6810b60d7281d3e847692fdfb06faf32c9a09e59 (patch) | |
tree | 8ec228aec8e3f61d7d0aca1d6345ad0c6731f8ea /src | |
parent | a2552f119733d4ff1d86bfba97405d5ebc2e698b (diff) | |
download | binaryen-6810b60d7281d3e847692fdfb06faf32c9a09e59.tar.gz binaryen-6810b60d7281d3e847692fdfb06faf32c9a09e59.tar.bz2 binaryen-6810b60d7281d3e847692fdfb06faf32c9a09e59.zip |
Clarify in tools help message that -O == -Os. (#4516)
Introduce static consts with PassOptions Defaults.
Add assertion to verify that the default options are the Os options.
Also update the text in relevant tests.
Diffstat (limited to 'src')
-rw-r--r-- | src/pass.h | 9 | ||||
-rw-r--r-- | src/tools/optimization-options.h | 29 |
2 files changed, 24 insertions, 14 deletions
diff --git a/src/pass.h b/src/pass.h index bc9b3edde..20e099334 100644 --- a/src/pass.h +++ b/src/pass.h @@ -166,10 +166,13 @@ struct PassOptions { // passes. std::map<std::string, std::string> arguments; + // -Os is our default + static constexpr const int DEFAULT_OPTIMIZE_LEVEL = 2; + static constexpr const int DEFAULT_SHRINK_LEVEL = 1; + void setDefaultOptimizationOptions() { - // -Os is our default - optimizeLevel = 2; - shrinkLevel = 1; + optimizeLevel = DEFAULT_OPTIMIZE_LEVEL; + shrinkLevel = DEFAULT_SHRINK_LEVEL; } static PassOptions getWithDefaultOptimizationOptions() { diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h index ca555d5e9..8bca7639f 100644 --- a/src/tools/optimization-options.h +++ b/src/tools/optimization-options.h @@ -27,6 +27,8 @@ namespace wasm { struct OptimizationOptions : public ToolOptions { static constexpr const char* DEFAULT_OPT_PASSES = "O"; + static constexpr const int OS_OPTIMIZE_LEVEL = 2; + static constexpr const int OS_SHRINK_LEVEL = 1; std::vector<std::string> passes; @@ -37,15 +39,20 @@ struct OptimizationOptions : public ToolOptions { const std::string& description) : ToolOptions(command, description) { (*this) - .add("", - "-O", - "execute default optimization passes", - OptimizationOptionsCategory, - Options::Arguments::Zero, - [this](Options*, const std::string&) { - passOptions.setDefaultOptimizationOptions(); - passes.push_back(DEFAULT_OPT_PASSES); - }) + .add( + "", + "-O", + "execute default optimization passes (equivalent to -Os)", + OptimizationOptionsCategory, + Options::Arguments::Zero, + [this](Options*, const std::string&) { + passOptions.setDefaultOptimizationOptions(); + static_assert( + PassOptions::DEFAULT_OPTIMIZE_LEVEL == OS_OPTIMIZE_LEVEL && + PassOptions::DEFAULT_SHRINK_LEVEL == OS_SHRINK_LEVEL, + "Help text states that -O is equivalent to -Os but now it isn't."); + passes.push_back(DEFAULT_OPT_PASSES); + }) .add("", "-O0", "execute no optimization passes", @@ -106,8 +113,8 @@ struct OptimizationOptions : public ToolOptions { OptimizationOptionsCategory, Options::Arguments::Zero, [this](Options*, const std::string&) { - passOptions.optimizeLevel = 2; - passOptions.shrinkLevel = 1; + passOptions.optimizeLevel = OS_OPTIMIZE_LEVEL; + passOptions.shrinkLevel = OS_SHRINK_LEVEL; passes.push_back(DEFAULT_OPT_PASSES); }) .add("", |